weeks ago we are migrating our project from JSF 1.2 to JSF 2.0 and we are already comparing MyFaces and Mojarra implementations.
I've almost done a prototype on Mojarra 2.1.7 and it works quite well, but when trying to make it work with MyFaces impl (2.1.6) it doesn't (pom modified to not mix Mojarra and MF implementations).
The fact is that when I make an ajax request it rerenders the view, but when I try to make another action with request (ajax, navigation) it does nothing.
In FireBugs, after the second action it throws this error:
<partial-response>
<error>
<error-name>java.lang.IllegalStateException</error-name>
<error-message><![CDATA[java.lang.NullPointerException: state]]></error-message>
</error>
</partial-response>
My beans are ViewScoped and I'm using Primefaces components(if it helps...), so I don't know why is the state null after first ajax request.
Anyone knows the solution?
Thanks, Carlos
Related
I'm working migrating a legacy software that use a lot of cases like <ui:repeat var="area" value="#{areaList.getResultList()}">. Where getResultList() executes a DB query. One of the problems is that when an ajax call is made, JSF at the phaseId 2 (APPLY_REQUEST_VALUES) visit all UIViewRoot children, and executes this DB queries.
The question is, there is a way to avoid this? Is correct to think when the request is an ajax type, don't visit all children. Is a JSF / JSF 2 issue or Primefices issue? The migration also include JSF 1 to JSF 2 (Mojarra)
(I have zero chance to modify the way of value is retrived)
UPDATE:
I'm using Wildfly 25.0.0 (it comes with jsf 2.3 by def) and JSF 2.1 Mojarra_2.1.29. But if you observe the stack when de ui:repeat is being accessed:
PartialViewContextImpl belong to JSF 2.3 (not mojarra_2.1.29) and there is where the original problem is, I think.
The strange is when the app starts, the log says:
INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 85) Inicializando Mojarra 2.1.29
I followed the next doc to configure a new JSF implementation on Wildfly: Link
UPDATE
I've extended UIRepeat and then solved my problem:
Thanks!
I wanted to upgrade JSF 2.1 (myfaces) to 2.2 in my application. I just changed two myfaces....jar files in TomEE/lib folder (TomEE-1.7.5). Everything seems to work well except one thing. I have an error page configured in web.xml:
<error-page>
<error-code>500</error-code>
<location>/error/500.jsf</location>
</error-page>
In order to catch error in case of ajax post, omnifaces' FullAjaxExceptionHandlerFactory is declared in faces-config.xml:
<factory>
<exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>
In error page there is a preRenderView function, in which there is a conditional redirect. In JSF 2.1 it was working perfectly. But with JSF 2.2 in case of redirection, because of some other exception I get this message:
Oops!
A problem occurred during processing the ajax request. Subsequently,
another problem occurred during processing the error page which should
inform you about that problem.
The other exception in log:
SEVERE: FullAjaxExceptionHandler: Well, another exception occurred
during rendering error page '/error/500.jsf'. Trying to render a
hardcoded error page now. java.lang.IllegalStateException: Cannot
change buffer size after data has been written
I tried to use something other event handler instead of preRenderView (I thought maybe the redirection should be made at an earlier point of the lifecycle(?)). With postAddToView event the result is the same, other events are not called at all.
Also instead of f:event I tried to use f:viewAction of JSF 2.2, but in case of ajax post none of the possible viewAction events is called on the error page (onPostback="true" parameter also did not help).
Questions:
Why I get the other exception on error page in case of redirection? (There was no any problem with myfaces 2.1)
Why viewAction function is not called at all on error page? (when the error resulted to go to the error page occured in an ajax request)
So how to make (conditional) redirect from error-page with JSF (myfaces) 2.2?
I have a JSF 2.1 + Primefaces 5.1 web application and I want to handle ViewExpiredExceptions. Besides the configuration in web.xml (mapping the exception to a location via <error-page>), I read that we need to treat these exceptions when they are thrown during ajax requests.
Primefaces provides a <p:ajaxExceptionHandler> for this purpose. I tried to use it and, although I could see the exception being thrown in the server log, I could not do anything else. Maybe I'm using it the wrong way. How could I, for instance, send the user to the index.xhtml page when such an exception occurs, refreshing all ajax components?
I defined the exception handler factory in faces-config.xml:
<factory>
<exception-handler-factory>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
</exception-handler-factory>
</factory>
And declared the facelets handler in my template page:
<p:ajaxExceptionHandler type="javax.faces.application.ViewExpiredException"/>
Here's my web.xml configuration for these exceptions:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/index.xhtml</location>
</error-page>
After being unsuccessful with this approach, I tried the explicit definition of the exception handler (Check if session exists JSF) but without success either.
Can anyone tell me how to solve this problem? (I'm trying to stick with plain JSF and Primefaces, although I know that Omnifaces provides a similar solution to Primefaces', but I haven't tried it yet).
I am in the middle of a migration from Richfaces 3.3.3 to Richfaces 4.3.0, which called for a JSF upgrade from 1.2 to 2.1. We are also using Spring Webflow 2.3.2 (upgraded from 2.1.1) for conversation definition. All beans are managed by Spring (no JSF managed beans). Several Richfaces components had to be adjusted for the application to work properly again. The problem I have now concerns the rich:pickList component, which looks like this (I took the showcase example and edited it to depict the problem):
<rich:pickList id="ownPicklist" value="#{listSelectBean.selectedCapitals}"
sourceCaption="Available cities" targetCaption="Selected cities"
listWidth="165px" listHeight="100px">
<a4j:ajax event="change" execute="#this" render="#{mainBean.dynamicRerenderList}" />
<f:selectItems value="#{listSelectBean.capitals}" var="capital"
itemValue="#{capital}" itemLabel="#{capital.name}" />
<f:converter converterId="CapitalsConverter" />
</rich:pickList>
Now unlike the showcase example, our ListSelectBean is a Spring bean and is defined like this:
<bean id="listSelectBean" class="com.xyz.example.bean.ListSelectBean" scope="request" />
The custom converter is registered in the faces-config.xml:
<converter>
<converter-id>CapitalsConverter</converter-id>
<converter-class>com.xyz.converter.CapitalsConverter</converter-class>
</converter>
As you can see we have an ajax event handler attached to the pickList, which dynamically calculates a list of components to be rerendered depending on the selected value(s) from the list. This list also contains the pickList itself, which normally has to be rerendered with much less elements to select from. The ajax response I get contains the full source list, but the target list is empty.
Now to the problem:
When I select an element from the left side it jumps to the right side and immediately back again.
I debugged the issue and learned that all the getters and setters of the listSelectBean are invoked correctly as different JSF phases are run through. The same example with JSF managed, request scoped beans works fine (which is in the Richfaces showcase), also with the ajax rerender on the component itself. I suspect a problem with the bean handling in Spring (Webflow). But I can't pinpoint it. Any help will be highly appreciated.
After long hours of debugging I finally found the solution to the problem. As RichFaces uses a HashSet during the rendering process it is important to have the hashCode() and equals() Methods overridden for complex objects (which is a good idea in general) used in the PickList. Otherwise selected objects won't be marked as selected.
Is it even possible to call a backing bean method using Ajax in a JSF 1.0 application and update the server side controls (dropdownlists) in server and push the changes to the client side?
I have no idea on how we could do that. Any help would be highly appreciated.