0

Some time ago, based on one of @BalusC answers (really don't know which one of them) I wrote a facelet tag that is a kind of a button generator, that generates a variable number of buttons disposed side-by-side, each one with some parameters passed through the attributes.

Now I want to turn the facelet tag into a composite component (because on the latter, I have the cc:interface tag, that provides information to others developers who wants to use the custom component).

In the rewriting process I must deal with the actions attributes of the dynamically generated buttons. In the facelet tag approach I don't have to declare them as methods, so I can pass their names as simple strings and process them inside the facelet tag also as simple strings and call the action methods. In the composite component approach it seems that I must pass the methods names as actual methods names (by using the method-signature attribute of cc:attribute). The problem is: as I don't know previously the number of buttons (it generates the buttons dinamically), I'm not able to declare the action methods in the cc:interface section.

A simplified version of my working facelet tag is:

<c:set var="idValues" value="#{fn:split(ids,',')}" />
<c:set var="actionValues" value="#{fn:split(actions,',')}" />
<c:set var="numberOfButtons" value="#{fn:length(idValues)}" />

<h:panelGrid id="#{id}" columns="#{numberOfButtons}">
    <c:forEach begin="0" end="#{numberOfButtons-1}" varStatus="i">
        <p:commandButton id="#{idValues[i.index]}"
                         action="#{bean[actionValues[i.index]]}" />
    </c:forEach>
</h:panelGrid>

and the facelet tag can be used like this:

<my:button id="idButton" 
           ids="btnSave,btnCancel"
           actions="onSave,onCancel"
           bean="#{myBean}" />

[EDIT]

As sugested by @BalusC in the answers, adding code like below in the taglib.xml file was enough for the Eclipse autocompletion to work fine:

<tag>
    <tag-name>button</tag-name>
    <source>tags/bottons.xhtml</source>
    <attribute><name>id</name></attribute>
    <attribute><name>ids</name></attribute>
    <attribute><name>actions</name></attribute>
    <attribute><name>bean</name></attribute>
</tag>
julianobrasil
  • 8,954
  • 2
  • 33
  • 55
  • 1
    *"because on the latter, I have the cc:interface tag, that provides information to others developers who wants to use the custom component"* Which information exactly do you want to provide which is apparently impossible with the taglib.xml file? Nonetheless, this is perhaps food for thought: http://stackoverflow.com/q/6822000 – BalusC Aug 06 '16 at 18:15
  • Some IDEs show a list of existing attributes when the user hit some key combination like ctrl+space in Eclipse, or get some help about the attributes (which I can put in the shortDescription attribute of cc:attribute). Ok... I`ll look for some information about the taglib.xml file. I haven't given it any great importance... at least until now. Thanks for the tip. – julianobrasil Aug 07 '16 at 03:15
  • Thank you, @BalusC. The taglib.xml does what I need. I underestimated its cababilities. – julianobrasil Aug 07 '16 at 03:30

0 Answers0