NB This question is about pure JSF2. I'm aware that there are third party frameworks, like PrimeFaces, that provide required functionality. But I'm looking for solution for pure JSF.
Inside JSF <h:form>
I have list of blocks rendered with <ui:repeat>
(!). Each block has a <h:commandLink>
"Submit this block" that should submit or process two values of that block - text and radio button.
CommandLink looks like this:
<h:commandLink value = "Submit this block">
<f:ajax
listener="#{myFormBean.updateFormBlock(blockModel)}"
event="click"
render="@form"
execute="@form" />
</h:commandLink>
Constraints: blocks, are be placed inside form (red rectangle) and I cannot change it.
Problem. When I click "Submit this block", the whole form is submitted (block 1 and block 2), and I don't want that.
Is there any way to submit only fields of the block?
Solution:
For each component that should be submitted - there must be unique id
attribute defined. NB! Despite the fact that components are inside ui:repeat
block, 'id' attribute value must not contain any rowIndex! (that was my mistake). Pure static text for id (jsf is clever enough - it'll figure out how to find component). The same id values should be defined (space separated) in f:ajax
attributes execute
and render
(see linked topic for details), instead of "@form".
Example
If edit component (with text "part 1") have id="myEdit" and radio button have id="myRadio" - then submit button could look like that:
<h:commandLink value = "Submit this block">
<f:ajax
listener="#{myFormBean.updateFormBlock(blockModel)}"
event="click"
render="@form"
execute="myEdit myRadio" /> </h:commandLink>