我在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
视图),因此当您的client
对象为null时,您仍然会看到相同的视图而没有更新消息。应该发生的是获得重定向来failure
查看,这样浏览器将没有机会显示错误消息。检查服务器日志中是否存在导航错误。
由于您希望浏览器停留在同一页面(视图)上并更新错误消息,因此null
添加消息后,方法应该返回,而不是返回failure
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句