3 Replies Latest reply on May 21, 2007 10:53 PM by Daniel Young

    How to get a facelets parameter into a seam component

    Tobias Kilian Newbie

      Hi Folks!

      I have the following scenario:
      I want to create a component that manages relationship between entities. To make it reusable, i have two general managers, which are templated EJB3 session beans and manage some buisness objects.
      These entities are derived from two interfaces AssociationMaster and AssociationSlave respectively. Their methods can tell which fields of the two entitys map the relationship betweeen them. So the only thing my component should be depend on is that the two managers given to it manage entities which are derived from the two interfaces and behave accordingly. The component itself consists of a Listbox to select the master and a MultipleSelectCheckbox on the right side to select the Associated Slaves. A Common scenario in our application would be to map users to groups and groups to tasks etc.
      I used the facelet-taglib with the source tag to define my component:



      myTaglib.xml:
      
      <facelet-taglib>
       <namespace>http://www.mobilanten.de/tags</namespace>
       <tag>
       <tag-name>associationTableInclude</tag-name>
       <source>tags/associationTable.xhtml</source>
       </tag>
      
      </facelet-taglib>
      



      testPage.xml:
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:mb="http://www.mobilanten.de/tags">
      
      <ui:define name="body">
       <tr:panelPage>
       <mb:associationTableInclude
       masterManager="#{gruppenManager}"
       slaveManager="#{benutzerManager}"/>
       </tr:panelPage>
      </ui:define>
      </ui:composition>
      


      inside the associationTable.xhtml (not posted here) i can use #{masterManager} and get the concretized #{gruppenManager}.

      when submitting the form, the called action method should call .save in the end.

      So the question his how to get the facelet template parameter #{masterManager} into my code by whatever means?

      I have tried many things like giving the masterManager as Parameter to the action method(always null) now but am stuck, so i wonder if theres any way at all to do this..

      Many thanks for your suggestions!
      Tobias Kilian

        • 1. Re: How to get a facelets parameter into a seam component
          Arthur Hupka Newbie

          Hi!

          Try it with:

          <ui:include src="groupManager.xhtml">
           <ui:param name="gruppenManager" value="#{component.property}"/>
           <ui:param name="benutzerManager" value"#{component.property}"/>
          </ui:include>
          


          I dont evet know if this works with ui:define.
          Anyway i think that can help you.

          • 2. Re: How to get a facelets parameter into a seam component
            Tobias Kilian Newbie

            Hi Arthur!

            Thanks for you reply, however according to

            http://www.jsfcentral.com/articles/facelets_3.html

            the ui:param and the custom tag approches are equivalent.

            The question how to get that given parameter into my backing bean remains:

            e.g., i have:
            <tr:commandButton id="saveButton" text="Save" action="#{associationTable.save()}">

            where associationTable is a conversation scoped POJO living in .war-file/WEB-INF/classes. It must get the SelectManyCheckbox injected in order to preselect Slaves after the user has selected a Master. So associationTable is the listener for the valueChangeEvents and also keeps state of which Salves the user has selected. It must however inform the Managers that one of their entities has changed to get the database updated.

            If anything on this approach is not "standard like" or how you would do it, please dont hesitate to correct me. However i thought keeping the UI-component "associationTable" seperated from my Buisness logic and therefor outside the .jar would be a good idea :-)

            Greetings,
            Tobias Kilian

            • 3. Re: How to get a facelets parameter into a seam component
              Daniel Young Novice

              Hi Tobias,

              I ran into this problem previously as well, and had to work around it by solving my problem some other way.

              However, I did just have an idea. With normal JSF components that you use, you can inject them into your Seam bean with this:

              @In(value="#{uiComponent['componentId']}")
              private UIComponent component;
              


              I'm not sure what instance of UIComponent this would inject, or how you can access your attributes. But maybe this will work, if you give your component an ID when you use it?

              Daniel.

              "quilian" wrote:
              Hi Arthur!

              Thanks for you reply, however according to

              http://www.jsfcentral.com/articles/facelets_3.html

              the ui:param and the custom tag approches are equivalent.

              The question how to get that given parameter into my backing bean remains:

              e.g., i have:
              <tr:commandButton id="saveButton" text="Save" action="#{associationTable.save()}">

              where associationTable is a conversation scoped POJO living in .war-file/WEB-INF/classes. It must get the SelectManyCheckbox injected in order to preselect Slaves after the user has selected a Master. So associationTable is the listener for the valueChangeEvents and also keeps state of which Salves the user has selected. It must however inform the Managers that one of their entities has changed to get the database updated.

              If anything on this approach is not "standard like" or how you would do it, please dont hesitate to correct me. However i thought keeping the UI-component "associationTable" seperated from my Buisness logic and therefor outside the .jar would be a good idea :-)

              Greetings,
              Tobias Kilian