5 Replies Latest reply on Aug 20, 2007 2:39 PM by tim_ph

    how to use s:button to execute action first before jump to v

    tim_ph

      Is there a way to for action on s:button first before it jumps to the view page with params?
      This is JSF code:

      <rich:dataTable values="#{locations}" var="location"...>
      ...
      <a:commandLink value="Remove" action="#{applicationHome.deleteLocation}"/>
      ...
      </rich:dataTable>
       <s:button value="Add New Location"
       action="#{applicationHome.addLocation}"
       view="/LocationEdit.xhtml"
       propagation="join"
       >
       <f:param name="locationId" value="#{applicationHome.location.id}"/>
       </s:button>
      

      I need new location added to current application before edit it in LocationEdit.xhtml
      Application.addLocation() is defined as followed
       @DataModelSelection("locations")
       private Location location;
       public Location getLocation() { return location; }
      
       public void deleteLocation()
       {
       getInstance().getLocations().remove(location);
       getEntityManager().remove(location);
       location = null;
       }
      
       public void addLocation()
       {
       location = new Location();
       getInstance().getLocations().add(location);
       getEntityManager().persist(location);
       }
      


      location is DataModelSelection to be used within dataTable but also be used when added new. If I use the edit panel in the same page, that will be no problem, but I have to jump to new page to do it, that same code won't work because addLocation() didn't get called before #{applicationHome.location.id} assignment.

        • 1. Re: how to use s:button to execute action first before jump
          thejavafreak

          Try adding LocationEdit.page.xml and in it write this:





          Hopefully this meets your needs.

          • 2. Re: how to use s:button to execute action first before jump
            thejavafreak

            Try adding LocationEdit.page.xml and in it write this:

            &lt;page action="#{applicationHome.addLocation}"&gt;

            &lt;/page&gt;

            Hopefully this meets your needs.

            • 3. Re: how to use s:button to execute action first before jump
              pmuir

              You can use a raiseEvent on the navigation (this was added recently, not quite sure when).

              • 4. Re: how to use s:button to execute action first before jump
                tim_ph

                I've been thinking how to make this transition form Joshua's suggestion and Pete's.
                I can't do what Joshua said addLocation() to action because that will make LocationEdit.xhtml not suitable for the case where we use existing location id from dataTable list.
                I'm trying to figure out how raiseEvent can use the ID of new Location created on applicationHome in locationHome through page parameter LocationEdit.page.xml.

                • 5. Re: how to use s:button to execute action first before jump
                  tim_ph

                  Ok, it works if I use navigation with redirect AND param.
                  (I've been using Seam Framework generated by seam-gen with modification to jump start my app.)

                  In ApplicationEdit.page.xhtml

                  ...
                   <navigation from-action="#{applicationHome.addLocation}">
                   <rule if-outcome="done">
                   <redirect view-id="/policy/LocationEdit.xhtml">
                   <param name="locationId" value="#{applicationHome.location.id}"/>
                   <param name="locationFrom" value="ApplicationEdit2"/>
                   <param name="applicationId" value="#{applicationHome.applicationId}"/>
                   </redirect>
                   </rule>
                   </navigation>
                  ...
                  

                  and inside ApplicationEdit.xhtml, change s:button "Add New Location" to
                   <s:button value="Add New Location"
                   action="#{applicationHome.addLocation}"
                   propagation="join"
                   />
                  


                  In ApplicationHome.java, change addLocation()
                   public String addLocation()
                   {
                   location = new Location();
                   getInstance().getLocations().add(location); // add new location to application
                   getEntityManager().persist(location); // to get id from Hibernate
                   return "done";
                   }
                  


                  If you think it's not the most efficient way to do it, let me know.