3 Replies Latest reply on Dec 15, 2009 4:55 PM by Osian Hughes

    Outject Boolean

    Osian Hughes Newbie

      Hi,


      A quick explanation of what I want to acheive.  I have a search page, with a Seam component in Conversation scope.  Then the user can select one of 3 actions by clicking a button:
        New
        Edit
        Clone


      The new and the edit are no problem, because the edit component (page scope) and page either has the selected entity or not.  I then thought that I could outject a Boolean to indicate that the injected Entity is to be cloned.  But because I can't set the value of the boolean object until the button has been clicked, it doesn't seem to be injected into the Edit page component.


      Should this work? or is there a better way to do this?


      Thanks,
      Osian

        • 1. Re: Outject Boolean
          Osian Hughes Newbie

          I have now also tested with the New button, by setting the selected Entity to null during the processing of the method called when the button is clicked, but this seems to have no effect.


          Is it too late in the lifecycle when I am attempting to do this?


          Is there anyway to outject values at this point in the lifecycle??


          Thanks again,
          Osian

          • 2. Re: Outject Boolean
            Tim Evers Master

            I'm not sure why you need to outject anything.


            Why can't you just write 3 methods.


            public void createNew() {
                //do whatever you are supposed to do to create new
                editBean.setSelectedEntity(new Entity);
                editBean.redirect();//Do whatever you do to redirect to your page.
            }
            
            public void edit(Entity entityToEdit) {
                //do whatever you need to do to edit the entity
                editBean.setSelectedEntity(entityToEdit);
                editBean.redirect();//Do whatever you do to redirect to your page.
            }
            
            public void clone(Entity entityToClone) {
                //do whatever you need to do to clone the entity
                Entity clone = BeanUtils.clone(entityToClone); //Whatever you code is here to do the clone
                editBean.setSelectedEntity(clone);
                editBean.redirect();//Do whatever you do to redirect to your page.
            }
            



            Now in your xhtml(NOTE: This is just off the top of my head and is wrong but the general idea should be ok.)


            <h:commandButton value="New" action="#{SearchBean.createNew()}"/>
            <h:dataTable value="#{SearchBean.results} var="result"
                <!-- Do all your columns and data output here and then in one of the columns put these buttons -->
                <h:commandButton value="Edit" action="#{SearchBean.edit(result)}"/>
                <h:commandButton value="Clone" action="#{SearchBean.clone(result)}"/>
            </h:dataTable>
            



            I'm not really sure on your requirements so not sure if this helps or not, but hopefully will give you some ideas. Maybe just make nice icon buttons to represent the edit and clone (this is what we have done in our app... an E icon for edit and you could do like a C icon for clone).

            • 3. Re: Outject Boolean
              Osian Hughes Newbie

              Thanks Tim.


              I thought about this approach, but because the seam component for the Edit page is in page scope I had to come up with a slightly different solution.


              I have an abstract base class which has 99% of the implementation, and then I have 3 classes which extend the base class.  For the clone and edit they have the selected item injected into them, and then the clone pulls whatever values he needs to for the clone.  Whereas the New doesn't have the selected row injected into him.


              Then, to ensure that I didn't re-code everything for the facelets, I made a facelet component for the configuration of the object, and then it takes in a parameter of either the New, Clone or Edit concrete implementations, and all is well.


              Thanks again,
              Osian