ユーザーが電子メールとパスワードを挿入してログインフォームにログインするJSFアプリケーションがあります。ManagedBean には、次の 2 つのメソッドがあります。
このメソッドcheckIdentity1()
は URL を返します (同じページにとどまるために検証が正しくない場合は ""、または次のページに移動するために挿入されたデータに問題がない場合は /useraccount.xhtml)。
このメソッドcheckIdentity2()
はブール値を返します (メッセージを表示するために検証が間違っている場合は false、問題がない場合は true)。
loginManagedBean.java
public String checkIdentity1()
{
String strResponse="";
//check id
if(email.equals("jose@a.com") && password.equals("1234"))
{
strResponse="/useraccount.xhtml?faces-redirect=true";
} else {
}
//
return strResponse;
}
public boolean checkIdentity2()
{
boolean bResponse=false;
//check id
if(email.equals("jose@a.com") && password.equals("1234"))
{
//setpassIncorrecta(false);
} else {
bResponse=true;
}
//
return bResponse;
}
私がやろうとしているのは、ajax と JSF を組み合わせて、[ログイン] ボタンをクリックして検証に失敗したときに「電子メールおよび/またはパスワードが正しくありません」と表示し、検証が成功したら account.xhtml に移動することです。しかし、間違った電子メールとパスワードを挿入してもメッセージは表示されず、正しく挿入してもページは account.xhtml にリダイレクトされません。私は何を間違っていますか?
これは私のFaceletです
<h:form>
<!--Email-->
<h:inputText id="email" label="email" required="true" size="32" maxlength="32"
value="#{loginManagedBean.email}"
requiredMessage="Insert your email">
</h:inputText>
<h:message for="email" />
<!--Password-->
<h:inputSecret id="password" label="password" required="true" size="32" maxlength="40"
value="#{loginManagedBean.password}"
requiredMessage="Insert your password">
</h:inputSecret>
<h:message for="password" />
<!--Button-->
<h:commandButton value="Login" action="#{loginManagedBean.checkIdentity1()}">
<f:ajax execute="@form" render=":loginErrorMessage" />
</h:commandButton>
</h:form>
<h:panelGroup id="loginErrorMessage">
<h:outputText value="Email and/or password incorrect" rendered="#{!loginManagedBean.checkIdentity2()}" />
</h:panelGroup>