0
我想知道这是否可能。我有一个登录表单,可以接收用户的ID和密码。如果它在后端检出,则会显示另一个表单。到目前为止,我实际上是将登录详细信息发送到另一个xhtml页面进行处理。但是,如果用户错误,页面仍会显示。JSF用AJAX显示表格
这是我的代码
的index.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://xmlns.jcp.org/jsf/html">
<h:head>
<title>Index</title>
</h:head>
<h:body>
<h:form>
<p>Login</p>
<h:inputText value="#{jsfbean.username}"/>
<h:inputText value="#{jsfbean.password}"/>
<h:commandButton action="#{jsfbean.message}" value="Results Page"/>
</h:form>
</h:body>
</html>
导航规则
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<navigation-rule>
<from-view-id>>index.xhtml</from-view-id>
<navigation-case>
<from-action>#{jsfbean.getMessage}</from-action>
<from-outcome>Success</from-outcome>
<to-view-id>result.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{jsfbean.getMessage}</from-action>
<from-outcome>Fail</from-outcome>
<to-view-id>index.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
JSF豆
public String getMessage() {
if(getUser(this.username,this.password)==true){
this.userID = aUser.getUserid();
this.secqn = aUser.getSecqn();
this.secans = aUser.getSecans();
return "Success";
}else{
return "Fail";
}
}
谢谢!但是,这是JSF 1的导航规则,还是我可以使用它2? – JianYA
您也可以将它用于JSF 2。 – Unknown
对不起,我正在执行此操作,并收到错误javax.el.MethodNotFoundException:/index.xhtml @ 13,80 action =“#{jsfbean.message}”:Method not found:stateless.jsfbean @ 573e86b7.message()。我编辑了我的问题。 – JianYA