JSF2.0 with <f: ajax> only works once

I have a problem with a tag in JSF2.0, and I hope someone can indicate what I'm doing wrong. Here is what I got in the user interface:

<h:panelGroup> <h:form id="theForm"> <h:selectOneMenu id="theMenu" value="#{viewBean.selectedItem}"> <f:ajax event="change" render="selectedItemText"/> <f:selectItem itemLabel=""/> <f:selectItems value="#{viewBean.selectableItems}"/> </h:selectOneMenu> <h:outputText id="selectedItemText" value="#{viewBean.selectedItemText}" /> </h:form> </h:panelGroup> 

This works fine - my bean chain binding support has the setSelectedItem method, and it called, and it does its thing the first time I select another item from the menu; The output text is updated in the interface, and I'm happy. However, further changes to the menu selection do not cause the setter to be called via ajax. I also tried this with the f:ajax tag listener - the listener method is only called for the first time (breakpoints in the code to figure this out).

Am I doing something wrong?

+4
source share
4 answers

I had a similar problem.

My second commandButton below only works once in the JSF view below, which has a view parameter. Adding <f:param> to my first commandButton resolved the issue. This situation, not covered by BalusC is a very useful discussion .

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <f:view> <f:metadata> <f:viewParam name="id" value="#{fooManager.millis}" required="true"/> </f:metadata> <h:head> <meta http-equiv="content-type" content="text/html;charset=utf-8"/> </h:head> <h:body> <h:form id="fooForm"> <h:commandButton id="barBbutton" value="foo:test" action="#{fooManager.test}"> <f:param name="id" value="1"/> <f:ajax render="fooMillis1"/> </h:commandButton> <p> <h:outputText id="fooMillis1" value="foo:display1: #{fooManager.millis}"/> </p> <p> <h:outputText id="fooMillis2" value="foo:display2: #{fooManager.millis}"/> </p> </h:form> <h:form id="barForm"> <h:commandButton id="barButton" value="bar:test" action="#{barManager.test}"> <f:ajax render="barMillis1"/> </h:commandButton> <p> <h:outputText id="barMillis1" value="bar:display1: #{barManager.millis}"/> </p> <p> <h:outputText id="barMillis2" value="bar:display2: #{barManager.millis}"/> </p> </h:form> </h:body> </f:view> </html> 

And my FooManager and BarManager look the same:

 @ManagedBean @ViewScoped public class FooManager { public long getMillis() { return millis; } public void setMillis(long millis) { this.millis = millis; } public void test() { setMillis(System.currentTimeMillis()); } private long millis; } 

When it does not work, my Weblogic / Mojarra library does not give any useful hint. There is no mistake. Only after numerous attempts did I come up with a working button similar to the first one above.

+4
source

I had the same problem. For the code below, ajax only ran once.

 <h:inputText id="element_id" value="#{viewBean.someValue}"></h:inputText> <h:commandLink action="#{viewBean.someAction}" value="click me"> <f:ajax render=":my_form:another_element" execute="element_id> </f:ajax> </h:commandLink> 

When I add a render attribute to the attribute, the element that I execute is then triggered every time.

 <h:inputText id="element_id" value="#{viewBean.someValue}"></h:inputText> <h:commandLink action="#{viewBean.someAction}" value="click me"> <f:ajax render=":my_form:another_element element_id" execute="element_id> </f:ajax> </h:commandLink> 
+3
source

I had a similar problem, in my case everithing worked fine in all browsers, except that in IE9 ajax was launched only once.

I used render="@form" , and when I changed it to render="@all" , it worked fine. I do not know why, since there is only one form on this page, and all my components are in this form.

So I would advise you to check the render and execute tags, at least in my case it was a solution

+1
source

I had the same error, it was fixed using Primeface's p:ajax instead of f:ajax .

0
source

Source: https://habr.com/ru/post/1339760/


All Articles