Tag Archives: JSF 2

JSF 2 AJAX/Submit issues with @ConversationScoped Beans

When working with ConversationScoped Beans and AJAX, you always have to be careful not to run into BusyConversationExceptions.

Lets consider the following scenario where the inputField triggers an ajax event when the value is changed:

[xhtml]
<h:inputField value="#{conversationScopedBean.bar}" …>
<f:ajax event="change" render="@this" … />
</h:inputfield>

<h:commandButton … action="fooAction.proceed" />
[/xhtml]

When you change the input and click on the commandButton, without triggering the change event by exiting the field first, you will encounter a BusyConversationException. This happens because the click triggers the change event firing an AJAX request, immediately followed by the button’s submit.
Continue reading JSF 2 AJAX/Submit issues with @ConversationScoped Beans

Keeping focus on element with JSF 2 AJAX render

Anyone who has developed JSF 2 applications for any length of time, will have come across the issue that element focus may get lost when AJAX rendering is preformed.
So what is the cause of this? I have constructed a simple webapp to demonstrate the issue and show a potential solution.

One of the simplest possible scenario is a simple value change event that triggers a render on the following field:

[xhtml]
<h:outputLabel value="Input field: " />
<h:inputText id="firstValue" value="#{sessionBean.firstValue}" tabindex="1">
<f:ajax event="change" render="secondValue thirdValue" />
</h:inputText>
<h:outputLabel value="Render to Upper field: " />
<h:inputText id="secondValue" value="#{sessionBean.secondValue}" tabindex="2" />
[/xhtml]

On the server side we are simply preforming a toUpper on the firstInput and assigning it to the secondValue. In this case implemented as a simple session scoped CDI bean, the underlying backing bean infrastructure has no influence on the response that JSF produces or how it is treated by the client.
Continue reading Keeping focus on element with JSF 2 AJAX render