5 Replies Latest reply on Dec 28, 2009 1:17 AM by Stephen Chan

    reRender the latest record in datatable

    Stephen Chan Newbie

      Hi all,

      Sorry, I'm a new guy in Richfaces and SEAM. I'm writing a simple search function in an application. However, I couldn't reRender the latest record which has just been updated by other user (event I trigger the query again). Here is my coding:

       

      In EJB:

      @Stateful
      @Scope(ScopeType.SESSION)
      @Name("adminAuthRecord")

      public class AdminAuthRecord implements AdminAuthRecordLocal {
      @DataModel
      private List<Record> adminRecordList;

      ...

      public void doFilter() {
        this.adminRecordList=null;
        adminRecordList=this.getAdminRecordList();
      }

      ...

      public List<Record> getAdminRecordList() {
         ...

         Query query = em.createQuery(
         "SELECT r FROM Record r WHERE r.studentProfile.loginId IS NOT NULL " + criteria);
         adminRecordList = query.getResultList();

         for(int i=0; i<adminRecordList.size; i++) {

           // if i print them out, the records are new, but not reflected on the reRender

         }
         return adminRecordList;
      }

      ...

      }

      In xhtml:

      <a:outputPanel id="recordListPanel">

         <a:commandButton value="" image="/style/img/btn_filter_trans.gif"
          action="#{adminAuthRecord.doFilter}" reRender="recordListPanel"/>

      <rich:dataTable id="list" value="#{adminRecordList}" var="adminRecord" rendered="#{adminRecordList.rowCount>0}"
        rows="10" reRender="ds" >
        <rich:column id="column1" width="700">
         <f:facet id="AddressFacet" name="header">Header</f:facet>
         <h:panelGrid columns="1">

             <h:outputText value="#{adminRecord.description}"/>
         </h:panelGrid>
        </rich:column>
              <f:facet name="footer">
              <rich:datascroller id="ds"
                oncomplete="Richfaces.hideModalPanel('ProgressModalPanel')"
           onpagechange="Richfaces.showModalPanel('ProgressModalPanel',{param1:'Please wait...'})"/>
              </f:facet>
      </rich:dataTable>
      ....
      </a:outputPanel>

       

      P.S. The record can be refreshed if I change the search criteria and then back to search the older criteria again

       

      Could any expert help me?

        • 1. Re: reRender the latest record in datatable
          Nick Belaevski Master

          Hi Stephen,

           

          Page code looks ok, please check if getAdminRecordList() method returns updated data when table is re-rendered.

          • 2. Re: reRender the latest record in datatable
            Stephen Chan Newbie

            Hi Nick,

            Thanks for your confirmation and reply.

            I tried to print the records in the console, it shows the records are latest, but seems it couldn't reflect on the screen

             

                public void doFilter() {
                    this.adminRecordList=null;
                    adminRecordList=this.getAdminRecordList();
                    for(int i=0; i<adminRecordList.size(); i++) {
                        System.out.println("Record" + i+ ": " + adminRecordList.get(i)); // print it inside console
                    }
                }

            • 3. Re: reRender the latest record in datatable
              Nick Belaevski Master
              Please add a4j:log component to the page, press the button calling "doFilter()" action and post logger ourtput here.
              • 4. Re: reRender the latest record in datatable
                Stephen Chan Newbie

                Hi Nick,

                 

                I got a finding by try-and-error. If I changed the scope from SESSION to CONVERSATION, it works...

                I'm quite confused, coz an example in SEAM reference said:

                The @DataModel annotation exposes an attibute of type java.util.List to the JSF page
                as an instance of javax.faces.model.DataModel. This allows us to use the list in a JSF
                <h:dataTable> with clickable links for each row. In this case, the DataModel is made
                available in a session context variable named messageList.

                 

                Why only CONVERSATION work? Actaully, I don't think my application needs to carry conversational state, so I tried to escape from it.\

                Do I have some misunderstandings?

                 

                Anyway, I've still printouted the logs "a4j:log" for your reference:

                 

                Originally, it shows some error messages which are related to ModalPanels

                debug[10:25:22,070]: search for  elements by name 'script'  in element span
                debug[10:25:22,070]: Scripts in  updated part count : 9
                debug[10:25:22,070]: Update part of  page for Id: recordListPanel successful
                debug[10:25:22,070]: call  selectSingleNode for id= ajax-view-state
                debug[10:25:22,070]: Hidden JSF state  fields:
                debug[10:25:22,070]: Namespace for  hidden view-state input fields is undefined
                debug[10:25:22,070]: search for  elements by name 'input'  in element span
                debug[10:25:22,070]: Replace value for  inputs: 22 by new values: 1
                debug[10:25:22,070]: Input in  response: javax.faces.ViewState
                debug[10:25:22,070]: Found same input  on page with type: hidden
                debug[10:25:22,070]: Found same input  on page with type: hidden
                debug[10:25:22,070]: Found same input  on page with type: hidden
                debug[10:25:22,070]: search for  elements by name 'INPUT'  in element span
                debug[10:25:22,070]: Replace value for  inputs: 22 by new values: 0
                debug[10:25:22,070]: call  selectSingleNode for id= _A4J.AJAX.focus
                debug[10:25:22,070]: No focus  information in response
                debug[10:25:22,211]: Evaluate script  replaced area in document: //new  Richfaces.Datascroller('editRecordListForm:sdpList:ds', function(event){if  (function(event){Richfaces.showModalPanel('ProgressModalPanel',{param1:'Please  wait...'}); return true;}(event))  {A4J.AJAX.Submit('editRecordListForm',event,{'ignoreDupResponses':true,'implicitEventsQueue':'editRecordListForm:sdpList:ds','oncomplete':function(request,event,data){Richfaces.hideModalPanel('ProgressModalPanel')},'similarityGroupingId':'editRecordListForm:sdpList:ds','parameters':{'editRecordListForm:sdpList:ds':event.memo.page,'ajaxSingle':'editRecordListForm:sdpList:ds'}  } ); return false;}});//
                debug[10:25:22,211]: Script evaluation  succeeded
                debug[10:25:22,211]: Evaluate script  replaced area in document: //LOG.LEVEL = LOG.ALL;//
                debug[10:25:22,211]: Script evaluation  succeeded
                debug[10:25:22,211]: Evaluate script  replaced area in document: //                        function  panelRevokeMesasge(messagevalue1, messagevalue2, messagevalue3) {                                                                        document.getElementById('form2:message1').innerHTML=messagevalue1;                                          document.getElementById('form2:message2').innerHTML=messagevalue2;                                          document.getElementById('form2:message3').innerHTML=messagevalue3;                                                   }                        function  panelSaveMesasge(messagevalue) {                                                                 document.getElementById('form2:progressStatus').innerHTML=messagevalue;                                              }                        function  panelMesasge(messagevalue) {                                                            document.getElementById('form2:progressStatus2').innerHTML=messagevalue;                                                     }                 //
                debug[10:25:22,211]: Script evaluation  succeeded
                debug[10:25:22,211]: Evaluate script  replaced area in document: //new ModalPanel('form2:ProgressModalPanel',                                 {                                        width: 300,                                         height: 150,                                         minWidth: -1,                                        minHeight: -1,                                         resizeable: true,                                         moveable: true,                                        left: "auto",                                         top: "auto",                                         zindex: 100,onresize: '',onmove: '',onshow:  function(event){javascript:panelSaveMesasge(event.parameters.param1)},onhide:  '',onbeforeshow: '',onbeforehide: '',                                         domElementAttachment: "",                                                                        keepVisualState: false,                                         showWhenRendered: false,                                        selectBehavior:  "disable",                                        autosized: false,                                         overlapEmbedObjects: false});//
                debug[10:25:22,227]: Script evaluation  succeeded
                debug[10:25:22,227]: Evaluate script  replaced area in document:
                error[10:25:22,227]: . Error message:  不正確的引數。(In english: invalid index)
                debug[10:25:22,227]: Evaluate script  replaced area in document: //new ModalPanel('form2:rejectDlg',                                 {                                        width: 300,                                         height: 150,                                         minWidth: -1,                                        minHeight: -1,                                         resizeable: true,                                         moveable: true,                                        left: "auto",                                         top: "auto",                                         zindex: 100,onresize: '',onmove: '',onshow:  function(event){javascript:panelMesasge(event.parameters.param1)},onhide:  '',onbeforeshow: '',onbeforehide: '',                                         domElementAttachment: "",                                                                        keepVisualState: false,                                         showWhenRendered: false,                                        selectBehavior:  "disable",                                        autosized: false,                                         overlapEmbedObjects: false});//
                debug[10:25:22,242]: Script evaluation  succeeded
                debug[10:25:22,242]: Evaluate script  replaced area in document:
                error[10:25:22,242]: . Error message:  不正確的引數。(In english: invalid index)
                debug[10:25:22,242]: Evaluate script  replaced area in document: //new ModalPanel('form2:revokeDlg',                                 {                                        width: 300,                                         height: 150,                                         minWidth: -1,                                        minHeight: -1,                                         resizeable: true,                                         moveable: true,                                        left: "auto",                                         top: "auto",                                         zindex: 100,onresize: '',onmove: '',onshow:  function(event){javascript:panelRevokeMesasge(event.parameters.param1,  event.parameters.param2, event.parameters.param3)},onhide: '',onbeforeshow:  '',onbeforehide: '',                                         domElementAttachment: "",                                                                        keepVisualState: false,                                         showWhenRendered: false,                                        selectBehavior:  "disable",                                        autosized: false,                                         overlapEmbedObjects: false});//
                debug[10:25:22,258]: Script evaluation  succeeded
                debug[10:25:22,258]: Evaluate script  replaced area in document:
                error[10:25:22,258]: . Error message:  不正確的引數。(In english: invalid index)
                debug[10:25:22,258]: call  selectSingleNode for id= org.ajax4jsf.oncomplete
                debug[10:25:22,258]: Call request  oncomplete function after processing updates
                debug[10:25:22,305]: call  selectSingleNode for id= _ajax:data

                 

                Afterward, I removed all ModalPanel in the xhtml, but the most updated record still CAN'T be reflected

                debug[10:19:47,494]: search for  elements by name 'script'  in element span
                debug[10:19:47,494]: Scripts in  updated part count : 2
                debug[10:19:47,494]: Update part of  page for Id: recordListPanel successful
                debug[10:19:47,494]: call  selectSingleNode for id= ajax-view-state
                debug[10:19:47,494]: Hidden JSF state  fields:
                debug[10:19:47,509]: Namespace for  hidden view-state input fields is undefined
                debug[10:19:47,509]: search for  elements by name 'input'  in element span
                debug[10:19:47,509]: Replace value for  inputs: 11 by new values: 1
                debug[10:19:47,509]: Input in  response: javax.faces.ViewState
                debug[10:19:47,509]: Found same input  on page with type: hidden
                debug[10:19:47,509]: Found same input  on page with type: hidden
                debug[10:19:47,509]: search for  elements by name 'INPUT'  in element span
                debug[10:19:47,509]: Replace value for  inputs: 11 by new values: 0
                debug[10:19:47,509]: call  selectSingleNode for id= _A4J.AJAX.focus
                debug[10:19:47,509]: No focus  information in response
                debug[10:19:47,556]: Evaluate script  replaced area in document: //new  Richfaces.Datascroller('editRecordListForm:sdpList:ds',  function(event){A4J.AJAX.Submit('editRecordListForm',event,{'ignoreDupResponses':true,'implicitEventsQueue':'editRecordListForm:sdpList:ds','similarityGroupingId':'editRecordListForm:sdpList:ds','parameters':{'editRecordListForm:sdpList:ds':event.memo.page,'ajaxSingle':'editRecordListForm:sdpList:ds'}  } ); return false;});//
                debug[10:19:47,556]: Script evaluation  succeeded
                debug[10:19:47,556]: Evaluate script  replaced area in document: //LOG.LEVEL = LOG.ALL;//
                debug[10:19:47,556]: Script evaluation  succeeded
                debug[10:19:47,556]: call  selectSingleNode for id= org.ajax4jsf.oncomplete
                debug[10:19:47,556]: Processing  updates finished, no oncomplete function to call
                • 5. Re: reRender the latest record in datatable
                  Stephen Chan Newbie

                  Hi Nick,

                   

                  Thanks for your kindly help... finally, i solved my stupid question. I believe ajax throws exception while I interrupt the value of DataModel, after erase the "set null"(as below), it works expectedly. However, can you tell me it works in CONVERSATION scope in the same case?

                   

                  public void doFilter() {
                    this.adminRecordList=null;
                    adminRecordList=this.getAdminRecordList();
                  }