ViewState lost after AJAX request - ajax

I have a very strange error with the following code:
<h:form id="myForm">
<h:panelGroup id="myPanelGroup">
...
<h:commandButton
value="randomtext"
action="#{mybean.action}" tabindex="301"
<f:ajax execute=":myPanelGroup" render=":messages #form"/>
</h:commandButton>
</h:panelGroup>
...
</h:form>
So the problem is that after I click on the button the form (myForm) looses its viewState after render. The strange is that in my dev env it is working, but on an other server it is not. Have I made some common mistake with this kind of execute/render pair settings or what else could cause such problem? I was also wondering that probably the 2 servers have different Mojarra version or something like that.
The messages in the render attribute is an id of a panelgroup in an other form.
The container is a WebLogic server with JSf 2.1.
Any ideas?
Thanks!

So I found out it is a common JSF issue that can be solved with the following library:
http://showcase.omnifaces.org/scripts/FixViewState
More info:
http://balusc.blogspot.hu/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichContainsAnotherForm

Related

How can I display the reason for <a4j:status> error?

I'm currently debugging an annoying AJAX bug in our web application using JSF2 and RichFaces v4.5.12.Final where I need further information about the reason why an ajax update fails.
We generate rather complex forms with several elements and on some of these forms the following code snippet fails to re-render and sets to error.
<h:selectBooleanCheckbox value="#{myBean.value}">
<a4j:ajax event="valueChange" execute="#form" render="#form,messages" status="minimal" />
</h:selectBooleanCheckbox>
The AJAX status is displayed using the following code:
<a4j:status name="minimal" onstart="$('body').css('cursor', 'progress');" onstop="$('body').css('cursor', 'default');">
<f:facet name="start">
<h:graphicImage name="/3rd-Party/Fugue-Icons/hourglass.png" styleClass="middle" />
</f:facet>
<f:facet name="stop"></f:facet>
<f:facet name="error">
<h:graphicImage name="/3rd-Party/Fugue-Icons/exclamation-red.png" styleClass="middle" />
</f:facet>
</a4j:status>
Is there any way to display the reason why the render fails? Can I access any variable containing some kind of error message?
Debugging shows that the execute is performed and doesn't result in any server side errors. The error happens on client side where the AJAX fails to reload the page content. It doesn't matter if we use render="#all" or anything else... the error occurs on some of our pages. Others with the same <a4j:ajax> work normally.
The error handler is triggered when there is a problem with the server response. RichFaces has <a4j:log> specifically for debugging, it will at least tell you what kind of error it is.

Ajax not working on a jsf 2.2 simple page

I have a simple jsf 2.2 page and cant figure out why ajax is not working, i searched the web but couldnt find a solution, i'm only showing the relevant part here... these are inside a multpart/form-data form. Nothing happens, the outputText is not shown on page when i toggle the selectBooleanCheckBox.
<h:selectBooleanCheckbox value="#{worksheetEditBean.sendMail}"><h:outputLabel value="Send Email"/>
<f:ajax event="change" render="mailPnl" execute="#this"/>
</h:selectBooleanCheckbox>
<h:panelGroup id="mailPnl">
<h:outputText rendered="#{worksheetEditBean.sendMail}">Hello</h:outputText>
</h:panelGroup>

Is it ok to have multiple primefaces socket tag on a page

Is it fine to have multiple tags with different channel on a page, for me it never worked.
Is it a good use of prime push, Or is there any alternative to receive server push messages from multiple channels on a page. Here is piece of sample code what i have tried
<h:form>
<p:socket channel="/pushMessages/#{session.id}">
<p:ajax event="message" update=":navigation-form"/>
</p:socket>
<p:socket channel="/pushMessages/cart/#{session.id}">
<p:ajax event="message" update=":message-form"/>
</p:socket>
</h:form>
Yes this works for me without a problem in PrimeFaces 6.2 (keep in mind that p:push is deprecated and the JSF 2.3 websockets is advised

How to prevent reload of page in Richfaces on action/event?

I am using JSF2.0 and RichFaces 4.0.1 Final. I want to prevent the reload of page on occurence of event.
My use case is: There is a Command button with hidden style. I need to invoke the event attached to it in certain case from Javascript.
Problem: Though I am able to invoke the hidden button, the issue is, the moment it gets invoked, the page is getting reloaded. I want to prevent this reload.
Just use ajax:
<h:commandButton id="foo" action="#{bean.foo}" styleClass="hide">
<f:ajax />
</h:commandButton>
Or, since you're already using RichFaces:
<a4j:commandButton id="foo" action="#{bean.foo}" styleClass="hide" />

valuehchange listener, ajax

I am using a JSF page in a portal environment. If I use a valueChangeListener, the method is not called in the backing bean unless I use onclick="submit()". This submits my page which I don't want. Same is the case with actionListner.
Also, if I use ajaxRefreshSubmit, my whole page is submitted rather than submitting the specified part on which the ajaxRefreshSubmit is used.
Why this behaviour? Is it because we are using it in a portal environment, or did we miss something in the configuration files?
The valueChangeListener runs indeed only when you submit the form to the server. It's indeed one of the major JSF beginner's misconceptions to think that it runs at the client side. It's not part of HTML or JavaScript code which runs in the webbrowser. It's part of Java/JSF code which runs in webserver. So the client has to send a request from webbrowser to webserver somehow. Submitting the form is one of the ways.
For the remnant, I don't have anything to say about ajaxRefreshSubmit since that's specific to the IBM component library which I don't use (and also can't because it's not open source nor freely available). If you don't get more respons here at Stackoverflow, then your best bet may be posting the question at their own forum at developerworks. It's only not as active and high-quality as here.
<h:form id="toilclaimform">
<h:panelGroup id="container">
<!-- Read only version -->
<hx:commandExButton type="button" id="testButton2" value="Submit" styleClass="hideRefreshToil" onmousedown="$.resourceManUtilities.formRefreshCookie()" >
<hx:behavior event="onclick" id="behavior3" behaviorAction="get" targetAction="container" ></hx:behavior>
</hx:commandExButton>
<hx:commandExButton onmousedown="runToilVal()" onmouseup="$.resourceManUtilities.formSubmitCookie()" type="submit" id="testButton" value="Submit" styleClass="rmButtons" action="#{toilClaimBean.submit}">
<hx:behavior event="onclick" id="behavior2" behaviorAction="get" targetAction="container" ></hx:behavior>
</hx:commandExButton>
</h:panelGroup>
</h:panelGroup>
<hx:ajaxRefreshSubmit id="ajaxRefreshRequest1" onstart="$.resourceManUtilities.ajaxLoadingStarting('form')" oncomplete="$.resourceManUtilities.ajaxFormSubmit('hideRefreshToilList')" target="container"></hx:ajaxRefreshSubmit>
</h:form>
When using this library you know longer use the standard command buttons, you instead use the hx command button, there is an example in the code above. Using this button will ensure that you don't get a full pagr refresh and will update the desired portlet.
Cheers

Resources