0

I have a composite component, which has an id I would like to send as a parameter when executing one of many posiible actions inside the composite component. I know I can use something like;

<h:form id="testForm">
    <p:commandButton value="#{testReqBean.label}" 
                     actionListener="#{testReqBean.perform()}"
                     process="@this or @form" update="@form" ajax="true" >
           <f:param value="#{cc.attrs.id}" name="CC-Id" />
     </p:commandButton>
</h:form>

now, imagine I have many forms or buttons with specific actions inside the composite component... is there a way to define the parameter I want to send in the request just once ? I mean not adding an f:param inside each form/button (depending on the process @form or @this) but one for the whole composite component?

Thanks in advance!

Rodrigo Martinez
  • 913
  • 3
  • 13
  • 29

2 Answers2

0

Maybe one solution would be to use viewparam but this only works if you can add a request parameter.

<f:metadata>
    <f:viewParam value="#{your_bean.your_property_name}" name="request_param"/>
</f:metadata>

The only problem here is that whoever implements your composite component would have to set the above when needed, but it still an abstraction to this problem of having to set the same property for all components in same page.

Esteban Rincon
  • 2,040
  • 3
  • 27
  • 44
0

I gather that the <h:form> is enclosed in the composite component itself.

Just use a plain HTML hidden input field.

<h:form>
    <input type="hidden" name="CC-Id" value="#{cc.attrs.id}" />
    ...
    <p:commandButton />
    <p:commandButton />
    <p:commandButton />
    ...
</h:form>

Unrelated to the concrete problem, having an entire form in a composite is kind of strange. This is then food for read: When to use <ui:include>, tag files, composite components and/or custom components?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555