简体   繁体   中英

Primefaces listener on selectOneMenu

I've problems with the primefaces ajax call listener. (primefaces 4.0 , JSF 2.0 , JBoss 6.1.1 )

This is the selectOneMenu that I defined:

<p:selectOneMenu id="sistema" label="Sistema" value="#{searchSchedulingBean.selectedSystem}">
    <p:ajax listener="#{searchSchedulingBean.systemChangeListener}" 
        process="@this"
        event="change"
        update="autostrada"/>
    <f:selectItems value="#{searchSchedulingBean.systemsList}" />
</p:selectOneMenu>

And this is the main part of my managedBean

@ManagedBean
@ViewScoped
public class SearchSchedulingBean implements Serializable {
    ...
    @PostConstruct
    public void init() {
        logger.info("init executed");
        ...
    }

    public void systemChangeListener() {
        logger.info("listener executed");
        ...
    }

When I open the page the log tell me that the init method is executed and the selectOneMenus are correctly populated so I assume that the managed bean is working. If I change the selectOneMenu that I wrote above the selectOneMenu that I want to modify is influenced because it is the only selectOneMenu of the page that selects the initial value of the list but the entries are not updated as I want and the method systemChangeListener is not executed because I don't see "listener executed" in the log.

I tried to change the managed bean from @ViewedScoped to @RequestScoped for debug purposes and it seems that the change of selectOneMenu fires an event because I can see on the log "init executed" each time that I modify the menu selection ( the ManagedBean is recreated to manage the event) but I don't see on the log "listener executed" so the listener method is not executed. No exception are thrown. Any idea to solve?

EDIT1: I tried your suggestions but it still doesn't work. I used @ManagedBean @RequestScoped as managed bean class annotation, and from the log I can see that the managed bean is initiated each time that the selectonemenu changes but the listener method is not executed. Could it be a compatibility problem between JBoss 6.1.1 (Jsf 2.0) and Primefaces 4.0? If yes which version of primefaces is suggested for JBoss 6.1.1? Is there any particular configuration needed to use primefaces? For completeness I write here the deployment descriptors

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0"
         metadata-complete="false"> 
    <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>programmazioni.xhtml</welcome-file>
    </welcome-file-list>
</web-app>

jboss-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <context-root>/PresentationModule</context-root>
</jboss-web>

And those are the dependencies that I imported in the pom.xml

<dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.3-1101-jdbc4</version>
        </dependency>
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>4.0</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.7</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.7</version>
            <scope>provided</scope>
        </dependency>

Solution 1 :

Replace

<p:ajax listener="#{searchSchedulingBean.systemChangeListener}" 

by

<p:ajax listener="#{searchSchedulingBean.systemChangeListener()}" 

Solution 2 :

Replace

systemChangeListener()

by

systemChangeListener(AjaxBehaviorEvent evt)

Try this one. This is working for me

<p:ajax listener="#{searchSchedulingBean.systemChangeListener}" update="autostrada"/>

我刚解决,问题是由selectOneMenu的属性值引起的,该属性值必须为String类型,但是在我的ManagedBean中,我将其设置为SelectItem类型。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM