I'm creating an h:form within a cycle, and I'd like each form to have a hidden input with the value taken from the cycle's variable. Like so:
<ui:repeat value="#{controller.elements}" var="element开发者_开发百科">
<h:form>
<h:inputHidden value="#{element.value}"/> <!-- Taken from element.value, but submitted to controller.myvalue -->
<h:commandLink action="#{controller.myaction}"/>
</h:form>
</ui:repeat>
Question is, how do I supply the input's value from one source, for example, from #{element.value}, but when submitted, I'd like it be set to #{controller.myvalue}?
Apparently the value attribute specifies both the source and the destination. I tried to do something like this:
<ui:param name="#{controller.myvalue}" value="#{element.value}"/>
<h:inputHidden value="#{controller.myvalue}"/>
Which didn't work. It must be a known issue, but I couldn't find a solution.
Thanks for help, Yuri.
Use f:setPropertyActionListener
.
<ui:repeat value="#{controller.elements}" var="element">
<h:form>
<h:commandLink action="#{controller.myaction}">
<f:setPropertyActionListener target="#{controller.value}" value="#{element.value}" />
</h:commandLink>
</h:form>
</ui:repeat>
This will do controller.setValue(element.getValue())
before controller.myaction()
.
精彩评论