Skip to main content

JSF2: Problems using buttons in facets to composite components

2 replies [Last post]
chris.joelly
Offline
Joined: 2011-08-02
Points: 0

Hello,

i want to add buttons via facets to a composite component. The component renders a datatable and i want to pass the row entity to the action method of the buttons as parameter. Unfortunately the passed in parameter is always NULL. If i use the datatable and the buttons directly, without composite component stuff, everything works as expected.
Is it not possible to set buttons via facets to composite components?

<composite:interface>
  <composite:attribute name="list" />
  <composite:facet name="rowButton" />
</composite:interface>

<composite:implementation>

  <p:dataTable id="customer" var="customer" value="#{cc.attrs.list}">
    ...
    <p:column>
      <composite:renderFacet name="rowButton" />
    </p:column>
  </p:dataTable>

</composite:implementation>
      <customer:list list="#{customerControllerBean.list}">
        <f:facet name="rowButton">
          <h:commandButton value="#{msg.deleteButtonLabel}"
        action="#{customerControllerBean.delete(customer)}" />

          <h:commandButton value="#{msg.deleteButtonLabel}" action="#{customerControllerBean.deleteCustomer}">
        <f:setPropertyActionListener target="#{customerControllerBean.customer}" value="#{customer}"/>
          </h:commandButton>

          <h:button outcome="customerdetail.jsf?id=#{customer.id}"
        value="#{msg.editButtonLabel}" />
        </f:facet>
      </customer:list>

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
oversteer
Offline
Joined: 2011-03-28
Points: 0

Edit: I think f:facet can only have one child, can you try wrapping everything inside the facet in a panelGroup. There are lots of people having problems with this, with no clear solution that I've seen. Although a great concept I usually hit a brick wall with composite components when trying to do anything beyond the very simple, which tends to outweigh the potential benefits.

Original answer:

I'm pretty rusty on composite components but can you try wrapping everything inside the composite:implementation in:

<composite:implementation>
  <div id="#{cc.clientId}">
   ...
  </div>
</composite:implementation>

I vaguely recollect issues with generating client ids in the generated code because the composite needs a naming container. You could use a <span> instead of a <div>, or a panelGroup with or without layout="block".

This is a long shot!

chris.joelly
Offline
Joined: 2011-08-02
Points: 0

thanks for the hints. i tried with div, span and panelGroup. i can see that the ids of the datatable and the buttons change, but unfortunately the passed in object is still null.
from stack overflow i got answer that composite components have logs of bugs and i should switch to templating. and i switchd to a template and it really works.