简体   繁体   English

a4j:commandButton 不起作用

[英]a4j:commandButton doesn't work

I'm new to JSF and RichFaces.我是 JSF 和 RichFaces 的新手。 I have a button that should call a method on bean.我有一个按钮,应该在 bean 上调用一个方法。 When I use当我使用

<h:commandButton action="#{loginBean.userLogin}" value="Login" />

it works fine, but when I click on它工作正常,但是当我点击

<a4j:commandButton action="#{loginBean.userLogin}" value="Login" />

nothing happens.什么都没发生。

My bean code:我的豆码:

public class LoginBean {

@Size(min = 2, max = 20, message = "Must be betwen 2 and 20 chars")
private String          login;
@Size(min = 1, message = "Please Enter your password")
private String          password;

//getters and setters

public String userLogin() {
    //user login code

}
}

My JSP Page code:我的JSP页面代码:

<body>
<f:view>
<div >
   <h:form id="loginForm">
       <h:panelGrid columns="3">
           <h:outputLabel for="login" value="Login:" />
           <h:inputText id="login" value="#{loginBean.login}" >

           </h:inputText>
           <rich:message for="login" />

           <h:outputLabel for="password" value="Password:" />
           <h:inputSecret id="password" value="#{loginBean.password}" />
           <rich:message for="password" />
       </h:panelGrid>

        <div>
            <h:commandButton action="#{loginBean.login}" value="Login" />
            <a4j:commandButton action="#{loginBean.login}" value="Login" />
        </div>
        <div>
            <a href="<%= request.getContextPath() %>/registration.jsf">Registration</a>
        </div>
    </h:form>
</div>
</f:view>
</body>

So as you can see I even added two buttons.正如你所看到的,我什至添加了两个按钮。 One works fine and second doesn't do anything.一个工作正常,第二个什么都不做。

UPD: I didn't use RichFaces at first and my application worked fine. UPD:起初我没有使用 RichFaces,我的应用程序运行良好。 So I guess navigation rules, etc are fine.所以我想导航规则等都很好。 The thing that doesn't work is a4j:commandButton that I've just added.不起作用的是我刚刚添加的 a4j:commandButton。

UPD2: Here is my web.xml: UPD2:这是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5" 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_2_5.xsd">

<display-name>webappsaichuk</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<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>*.jsf</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

Your method must have a different name from your attribute.您的方法必须与您的属性具有不同的名称。

public class LoginBean {

    @Size(min = 2, max = 20, message = "Must be betwen 2 and 20 chars")
    private String login;
    @Size(min = 1, message = "Please Enter your password")
    private String password;

    //getters and setters...

    public String userLogin() {
        //user login code
    }
}
<h:inputText id="login" value="#{loginBean.login}" styleClass="rowInput">
<h:commandButton action="#{loginBean.userLogin}" value="Login" />
<a4j:commandButton action="#{loginBean.userLogin}" value="Login" />

UPDATE更新

You should add the RichFaces filter to the web.xml (based on Getting started with RichFaces ):您应该将 RichFaces 过滤器添加到 web.xml(基于RichFaces 入门):

<!-- some context params to get better performance for RichFaces -->
<context-param>
    <param-name>org.ajax4jsf.COMPRESS_SCRIPT</param-name>
    <param-value>true</param-value>
</context-param>
<context-param>
    <param-name>org.ajax4jsf.SKIN</param-name>
    <param-value>classic</param-value>
</context-param>
<context-param>
    <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
    <param-value>true</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.LoadScriptStrategy</param-name>
    <param-value>ALL</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.LoadStyleStrategy</param-name>
    <param-value>ALL</param-value>
</context-param>
<!-- main filter for RichFaces -->
<filter>
    <display-name>Ajax4jsf Filter</display-name>
    <filter-name>ajax4jsf</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
</filter>

<filter-mapping>
    <filter-name>ajax4jsf</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

a4j:commandButton is an ajax submit. a4j:commandButton 是一个 ajax 提交。 So nothing will happen unless you re-render part of the screen that has changed based on the action.因此,除非您重新渲染根据操作更改的屏幕部分,否则什么也不会发生。

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

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