简体   繁体   English

selectOneMenu上的Primefaces侦听器

[英]Primefaces listener on selectOneMenu

I've problems with the primefaces ajax call listener. 我遇到了Primefaces Ajax呼叫监听器的问题。 (primefaces 4.0 , JSF 2.0 , JBoss 6.1.1 ) (primefaces 4.0,JSF 2.0,JBoss 6.1.1)

This is the selectOneMenu that I defined: 这是我定义的selectOneMenu:

<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的主要部分

@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. 当我打开页面时,日志告诉我执行了init方法并且正确填充了selectOneMenus,因此我假定托管bean正在工作。 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. 如果更改我在要修改的selectOneMenu上方编写的selectOneMenu,则会受到影响,因为它是页面中唯一选择列表初始值的selectOneMenu,但条目并未按我的意愿进行更新,因此systemChangeListener方法不会执行,因为我在日志中看不到“监听器已执行”。

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. 我尝试将托管bean从@ViewedScoped更改为@RequestScoped以便进行调试,并且似乎selectOneMenu的更改会触发一个事件,因为每次修改菜单选择时,我都可以在日志中看到“初始化执行”(ManagedBean是重新创建以管理事件),但在日志中没有看到“已执行监听程序”,因此未执行监听器方法。 No exception are thrown. 没有异常被抛出。 Any idea to solve? 有什么想法要解决吗?

EDIT1: I tried your suggestions but it still doesn't work. EDIT1:我尝试了您的建议,但仍然不起作用。 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. 我使用@ManagedBean @RequestScoped作为托管Bean类注释,并且从日志中可以看到,每次selectonemenu更改但未执行侦听器方法时,都会启动托管Bean。 Could it be a compatibility problem between JBoss 6.1.1 (Jsf 2.0) and Primefaces 4.0? 这可能是JBoss 6.1.1(Jsf 2.0)和Primefaces 4.0之间的兼容性问题吗? If yes which version of primefaces is suggested for JBoss 6.1.1? 如果是,建议为JBoss 6.1.1建议使用哪个版本的primeface? Is there any particular configuration needed to use primefaces? 使用质数符号是否需要任何特殊的配置? For completeness I write here the deployment descriptors 为了完整起见,我在此处编写部署描述符

web.xml 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 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 这些是我在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 : 解决方案1:

Replace 更换

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

by 通过

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

Solution 2 : 解决方案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类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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