首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JSF支持bean没有通过h:commandButton调用,页面只刷新

JSF支持bean没有通过h:commandButton调用,页面只刷新
EN

Stack Overflow用户
提问于 2014-02-02 11:44:44
回答 1查看 730关注 0票数 0

我有一个登录页面,在该页面中,按钮提交时,我期望调用backing方法。单击submit按钮时将调用@PostConstruct方法,但是没有调用backing中的方法(登录方法)。没有显示错误消息,日志中也没有错误。

这是我的login.xhtml页面:

代码语言:javascript
复制
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Login</title>
</h:head>
<h:body>

    <p />
    <h:form id="login" prependId="false">
        <h:messages globalOnly="true" />
        <h:outputLabel for="username" value="Username" />
        <h:inputText id="username" value="#{user.username}" required="true" />
        <h:message for="username" />
        <br />
        <h:outputLabel for="password" value="Password" />
        <h:inputSecret id="password" value="#{user.password}" required="true" />
        <h:message for="password" />
        <br />
        <h:commandButton value="Sign in" actionListener="#{user.login}" action="#{user.login}" />
    </h:form>
</h:body>
</html>

这是我的后盾豆:

代码语言:javascript
复制
@ViewScoped
@Named(value = "user")
public class UserController implements Serializable {

    private static final long serialVersionUID = 1L;

    private String username;
    private String password;
    private String originalURL;

    @PostConstruct
    public void init() {

        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
        originalURL = (String) externalContext.getRequestMap().get(RequestDispatcher.FORWARD_REQUEST_URI);

        if (originalURL != null) {
            String originalQuery = (String) externalContext.getRequestMap().get(RequestDispatcher.FORWARD_QUERY_STRING);

            if (originalQuery != null) {
                originalURL += "?" + originalQuery;
            }
        }
    }

    public void login() throws IOException {

        HttpServletRequest request = WebContext.getRequest();

        try {
            request.login(username, password);

            if (originalURL != null) {
                WebContext.redirect(originalURL);
            } else {
                WebContext.redirect("/index.xhtml");
            }

        } catch (ServletException e) {
            WebContext.addMessage(null, new FacesMessage("Incorrect username or 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;
}
}

我已经将日志记录放到跟踪中,在单击submit按钮后的输出如下:

代码语言:javascript
复制
2014-02-02 13:35:01,881 DEBUG [org.jboss.weld.Conversation] (default task-6) WELD-000327: Resuming conversation with id null
2014-02-02 13:35:01,882 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) servletPath /login.xhtml
2014-02-02 13:35:01,882 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) pathInfo null
2014-02-02 13:35:01,882 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) URL pattern of the FacesServlet executing the current request .xhtml
2014-02-02 13:35:01,882 FINE  [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-6) execute(com.sun.faces.context.FacesContextImpl@115359ad)
2014-02-02 13:35:01,883 FINE  [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-6) Entering RestoreViewPhase
2014-02-02 13:35:01,883 FINE  [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-6) New request: creating a view for /login.xhtml
2014-02-02 13:35:01,883 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) URL pattern of the FacesServlet executing the current request .xhtml
2014-02-02 13:35:01,883 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) URL pattern of the FacesServlet executing the current request .xhtml
2014-02-02 13:35:01,883 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.ViewRoot'
2014-02-02 13:35:01,884 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created new view for /login.xhtml
2014-02-02 13:35:01,884 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Locale for this view as determined by calculateLocale en_US
2014-02-02 13:35:01,884 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) RenderKitId for this view as determined by calculateRenderKitId HTML_BASIC
2014-02-02 13:35:01,884 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.factory] (default task-6) Resource-Url from external context: file:/opt/jboss/standalone/tmp/vfs/temp/temp95c150145d0990a0/content-200a83a1e489dda9/login.xhtml
2014-02-02 13:35:01,885 FINE  [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-6) Exiting RestoreViewPhase
2014-02-02 13:35:01,885 FINE  [javax.enterprise.resource.webcontainer.jsf.timing] (default task-6)  [TIMING] - [2ms] : Execution time for phase (including any PhaseListeners) -> RESTORE_VIEW 1
2014-02-02 13:35:01,885 FINE  [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-6) render(com.sun.faces.context.FacesContextImpl@115359ad)
2014-02-02 13:35:01,885 FINE  [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-6) Entering RenderResponsePhase
2014-02-02 13:35:01,885 FINE  [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-6) About to render view /login.xhtml
2014-02-02 13:35:01,885 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Building View: /login.xhtml
2014-02-02 13:35:01,885 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.factory] (default task-6) Resource-Url from external context: file:/opt/jboss/standalone/tmp/vfs/temp/temp95c150145d0990a0/content-200a83a1e489dda9/login.xhtml
2014-02-02 13:35:01,886 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.Output'
2014-02-02 13:35:01,886 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @5,9 <h:head> Component[2030916047_790d51c2] Created: javax.faces.component.UIOutput
2014-02-02 13:35:01,887 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.OutputBody'
2014-02-02 13:35:01,887 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @9,9 <h:body> Component[2030916047_790d51e8] Created: javax.faces.component.html.HtmlBody
2014-02-02 13:35:01,887 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlForm'
2014-02-02 13:35:01,887 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @14,22 <h:form> Component[2030916047_790d518e] Created: javax.faces.component.html.HtmlForm
2014-02-02 13:35:01,888 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlMessages'
2014-02-02 13:35:01,888 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @15,36 <h:messages> Component[2030916047_790d5194] Created: javax.faces.component.html.HtmlMessages
2014-02-02 13:35:01,888 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlOutputLabel'
2014-02-02 13:35:01,888 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @16,52 <h:outputLabel> Component[2030916047_790d51a7] Created: javax.faces.component.html.HtmlOutputLabel
2014-02-02 13:35:01,889 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlInputText'
2014-02-02 13:35:01,889 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @17,73 <h:inputText> Component[2030916047_790d51ba] Created: javax.faces.component.html.HtmlInputText
2014-02-02 13:35:01,889 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) created validator of type 'javax.faces.Bean'
2014-02-02 13:35:01,889 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlMessage'
2014-02-02 13:35:01,889 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @18,31 <h:message> Component[2030916047_790d514d] Created: javax.faces.component.html.HtmlMessage
2014-02-02 13:35:01,890 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlOutputLabel'
2014-02-02 13:35:01,890 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @20,81 <h:outputLabel> Component[2030916047_790d5140] Created: javax.faces.component.html.HtmlOutputLabel
2014-02-02 13:35:01,890 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlInputSecret'
2014-02-02 13:35:01,891 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @21,75 <h:inputSecret> Component[2030916047_790d5153] Created: javax.faces.component.html.HtmlInputSecret
2014-02-02 13:35:01,891 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) created validator of type 'javax.faces.Bean'
2014-02-02 13:35:01,891 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlMessage'
2014-02-02 13:35:01,891 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @22,31 <h:message> Component[2030916047_790d5166] Created: javax.faces.component.html.HtmlMessage
2014-02-02 13:35:01,891 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlCommandButton'
2014-02-02 13:35:01,891 FINE  [javax.enterprise.resource.webcontainer.jsf.facelets.tag.component] (default task-6) /login.xhtml @24,92 <h:commandButton> Component[2030916047_790d5179] Created: javax.faces.component.html.HtmlCommandButton
2014-02-02 13:35:01,892 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Rendering View: /login.xhtml
2014-02-02 13:35:01,894 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) URL pattern of the FacesServlet executing the current request .xhtml
2014-02-02 13:35:01,894 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) URL pattern of the FacesServlet executing the current request .xhtml
2014-02-02 13:35:01,895 FINE  [javax.enterprise.resource.webcontainer.jsf.renderkit] (default task-6) component.getValue() returned Username
2014-02-02 13:35:01,895 FINE  [javax.enterprise.resource.webcontainer.jsf.renderkit] (default task-6) Value to be rendered Username
2014-02-02 13:35:01,895 FINE  [javax.enterprise.resource.webcontainer.jsf.renderkit] (default task-6) component.getValue() returned null
2014-02-02 13:35:01,895 FINE  [javax.enterprise.resource.webcontainer.jsf.renderkit] (default task-6) Value to be rendered null
2014-02-02 13:35:01,895 FINE  [javax.enterprise.resource.webcontainer.jsf.renderkit] (default task-6) component.getValue() returned Password
2014-02-02 13:35:01,895 FINE  [javax.enterprise.resource.webcontainer.jsf.renderkit] (default task-6) Value to be rendered Password
2014-02-02 13:35:01,896 FINE  [javax.enterprise.resource.webcontainer.jsf.renderkit] (default task-6) component.getValue() returned null
2014-02-02 13:35:01,896 FINE  [javax.enterprise.resource.webcontainer.jsf.renderkit] (default task-6) Value to be rendered null
2014-02-02 13:35:01,896 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Begin writing marker for viewId /login.xhtml
2014-02-02 13:35:01,896 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) End writing marker for viewId /login.xhtml
2014-02-02 13:35:01,896 FINE  [javax.enterprise.resource.webcontainer.jsf.application] (default task-6) Created component with component type of 'javax.faces.HtmlMessages'
2014-02-02 13:35:01,897 FINE  [javax.faces.component] (default task-6) No renderer-type for component j_id1
2014-02-02 13:35:01,897 FINE  [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-6) Exiting RenderResponsePhase
2014-02-02 13:35:01,897 FINE  [javax.enterprise.resource.webcontainer.jsf.timing] (default task-6)  [TIMING] - [12ms] : Execution time for phase (including any PhaseListeners) -> RENDER_RESPONSE 6
2014-02-02 13:35:01,898 TRACE [org.jboss.security] (default task-6) PBOX000354: Setting security roles ThreadLocal: null
2014-02-02 13:35:11,597 DEBUG [org.jboss.ejb.client.txn] (Periodic Recovery) Send recover request for transaction origin node identifier 1 to EJB receiver with node name localhost

任何帮助都将不胜感激,因为我现在已经花了很多时间来修复这个问题。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-05 11:31:20

问题是,我在web.xml中的配置导致了错误,并阻止了bean方法的调用。

我从我的web.xml中删除了以下内容,并调用了:

代码语言:javascript
复制
<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>mysqldomain</realm-name>
    <form-login-config>
        <form-login-page>/login.xhtml</form-login-page>
        <form-error-page>/index.xhtml?error=true</form-error-page>
    </form-login-config>
</login-config>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21510170

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档