RichFaces 4 and @ViewScoped

I am switching from RichFaces 3.3.3 to 4.0 and am facing a problem that cannot figure out how to solve.

So far, I have used the @KeepAlive RichFaces annotation to reach the View area with beans, but in new version 4 there is no such function yet (as far as I know). So I thought the @ViewScoped annotation would be a natural (and quick) replacement, but it does not work. Here is the relevant code that gives me problems. It displays a table containing clients with names as links, so when you click on a name, it brings up a pop-up window for editing data. It works in v3.3.3 with @KeepAlive, but not in v4 with @ViewScoped (popup does not get called).

Page:

<h:form prependId="false"> <rich:dataTable id="table" value="#{myBean.customers}" var="customer"> <!--...headers...--> <h:column> <a4j:commandLink action="#{myBean.selectCustomer}" oncomplete="#{rich:component('popup_customer_editor')}.show();" render="form_customer_editor"> ${customer.name} <f:setPropertyActionListener value="#{customer}" target="#{myBean.selectedCustomer}"/> </a4j:commandLink> </h:column> <h:column>${customer.address}</h:column> </rich:dataTable> </h:form> <rich:popupPanel id="popup_customer_editor> <h:form id="form_customer_editor"> <!--...form fields...--> </h:form> </rich:popupPanel> 

bean:

 @ManagedBean @ViewScoped //It was @KeepAlive before public class MyBean implements Serializable { private String name; private String address; private Customer selectedCustomer; //POJO class //getters and setters ... public String selectCustomer() { name = selectedCustomer.getName(); address = selectedCustomer.getAddress(); return null; } } 

Any help would be appreciated

+4
source share
1 answer

There are two reasons why your action cannot be triggered:

  • You have a field that has been submitted and verification / conversion is completed . If you have validation or conversion errors, the action will not be called. You must have <h:messages> to make sure you see it, and since it is a4j: clickLink, put it inside a4j:outputPanel as follows: <a4j:outputPanel ajaxRendered="true"><h:messages/></a4j:outputPanel> .

  • You have a <h:form> inside another <h:form> and you are trying to send an internal one. You can track this with firebug really, really easy. For some reason, the JSF decides not to do anything.

Looks like you're doing funk business here:

  • reformat forms . I had serious problems with reerendering <h:form> in JSF2 (namely, they stopped working), especially. with the richfaces modular panel, made the way they implement the actual panel, where they move content from anywhere in the DOM in the <body> element. Therefore, I recommend creating <h:panelGrid> inside the form and re-executing it.
  • <f:setPropertyActionListener> . Indeed? You must also have EL2, so you can change this:

     <a4j:commandLink action="#{myBean.selectCustomer}" oncomplete="#{rich:component('popup_customer_editor')}.show();" render="form_customer_editor"> ${customer.name} <f:setPropertyActionListener value="#{customer}" target="#{myBean.selectedCustomer}"/> </a4j:commandLink> 

to

 <a4j:commandLink action="#{myBean.selectCustomer(customer)}" oncomplete="#{rich:component('popup_customer_editor')}.show();" render="form_customer_editor" value=#{customer.name}"/> 

+3
source

Source: https://habr.com/ru/post/1346669/


All Articles