4 Replies Latest reply on Oct 30, 2008 11:08 PM by Andrew Elegante

    Why i get null,when i use seam extended EL

    Wang Ruifeng Newbie

      UserList.xhtml




      <rich:dataTable id="userList"                       
          value="#{userList.resultList}"
          var="user"                                          
          rendered="#{not empty userList.resultList}">
          <f:facet name="header">
              <h:outputText value="UserList"/>
              </f:facet>
              <rich:column sortBy="#{user.id}"> 
                      <f:facet name="header">
                              <h:outputText value="ID"/>
                      </f:facet>
                      <h:outputText value="#{user.id}"/>
              </rich:column> 
                      
              <rich:column sortBy="#{user.name}"> 
                      <f:facet name="header">
                              <h:outputText value="Name"/>
                      </f:facet>
                      <h:outputText value="#{user.name}"/>
              </rich:column>
      
              <rich:column>
                      <f:facet name="header"></f:facet>
                      <s:link view="/#{empty from ? 'User' : from}.xhtml" value="#{empty from ? 'Detail' : 'Select'}" id="user">
                              <f:param name="userId" value="#{user.id}"/>
                      </s:link>
              </rich:column>
                      
              <rich:column>
                      <f:facet name="header"></f:facet>
                      <s:link id="deleteUser"      value="Delete" action="#{UserDelete.userDelete(user)}" />
              </rich:column>                    
      </rich:dataTable>




      UserDeleteAction.java




      @Stateless
      @Name("UserDelete")
      public class UserDeleteAction implements UserDelete {
      
          @Logger private Log log;
      
          @In FacesMessages facesMessages;
      
          public void userDelete(User user) {
                      log.info("UserId:" + user.getId());
                      log.info("UserName:" + user.getName());        
          }
      
      }



      When i click the delete link on UserList.xhtml
      I got:


      INFO  [UserDeleteAction] UserId:null
      INFO  [UserDeleteAction] UserName:null




      Why UserDelete.userDelete(user) can work?

        • 2. Re: Why i get null,when i use seam extended EL
          Wang Ruifeng Newbie

          But why in the booking example this code can work:


          <h:dataTable id="hotels" value="#{hotels}" var="hot" rendered="#{hotels.rowCount>0}">
                    <h:column id="column1">
                    <f:facet id="NameFacet"name="header">Name</f:facet>
                    #{hot.name}
               </h:column>
               <h:column id="column2">
                    <f:facet id="AddressFacet" name="header">Address</f:facet>
                    #{hot.address}
               </h:column>
               <h:column id="column3">
                    <f:facet id="CityStateFacet" name="header">City, State</f:facet>
                    #{hot.city}, #{hot.state}, #{hot.country}
               </h:column> 
               <h:column id="column4">
                    <f:facet id="ZipFacet" name="header">Zip</f:facet>
                    #{hot.zip}
               </h:column>
               <h:column id="column5">
                    <f:facet id="ActionFacet"name="header">Action</f:facet>
                    <s:link id="viewHotel" value="View Hotel" action="#{hotelBooking.selectHotel(hot)}"/>
               </h:column>
          </h:dataTable>


          • 3. Re: Why i get null,when i use seam extended EL
            Manoj Agrawal Newbie

            Hi,
            Did you get the solution for your problem? I am also facing the same problem.
            Thanks

            • 4. Re: Why i get null,when i use seam extended EL
              Andrew Elegante Newbie

              The hotel booking models' backing bean exposes 'hot' via the @DataModelSelection annotation.  For your example, in your 'userList' bean you would ideally want to annotate the value returned by 'userList.resultList' with @DataModel and then have a field private User selectedUser annotated with @DataModelSelection.


              ex:


               
                .....
                @DataModel
                private List<User> searchResults;
                @DataModelSelection
                private User selectedUser;
                .....
              



              That should solve your user delete issue.  You should also change 'userList.resultList' to just reference your outjected data model i.e.


              <rich:dataTable id="userList"                       
                  value="#{searchResults}"
                  var="user"                                          
                  rendered="#{not empty searchResults}">
              
              



              When you call


              #{UserDelete.userDelete(user)}
              



              seam injects the value of selectedUser into your 'user' variable.


              Drew