1 Reply Latest reply on Nov 24, 2010 1:26 PM by Ryan Samiley

    Composition Component with Seam Argument Passing

    Ryan Samiley Newbie

      Hello,


      I am trying to consolidate a lot of duplicate code by creating Composition components using Facelets.


      I'm using this article as a guide: http://www.ibm.com/developerworks/java/library/j-facelets/


      The article states I can call actions by using separate attributes in my custom tag to pass in the managed bean and method name. Inside the composition component, I can bind a method to the managed bean with square brackets. For example,

      #{managedBean[actionName]}



      This works great when the method takes no arguments, but most of our Seam managed beans take arguments. How do I go about passing in an argument.


      Specifically, I am trying to consolidate an inputText, suggestionBox, and an A4J onSelect call into one tag.


      Here is what the tag will look like:

      <my:personSuggest
        id="nameSuggest"
        value="#{aPersonEntity}"
        personSuggestBean="#{personSuggestionManager}"
        suggestAction="suggestByName"
        selectionListenerBean="#{personSelectBean}"
        selectionListenerAction="personSelected"/>



      Here is the markup for the Composition Component:

      <!-- Set optional values when they do not exist -->
      <c:if test="${empty minchars}">
        <c:set var="minchars" value="3"/>
      </c:if>
      
      <c:if test="${empty nothingLabel}">
        <c:set var="nothingLabel" value="No results for entered name."/>
      </c:if>
      
      <h:inputText
        id="#{id}"
        value="#{value.fullName}"/>
                                      
      <rich:suggestionbox
        for="#{id}"
        var="suggestedPerson"
        immediate="true"
        minChars="#{minchars}"
        nothingLabel="#{nothingLabel}"
        suggestionAction="#{personSuggestBean[suggestByName]}"
        requestDelay="0">
        <h:column>
          <h:outputText value="#{suggestedPerson.fullName} #{suggestedPerson.middleInitial}" />
        </h:column>
        <h:column>
          <h:outputText value="#{suggestedPerson.badgeNumber}"/>
        </h:column>
          <a4j:support
            event="onselect"
            immediate="true"
            action="#{selectionListenerBean[selectionListenerAction(suggestedPerson)]}"
            requestDelay="1000"/>
      </rich:suggestionbox>



      The rich:suggestionBox's suggestionAction works because I am not trying to pass in any arguments. The a4j:support's action does not because I am passing in an argument.


      How do I get this to work with Seam's argument passing?


      Thanks,
      Ryan