RichFaces a4j:poll not working - jsf

My code in RichFaces 3.3.3:
<a:region>
<h:form>
<a:poll id="feed" enabled="true" reRender="feedReader" interval="100"/>
</h:form>
</a:region>
<h:form>
<h:outputText value="#{feedReader2.title}" id="feedReader" />
</h:form>
This is close to the example here: http://www.mastertheboss.com/richfaces/using-ajax-with-jboss-richfaces
What it should do is poll the server which reads an rss feed and gives back the title.
However, this is not working. In Chrome developer tools I can't see any AJAX requests made to the server. Instead, I see an error Uncaught TypeError: Cannot read property action of null on framework.pack.js. The line in which the error occurs is:
this._actionUrl=(this._form.action)?this._form.action:this._form
I can only guess that this is releated to the <h:form> which doesn't have an action attribute. But I don't see why I need this here, as it is not included in all of the examples you can find.
Moreover, I do not want the <h:outputText> to query the bean on page load. My aim is to use AJAX to read the feed after the page is done rendering.
If this is an issue related to my RichFaces version, could someone please give me an example on how to do this in 3.3.3?

I found the issue. It was an error outside the above markup i've included. Had two <h:form> nested, which caused the second one to malfunction.

Related

JSF 2.3 on open liberty. Immediate javax.faces.application.ViewExpiredException

I am experimenting with Open Liberty and wanted to try out JSF-2.3 support. I must be doing something silly because when trying implicit navigation I immediately get the exception:
javax.faces.application.ViewExpiredException: View "/view/index.xhtml" could not be restored.
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:181)
I can render an initial Facelets-page using the following server.xml features:
<featureManager>
<feature>servlet-4.0</feature>
<feature>jsf-2.3</feature>
<feature>el-3.0</feature>
<feature>cdi-2.0</feature>
<feature>jsp-2.3</feature>
</featureManager>
My page is really simple and looks like this:
<h:body>
<h:outputText value="It works!"/>
<br/>
<h:form>
<h:commandLink value="NAvigate" action="view/page2" />
<h:commandButton value="NAvigate 2" action="view/page2" />
</h:form>
</h:body>
I have a corresponding page2.xhtml.
When clicking on either the commandLink or commandButton I get the exception:
javax.faces.application.ViewExpiredException: View "/view/index.xhtml" could not be restored.
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:181)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:195)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:142)
Have I mis-configured something in Open Liberty or are my JSF-mojo just lacking severely?
Ugh.. after testing in another browser (Safari) it worked. Hard-resetting Chrome site storage then fixed the original problem.
This problem must have surfaced somewhere in between automatic restarts.

Input fields not clearing after the validation fails

I have a form, it contains username and password etc... if i gave any wrong value the validation will fail. next if i see the form na that previously given values are coming in the input fields.. i cleared the bean values also. but the input fields are not yet cleared.
i have cleared the input fields using the following link 1st step.
https://cwiki.apache.org/MYFACES/clear-input-components.html
this is working but what the problem is this is working only in <rich:datatable> 1st page.
if i have navigate to second page and next pages and all that Popup panel itself not opening.
i am using the jsf version 2.0,
Please provide a good solution.
Thanks,
You can add OmniFaces Library to your project and use their ResetInputAjaxActionListener
Like this
<h:commandButton value="Update" action="#{bean.update}">
<f:ajax execute="#this" render="#form" />
<f:actionListener type="org.omnifaces.eventlistener.ResetInputAjaxActionListener" />
</h:commandButton>
Read more about it on BalusC blog Reset non-processed input components on ajax update
Are you using session scope ? Change it to request scope. Otherwise, add your xhtml page and bean class.

Cannot find component with identifier in View JSF

I was trying to show messages using a p:growl like this.to be updated on the OnRowSelect Method of a Data Table lazy loading like this
<p:growl id="applyMessages" showDetail="false" global="true" /> and <p:ajax event="rowSelect" listener="#{editBean.onRowSelect}" update=":studyPlanEditForm:display applyMessages"/>
but got the error like this
Cannot find component with identifier "applyMessages" in view.
Please Help.
Check the source code of your page in browser. Then identify the p:growl markup and its generated client-id. It surely is longer than applyMessages and has a prefix similar to containerID:applyMessages. Use this id in your update attribute of the ajax call.

How to update a h:inputHidden with p:commandButton?

I writed an ajax request for any data. But the data don't work with h:inputHidden.
I think it's a bug of Primefaces.
But I don't know how to get the data now.
code:
<h:inputHidden id="buttonData" value="#{buttonDataBean.buttonData}" />
...
<p:commandButton id="getData" action="#{buttonAction.getButtonData}" update="buttonData" />
When I click the commandButton, the value of don't work.
But if I use the h:outputText, it worked.
My requirement:
Before click the commandButton, I have create any html buttons dynamically. I want to click the commandButton and update the name and position of html buttons. So that I must get any data and update the html buttons with Javascript.
how could I do about it?
If I want to use the JavaScript to get the ajax data, how to do it. I see the document and find two method: jsf.ajax.request() and Primefaces.ajax.AjaxRequest(). But I don't know how to use the two method. for example: Primefaces.ajax.AjaxRequest("test.xhtml",,). The "test.xhtml" how to request the method testMethod of TestAction?
use firebug to inspect html code. you can see new value
<h:form id="form">
<h:inputHidden id="buttonData" value="#{buttonDataBean.buttonData}" />
<p:commandButton id="getData" value="button"
action="#{buttonDataBean.buttonAction}" update="buttonData" />
</h:form>
If your problem does not get solved with primefaces ajax, you can use the native ajax provided by jsf have a look at it.It works, i have done many such things with it.
Instead of using a hidden input you could take advantage of JSF and use a f:param or f:attribute.
Read this really fine article, under the brand of BalusC: http://balusc.blogspot.com/2006/06/communication-in-jsf.html .

JSF 2 : Ajax errors not displayed

Im currently trying out the ajax feature, and im curious about how can i display the error messages occured when i do the ajax stuff ?
For example, i have a primefaces button :
<p:commandButton value="Refresh" update="debugPanel messages"
action="#{checkbocLabBean.submit}"/>
When testing that button, nothing seems to happen, until i check the server logs, there's an exception. It turns out that i have a typo. Should be #{checkboxLabBean.submit}.
The only thing i can think of right now is to have disable the ajax, adding ajax="false" in my case, and the error will show up.
Is there any other ways to show errors right into the browser in development phase when using ajax requests ?
Ajax requests happens asynchronously. They do by default not affect the entire document. Exceptions thrown during PrimeFaces' ajax requests are delegated to <p:ajaxStatus>. You can do your thing in <facet name="error">.
<p:ajaxStatus>
<f:facet name="start">Loading...</f:facet>
<f:facet name="success"><h:outputText value="" /></f:facet>
<f:facet name="error">An error has occurred!</f:facet>
</p:ajaxStatus>
If you rather want to replace the current document with the error page -which is a very reasonable choice- then it's good to know that PrimeFaces uses jQuery under the covers and that you can configure jQuery as follows to do so:
<script>
jQuery.ajaxSetup({
error: handleXhrError
});
function handleXhrError(xhr) {
document.open();
document.write(xhr.responseText);
document.close();
}
</script>
See also:
How to safeguard webapplication on server-side errors?
Handling of server-side HTTP errors in jQuery's ajax requests

Resources