java - :message not displayed in jsf page

标签 java jsf


我在 jsf 中制作了一个带有登录字段的简单登录页面。如果登录不正确(数据库中未找到用户),页面上应显示一条消息,但不会显示任何内容...
ps : 如果用户什么都不输入,则显示“requiredMessage”中指定的消息。
这是我的 jsf 页面的代码:

<h:body>
        <p>Identification</p>
        <h:form prependId="false">           
            login : <h:inputText id="log" value="#{filesystemCtrl.login}" required="true" requiredMessage="Please enter your username"/>
            <h:message for="log" style="color:red"/><br/>
            <h:commandButton action="#{filesystemCtrl.identifier()}" value="Login"/>
        </h:form>
        <div id="footer" align="center">
            <ui:insert name="footer">


             <ui:include src="footer.xhtml" />
            </ui:insert >
        </div>
    </h:body>

这是 ManagedBean 的一部分:

public String identifier() {
        client = filesystemFacade.identifier(login);
        if (client == null) {
            FacesContext context = FacesContext.getCurrentInstance();
            context.addMessage("log", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "No user found !"));
            return "failure";
        } else {
            return "success";
        }
    }

最佳答案

您的操作方法返回所有路径中的导航情况。我猜您实际上没有 failure 导航(即 failure.xhtml View ),因此当您的 client 对象为 null 时,您仍然会看到相同的 View ,但没有更新消息。应该发生的情况是重定向到 failure View ,这样浏览器将没有机会显示错误消息。检查您的服务器日志是否有导航错误。

由于您希望浏览器保持在同一页面( View )并更新错误消息,因此您的方法应在添加消息后返回 null,而不是 failure .

关于java - :message not displayed in jsf page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20785552/

相关文章:

java - 助手类最佳方法android

上下文中的 Java 类路径

css - h :inputText 周围出现额外空间

java - PrimeFaces:在 Javascript 中获取当前列的排序顺序

JSF 事件 session 计数器。如何?

java - 使用 JSF 和 Tomcat 的 LDAP 身份验证

java - 找不到类型为 Org.springframework.mail.javamail.JavaMailSender 的 Bean?

java - 如何在不转换为文件的情况下将音频与视频分开?

java - 启动后 Eclipse Kepler 崩溃并显示消息 :-Java heap space

javascript - p :commandButton only works with two clicks (JSF 2. 2 错误?)