8 Replies Latest reply on Apr 1, 2008 2:20 PM by mars1412

    Passing var via method

    wachtda.scsi.gmx.ch

      Hello Seam fans!


      Sometimes I have the problem, that I want to pass a var via a method invocation, and it doesn't work!


      Examples...


      View:


      <h:dataTable value="#{datalogger.nodes}" var="node" rendered="#{datalogger.nodes.size>0}" headerClass="data_header" rowClasses="data_row,data_row_tainted" width="100%">
        <h:column>
          <f:facet name="header">#{msg.f_netId}</f:facet>
          #{node.networkAddress}
        </h:column>
        <h:column>
          <f:facet name="header">#{msg.f_device}</f:facet>
          #{node.description}
        </h:column>
        <h:column>
          <f:facet name="header">#{msg.f_model}</f:facet>
          #{node.model.description}
        </h:column>      
        <h:column>
          <f:facet name="header">#{msg.f_serial}</f:facet>
          #{node.serialNumber}
        </h:column>
        <h:column>
          <f:facet name="header">#{msg.f_retentionTime}</f:facet>
          #{deviceAction.calcDuration(node)}
        </h:column>                    
        <h:column width="25%">
          <f:facet name="header">#{msg.f_notes}</f:facet>
          <s:link action="#{logEntryAction.selectDevice(node.ID)}" view="/notes.xhtml" target="new" value="#{q_msg.f_edit}" />
        </h:column>
      </h:dataTable>



      Bean:


      public void selectDevice(String id) {
                
        if(id.equals("")) {
          m_Device = m_EM.find(Device.class, Long.valueOf(id));
          System.out.println("DEVICE: " + m_Device.getDescription() + " (" + m_Device.getID() + ")");
        }
                
      }



      Can anbody tell my why the passed var always is void?
      This should be work or not?
      Do I missunderstand something?


      Thank you for helping


        • 1. Re: Passing var via method

          Same happens to me from time to time. I would recommend using @DataModel and @DataModelSelection instead like inte the example 1.11:




          @Stateful
          @Scope(SESSION)
          @Name("messageManager")
          public class MessageManagerBean implements Serializable, MessageManager
          {
          
             @DataModel                                                                            (1)
             private List<Message> messageList;
             
             @DataModelSelection                                                                   (2)
             @Out(required=false)                                                                  (3)
             private Message message;
             
             @PersistenceContext(type=EXTENDED)                                                    (4)
             private EntityManager em;
             
             @Factory("messageList")                                                               (5)
             public void findMessages()
             {
                messageList = em.createQuery("from Message msg order by msg.datetime desc")
                                .getResultList();
             }
             
             public void select()                                                                  (6)
             {
                message.setRead(true);
             }
             
             public void delete()                                                                  (7)
             {
                messageList.remove(message);
                em.remove(message);
                message=null;
             }
             
             @Remove                                                                               (8)
             public void destroy() {}
          
          }



          • 2. Re: Passing var via method

            just a guess, but could you please try this:
            rename your ID field to Id (upper/lowercase) and also your getter/setters and try again.


            This works fine for me and AFAIK this should work OOTB.


            If this does not solve your problem show some more code of your entity and session bean.

            • 3. Re: Passing var via method
              wachtda.scsi.gmx.ch

              The problem is, that my method is not in the same bean as the datamodel. (i need this method in several views...)

              • 4. Re: Passing var via method
                damianharvey.damianharvey.gmail.com

                I'd be surprised if this worked. See the EL Limitations Chapter in the docs


                If you use h:commandLink/Button or a4j:commandLink/Button it will work. My pattern for s:link is to have a stub method in the same Bean as the @DataModel that calls the method in the Bean that actually implements the functionality.


                Cheers,


                Damian.

                • 5. Re: Passing var via method

                  yipp - you are right


                  in fact my example uses a4j:commandLink not s:link


                  sorry for not reading thoroughly..

                  • 6. Re: Passing var via method
                    wachtda.scsi.gmx.ch

                    Ok, it was my fault...
                    Now  I know what's the problem, thank you damian!

                    • 7. Re: Passing var via method
                      wachtda.scsi.gmx.ch

                      Now I have another problem.
                      I have a device list, if I click on a device I want to display a popup with the log entries of the selected device.


                      My Problem is, that the factory which will call the device list is invoked before the method which will select the actual device:


                      <h:commandLink action="#{logEntryAction.selectDevice(node.ID)}" onclick="window.open('notes.seam', 'notes', 'width=1024,height=600')" value="#{msg.f_edit}" />



                      Because the onklick() method is called before the action() the device is not selected if the pages notes.seam gets the list via a factory. How can I make, that the action() is called befor the onklick()?


                      Thank you, Daniel

                      • 8. Re: Passing var via method

                        I suggest you use an a:commandButton with your action and instead of onclick, you use oncomplete