如何在PrimeFaces移动渲染模式下将命令按钮连接到动作处理程序



我有一个PrimeFaces页面,格式如下:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pm="http://primefaces.org/mobile">
<f:view renderKitId="PRIMEFACES_MOBILE"/>
<h:head>
</h:head>
<h:body>
    <pm:page>
        <pm:header title="Test"></pm:header>
        <pm:content>
            <p:panel header="Login">
                <h:form>
                    <pm:field>
                        <p:outputLabel for="basic" value="User:"/>
                        <p:inputText id="basic"/>
                    </pm:field>
                    <pm:field>
                        <p:outputLabel for="password" value="Password:"/>
                        <p:password id="password"/>
                    </pm:field>
                    <p:commandButton value="Login" type="button"
                                     actionListener="#{index.loginButtonAction}"/>
                </h:form>
            </p:panel>
        </pm:content>
    </pm:page>
</h:body>
</html>

并且我有如下定义的类IndexView

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
@ManagedBean(name = "index")
@RequestScoped
public class IndexView {
    public void loginButtonAction(ActionEvent actionEvent)
    {
        System.out.println("loginButtonAction");
        addMessage("loginButtonAction");
    }
    public void registerButtonAction(ActionEvent actionEvent)
    {
        System.out.println("registerButtonAction");
        addMessage("registerButtonAction");
    }
    public void addMessage(String summary) {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary,  null);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
}

当我按下"登录"按钮时,什么也不会发生。我甚至没有在日志中看到消息。

按下按钮后,我需要更改什么才能调用loginButtonAction操作?

我的pom.xml文件外观中的依赖项如下:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.1</version>
        <scope>test</scope>
    </dependency>
    <!-- PrimeFaces (start) -->
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>5.1</version>
    </dependency>
    <!-- PrimeFaces (end) -->
    <!-- JSF 2 (start) -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.11</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.11</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
    </dependency>
    <!-- JSF 2 (end) -->
</dependencies>

尝试删除

type="button"

从您的命令按钮。只要它的类型是按钮,它就只能点击,不会将表单数据发送到服务器。

最新更新