weixin_33720078 2012-04-10 12:48 采纳率: 0%
浏览 83

a4j:commandButton不起作用

I'm new to JSF and RichFaces. I have a button that should call a method on 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:

<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. So I guess navigation rules, etc are fine. The thing that doesn't work is a4j:commandButton that I've just added.

UPD2: Here is my 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>

  • 写回答

2条回答 默认 最新

  • Memor.の 2012-04-10 14:17
    关注

    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):

    <!-- 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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题