JSF Ajax called only 1 time
In JSF2, I have XHTML like this:
<h:form id="myForm"> ... <c:forEach items="#{myController.header}" var="hd" varStatus="count"> #{hd} <h:selectOneMenu value="#{myController.type[count.index]}" id="formtype" > <f:selectItem itemValue="Nop" itemLabel="Nop" /> <f:selectItem itemValue="Yep" itemLabel="Yep" /> <f:ajax render="@form" /> </h:selectOneMenu> #{myController.type[count.index]} <h:selectBooleanCheckbox value="#myController.valid[count.index]}" id="valid"> <f:ajax render="@form"/> </h:selectBooleanCheckbox> #{myController.valid[count.index]} </c:forEach> ... </h:form> And my managed bean has:
private String[] type; private boolean[] valid; which I initialize ( type = new String[...]; and assign a value to each position) when the named bean is loaded 1.
If I change the combo or checkbox, it works , the value changes in the managed bean, and the new value is printed (displayed) on the JSF page. But only for the first time . The following changes do not change anything. This is strange because I have similar code in other applications and it works fine, so I am doing something wrong but cannot find it. My template has h:header , and I do not see any logs in the JS console or in TomEE (I only see. INFO - The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myApp]] after start() had already been called. The second call will be ignored , but I think it is irrelevant). I tried to add execute="@this" / execute="@form" , and others failed, and check all the items in this post , but nothing seems to me.
What mistake do I not see?
EDIT
@Named(value = "myController") @ViewScoped public class MyController implements Serializable { ... I also have <h:messages globalOnly="true" showDetail="true" showSummary="true" /> in my template.
I think I understand, finally!
Thanks to two things:
Paragraph 3 in response to BalusC . I added an identifier to my post in the
<h:messages id="msg"template, and then used<f:ajax render="@form msg"....The errorj_idt1: Validation Error: Value is required.Then I was able to find a solution in this post : change the required parameter from
trueto<f:viewParam required="#{!facesContext.postback}". This was not required in my other applications because it was βfalseβ because it could be called with or without a parameter. When it was called with a parameter, it worked because, thanks to serendipity, the page could be called without it.
Go to the same problem, my <f:ajax> will work for the first time, and then nothing ... without errors or anything on the page. After several hours and countless search engines, nothing happened. (Most of the StackOverflow questions actually had the opposite problem, Ajax did not start the first time, but then it would work just fine). I finally stumbled upon this question, which accurately described what I saw.
Previously, I tried to re-render only part of the page, but I noticed that as soon as I changed the render attribute to "@all" , I got the same error message described above:
j_idt1: Validation Error: Value is required
I scrolled up and noticed that I have <f:viewParam> with the required value of "true" . I made the change described by user 1156544 and it did the trick.