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.
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!
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
Im facing problem expiring session in JSF 2.2, I tried many solutions but in vain.
FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
and
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
request.getSession().invalidate();
I checked bean with both scopes 'View' and 'Session'. Im not using JSF scope annotations rather our application architecture restrict us to use Spring scope like #scope("session") and i created view scope bean (according to: http://comdynamics.net/blog/109/spring3-jsf2-view-scope/) and register with Spring scopes and used like #scope("view"). It doesn't throw any exception, calls bean logout code and navigate to login page but after logging out when i try to access homepage or any other page it shows all session data even in different browser.
It was working fine with JSF 1.2, I upgraded JSF from 1.2 to 2.2 and now its not working since.
Please help me in this regard.
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.
The real question: Is there a way to clear certain attributes for all components on an initial page load?
Background info:
In my application, I have a JSF 2.0 frontend layer that speaks to a service layer (the service layer is made up of Spring beans that get injected to the managed beans).
The service layer does its own validation, and I do the same validation in the frontend layer using my own validator classes to try and avoid code duplication somehow. These validator classes aren't JSF validators, they're just POJOs.
I'm only doing validation on an action, so in the action method, I perform validation, and only if it's valid do I call through to the service layer.
When I do my validation, I set the styleClass and title on the UIComponents using reflection (so if the UIComponent has the setStyleClass(:String) or setTitle(:String) methods, then I use them).
This works nicely, and on a validation error I see a nicely styled text box with a popup containing the error message if I hover over it. However, since the component is bound to a Session Scoped Managed Bean, it seems that these attributes stick. So if I navigate away and come back to the same page, the styleClass and title are still in the error state.
Is there a way to clear the styleClass and title attributes on each initial page load?
Thanks,
James
P.S. I'm using the action method to validate because of some issues I had before with JSF 1.2 and it's validation methods, but can't remember why... so that's why I'm using the action method to validate.
Ok, so I must use a PhaseListener, see this blog entry by BalusC and this other blog entry, that's a much better way of doing what I'm doing already - setting the styleClass manually using reflection - which gets all components with messages and highlights them... I'm gonna do the same, however think it's possible to add an attribute instead, haven't tried it yet.