开发者

JSF: Is there a way to create animation effect when insert a new record into table?

开发者 https://www.devze.com 2023-01-16 20:59 出处:网络
I\'ve been googling this question a lot and I dont seem to find a solution. I wonder开发者_如何学运维 if any developer out there that able to achieve this? I know there are couple ajax framework out t

I've been googling this question a lot and I dont seem to find a solution. I wonder开发者_如何学运维 if any developer out there that able to achieve this? I know there are couple ajax framework out there for JSF like Richfaces, primefaces, icefaces ... I have look at their showcase, and could not seems to find what I am looking for.


This is how it would work for h:dataTable assuming that we always append to the table:

<h:form>
 <h:panelGroup id="animatedTableGroup">
  <h:dataTable id="animatedTable" value="#{myBean.rows}" var="row">
   <h:column>
    <h:outputText value="#{row}"/>
   </h:column>
  </h:dataTable>
  <rich:jQuery timing="onload" 
        selector="#animatedTable tr:last" query="fadeOut('slow')"/>
  <rich:jQuery timing="onload" 
        selector="#animatedTable tr:last" query="fadeIn('slow')"/>
 </h:panelGroup>

 <a4j:commandButton value="Add row" 
      action="#{myBean.addRow}" reRender="animatedTableGroup"/>
</h:form>

And the bean:

public void addRow() {
  rows.add(new Date().toString());
}

public List<String> getRows() {
  return rows;
}

If you want to insert into selected position in the table, then it's better to use rich:extendedDataTable and use something like this as selector:

<rich:jQuery timing="onload" 
        selector="#animatedTable tr.rich-sdt-row-selected" query="..."/>


Richfaces has native support for jQuery using rich:jQuery component. You can use any effects that jQuery supports. For example:

<h:commandButton id="submitButton" value="Submit" 
   action="#{myBean.myAction}" style="display: none;"/>
<rich:jQuery selector="#submitButton" 
   query="fadeIn('slow')" timing="onload">

or

<h:commandButton id="submitButton" value="Submit" 
   action="#{myBean.myAction}" 
   onmouseover="jQuery(this).fadeOut('slow');" 
   onmouseout="jQuery(this).fadeIn('slow')"/>

You can find more examples here: http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_jQuery.html

0

精彩评论

暂无评论...
验证码 换一张
取 消