3 Replies Latest reply on Aug 25, 2007 6:06 AM by Adam Warski

    Re-rendering only some table elements

    Adam Warski Master

      Hello,

      I have a table (1 column, so more of a list) of some elements, and I would like to set a4j:poll to re-render only one given panel of each row of the table (each row consists of several panels). Is it possible?

      I've seen the suggestion in the FAQ to use a4j:repeat, but I don't quite understand how that could solve my case.

      --
      Thanks,
      Adam

        • 1. Re: Re-rendering only some table elements
          Alexander Smirnov Master

          Yes, it is. You can point to any element inside a4j:repeat, rich:dataTable, rich:dataList :

           <a4j:poll id="p" reRender="text" interval="1000"
           enabled="#{timerBean.enabled}" action="#{listAction.timer}" />
           <rich:dataList id="list" var="data" value="#{repeatData.data}" >
           <h:panelGroup id="row">
           <h:outputText value="Row data :"/><h:outputText id="text" value="#{data.text}"/>
           </h:panelGroup>
           </rich:dataList>
          
          

          In this case, content of the component "text" should be updated for a all rows.
          Even, where is possible update some components for a selected rows :
           <a4j:poll id="p" reRender="text" interval="1000"
           enabled="#{timerBean.enabled}" action="#{listAction.timer}" />
           <rich:dataList id="list" var="data" value="#{repeatData.data}" ajaxKeys="#{listAction.keys}">
           <h:panelGroup id="row">
           <h:outputText value="Row data :"/><h:outputText id="text" value="#{data.text}"/>
           </h:panelGroup>
           </rich:dataList>
          

          Rows numbers for update seted in a request-scope bean ( random number of rows in this simple case ):
          /**
           * @author asmirnov
           *
           */
          public class ListAction {
          
           private List data;
          
           private Set keys;
          
           /**
           * @return the data
           */
           public List getData() {
           return data;
           }
          
           /**
           * @param data the data to set
           */
           public void setData(List data) {
           this.data = data;
           }
          
           public Set getKeys(){
           return keys;
           }
          
           public String timer(){
           if(null != data){
           keys=new HashSet();
           int random = (int)(Math.random()*10.0);
           for(int i=0;i<random;i++){
           Bean bean = (Bean) data.get(i);
           bean.setText(bean.getText()+" X");
           keys.add(new Integer(i));
           }
           }
           return null;
           }
          
          
          }
          

          beans are defined in the faces-config.xml :
           <managed-bean>
           <managed-bean-name>repeatData</managed-bean-name>
           <managed-bean-class>org.ajax4jsf.RepeatData</managed-bean-class>
           <managed-bean-scope>session</managed-bean-scope>
           </managed-bean>
           <managed-bean>
           <managed-bean-name>listAction</managed-bean-name>
           <managed-bean-class>org.ajax4jsf.ListAction</managed-bean-class>
           <managed-bean-scope>request</managed-bean-scope>
           <managed-property>
           <property-name>data</property-name>
           <property-class>java.util.List</property-class>
           <value>#{repeatData.data}</value>
           </managed-property>
           </managed-bean>
          



          • 2. Re: Re-rendering only some table elements
            Adam Warski Master

            Hello,

            thanks a lot! It works (almost) --- that is, it works when I put the id I want to refresh in <a4j:poll>. But it doesn't, if for example I put it inside reRender of a <a4j:commandLink> (other components, which aren't inside the <rich:dataList>, are refreshed). Should it be so?

            Also, I noticed that if I submit an ajax request, and it concides with a poll ajax request, sometimes the whole page is refreshed. Is it because of the colliding requests?

            --
            Adam

            • 3. Re: Re-rendering only some table elements
              Adam Warski Master

              Hello,

              also, I noticed that if in the item of <rich:dataList> I have a <rich:togglePanel> with some facets, I get errors that facets are not defined (that there are no facets with names defined in the stateOrder of the togglePanel). Is it possible to have togglePanels inside a dataList?

              --
              Adam