当我点击登录按钮时,我试图重定向一个jsf页面,但它不起作用。在我的例子中,当我单击login按钮时,它检查是否在数据库中找到了user,一旦找到了,系统将重定向到页面utitled2.jsf我在jdeveloper下使用J2ee。有人能帮帮我吗?
这是我在sessionEJB
中的函数public UserEntity authentification(String login, String pwd) {
try{
Query query;
query = em.createQuery("select o from UserEntity o where " + " o.login = :LOGIN AND o.pwd = :PWD");
query.setParameter("LOGIN",login);
query.setParameter("PWD",pwd);
return
(UserEntity) query.getSingleResult();
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
this is my backingbean
public String loginaction() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("authentification");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()) {
return "success";
}
return null;
}
this is my faces-config
<?xml version="1.0" encoding="windows-1256"?>
<faces-config version="2.1" xmlns="http://java.sun.com/xml/ns/javaee">
<application>
<default-render-kit-id>oracle.adf.rich</default-render-kit-id>
</application>
<navigation-rule>
<from-view-id>/login.jsf</from-view-id>
<navigation-case>
<from-action>#{backing_login.loginaction}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/untitled2.jsf</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
</faces-config>
,这是我的登录。JSF
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html>
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<af:document title="login.jsf" id="d1" binding="#{backingBeanScope.backing_login.d1}">
<af:messages binding="#{backingBeanScope.backing_login.m1}" id="m1"/>
<af:form id="f1" binding="#{backingBeanScope.backing_login.f1}">
<af:panelFormLayout id="pfl1" binding="#{backingBeanScope.backing_login.pfl1}">
<af:inputText value="#{bindings.login.inputValue}" label="#{bindings.login.hints.label}"
required="#{bindings.login.hints.mandatory}"
columns="#{bindings.login.hints.displayWidth}"
maximumLength="#{bindings.login.hints.precision}"
shortDesc="#{bindings.login.hints.tooltip}" id="loginfield"
binding="#{backingBeanScope.backing_login.it1}">
<f:validator binding="#{bindings.login.validator}"/>
</af:inputText>
<af:inputText value="#{bindings.pwd.inputValue}" label="#{bindings.pwd.hints.label}"
required="#{bindings.pwd.hints.mandatory}" columns="#{bindings.pwd.hints.displayWidth}"
maximumLength="#{bindings.pwd.hints.precision}" shortDesc="#{bindings.pwd.hints.tooltip}"
id="it2" binding="#{backingBeanScope.backing_login.it2}">
<f:validator binding="#{bindings.pwd.validator}"/>
</af:inputText>
<af:button text="authentification"
disabled="#{!bindings.authentification.enabled}" id="b1"
binding="#{backingBeanScope.backing_login.b1}"
action="#{backingBeanScope.backing_login.loginaction}"/>
</af:panelFormLayout>
</af:form>
</af:document>
<!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_login-->
</f:view>
在您的后台bean方法loginaction
中,您应该返回一个字符串对象,而不是返回null(这意味着您告诉JSF停留在当前视图上),其中应该包含您希望函数重定向到的页面的名称。如果你正在做一个faces应用程序,这个格式应该可以工作(否则应该是类似的,只需在线检查):
return "/faces/nameOfPageToRedirect.jsf?faces-redirect=true";