0

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?

form and 2 blocks

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>
Community
  • 1
  • 1
Aleksey Timohin
  • 591
  • 1
  • 9
  • 15
  • 1
    Partial submit or partial process (execute)? Partial submit only being available in PrimeFaces or IceFaces, but I think partial 'execute' is enough since there are not hundreds of inputs. You explicitly use `execute="@form"` so the behaviour you see is the behaviour to tell it to have. See http://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes (which is effectively a duplicate) – Kukeltje Dec 30 '16 at 09:38
  • Question is about pure JSF. JSF2, btw. No third party frameworks, like PrimeFaces or IceFaces are used. I don't understand the difference between submit and process. Can you explain that (or point me to related)? I assume that it's the case of partial execute. – Aleksey Timohin Dec 30 '16 at 09:56
  • I tried partial execute, but had troubles to specify correct id of elements to be executed. All the blocks are created inside ``. See: http://stackoverflow.com/questions/9147771/how-can-i-set-id-of-hpanelgroup-inside-uirepeat – Aleksey Timohin Dec 30 '16 at 09:59
  • Just use `execute="idOfBlock"` to execute/process/submit a specific block instead of the whole form. The duplicate also handles `execute`/`render` (which is nearly identical to `process`/`update` with only a few differences already explained over there). – BalusC Dec 30 '16 at 10:04
  • @BalusC - your, so-called "duplicate" gives explanation on PrimeFaces (mostly) and JSF ajax, but it does not give the complete answer to my question. How to make it work inside ? Please update "duplicate" answer, or remove duplication mark from my question. – Aleksey Timohin Dec 30 '16 at 10:21
  • 1
    Do it like there is no repeat. The fact that it is in a repeat does not matter, references are relative. Just give your 'block' (which needs to be a jsf component!) an id (e.g. 'block'). If the button is also in the repeat, you can use `execute="block"` just like it would be in a single non-repeating block – Kukeltje Dec 30 '16 at 10:30
  • @BalusC: Enhancing the 'duplicate' that descendents of an explicit id are also processed/executed might indeed be a good enhancement. It is only kind of referenced via `@parent` which is not available in plain jsf – Kukeltje Dec 30 '16 at 10:51
  • @Kukeltje thank you very much for "Do it like there is no repeat" comment. It was the "part of the puzzle" that I missed. I found the solution to my problem. (the problem was that all the id's of JSF components in my code were generated as compound "static_part__"+rowIndex, so removing "+rowIndex" did the trick. I'll update my question later. – Aleksey Timohin Dec 30 '16 at 11:16
  • Haveing the rowIndex would not have been a problem (if the resulting ids were the real ids!!!). You'd just needed to add that compound id in the execute each time – Kukeltje Dec 30 '16 at 11:31
  • As said in comment, just use `execute="idOfBlock"`. No need to manually mess around with IDs. JSF takes care of it. See also a.o. http://stackoverflow.com/q/13378621 – BalusC Dec 30 '16 at 11:40
  • @Kukeltje, rowIndex actually brings problem. ` – Aleksey Timohin Dec 30 '16 at 13:23
  • A sorry, the rowIndex from the repeat... Yes that is certainly not needed (and done automagically) – Kukeltje Dec 30 '16 at 13:24

0 Answers0