eclipse - PrimeFaces 登录尝试(示例)失败

标签 eclipse jsf jakarta-ee tomcat primefaces

我正在测试位于 http://www.primefaces.org/showcase/ui/dialogLogin.jsf 的 PrimeFaces 示例.我在 Eclipse Dyamic Web 项目中正确地导入了 PrimeFaces 和 JSF 2.1,但是当我尝试登录时填写表单后出现以下错误:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax.el.MethodNotFoundException: Method not found: classi.LoginBean@ee03ec.login()
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:229)
root cause

org.apache.myfaces.view.facelets.el.ContextAwareMethodNotFoundException: javax.el.MethodNotFoundException: Method not found: classi.LoginBean@ee03ec.login()
    org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:104)
    javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:88)
    javax.faces.event.ActionEvent.processListener(ActionEvent.java:51)
    javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:418)
    javax.faces.component.UICommand.broadcast(UICommand.java:103)
    javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1028)
    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
    javax.faces.component.UIViewRoot._process(UIViewRoot.java:1375)
    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
    org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
    org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
    org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
root cause

javax.el.MethodNotFoundException: Method not found: classi.LoginBean@ee03ec.login()
    org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:225)
    org.apache.el.parser.AstValue.invoke(AstValue.java:253)
    org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
    org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
    javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:88)
    javax.faces.event.ActionEvent.processListener(ActionEvent.java:51)
    javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:418)
    javax.faces.component.UICommand.broadcast(UICommand.java:103)
    javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1028)
    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
    javax.faces.component.UIViewRoot._process(UIViewRoot.java:1375)
    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
    org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
    org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
    org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.21 logs.

Apache Tomcat/7.0.21

LoginBean.java 是:

package classi;
import java.awt.event.ActionEvent;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;
@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean
{
    private String username;  

    private String password;  

    public String getUsername() {  
        return username;  
    }  

    public void setUsername(String username) {  
        this.username = username;  
    }  

    public String getPassword() {  
        return password;  
    }  

    public void setPassword(String password) {  
        this.password = password;  
    }  

    public void login(ActionEvent actionEvent) {  
        RequestContext context = RequestContext.getCurrentInstance();  
        FacesMessage msg = null;  
        boolean loggedIn = false;  

        if(username != null  &&&& username.equals("admin") && password != null  && password.equals("admin")) {  
            loggedIn = true;  
            msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", username);  
        } else {  
            loggedIn = false;  
            msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Invalid credentials");  
        }  

        FacesContext.getCurrentInstance().addMessage(null, msg);  
        context.addCallbackParam("loggedIn", loggedIn);  
    }  
}

login.xhtml 是:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h:outputLink id="loginLink" value="javascript:void(0)" onclick="dlg.show()" title="login">     
    <p:graphicImage value="/images/login.png" />  
</h:outputLink>  

<p:growl id="growl" showDetail="true" life="3000" />  

<p:dialog id="dialog" header="Login" widgetVar="dlg">  
    <h:form>  

        <h:panelGrid columns="2" cellpadding="5">  
            <h:outputLabel for="username" value="Username:" />  
            <p:inputText value="#{loginBean.username}"   
                    id="username" required="true" label="username" />  

            <h:outputLabel for="password" value="Password:" />  
            <h:inputSecret value="#{loginBean.password}"   
                    id="password" required="true" label="password" />  

            <f:facet name="footer">  
                <p:commandButton id="loginButton" value="Login" update=":growl"   
                    actionListener="#{loginBean.login}"   
                    oncomplete="handleLoginRequest(xhr, status, args)"/>  
            </f:facet>

        </h:panelGrid>  

    </h:form>  
</p:dialog>  

<script type="text/javascript">  
    function handleLoginRequest(xhr, status, args) {  
        if(args.validationFailed || !args.loggedIn) {  
            jQuery('#dialog').effect("shake", { times:3 }, 100);  
        } else {  
            dlg.hide();  
            jQuery('#loginLink').fadeOut();  
        }  
    }  
</script>  
</body>
</html>

最佳答案

你有一个错误的导入,替换:

import java.awt.event.ActionEvent;

import javax.faces.event.ActionEvent;

此外,&&&& 是否有效?!如果它不给你错误,也许你有一个特殊的编译器:)

if(username != null  &&&& username.equals("admin") && password != null  && password.equals("admin"))

关于eclipse - PrimeFaces 登录尝试(示例)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13641428/

相关文章:

java - 指定类文件目标 eclipse ide

java - 使用 SimpleTable 数据填充 JCombobox

java - JSF、validateRegex 和 &(符号)

java - JPA 实体监听器中的排除字段

android - Android 项目的 Gen 文件夹为空

java - Eclipse Thym 需要 'osgi.bundle; org.eclipse.jgit [3.0.0,5.0.0)' 但找不到

jsf - f :param tag attribute 'disable' is not work

jsf - p :panel and p:fieldset issue with collapsed state when using ajax/update

java - 基于 SOAP 的 Web 服务中的身份验证和角色 (Java)

java - 什么是 Java Web 应用程序部署格式?