我在点击登录按钮时尝试重定向jsf页面,但它不起作用。 在我的情况下,当我点击登录按钮检查是否在数据库中找到用户,一旦找到它,系统重定向到页面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;
}
}
这是我的支持
public String loginaction() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("authentification");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()) {
return "success";
}
return null;
}
这是我的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>
这是我的login.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>
答案 0 :(得分:1)
在你的支持bean方法loginaction
中,你应该返回一个字符串对象,而不是返回null(这意味着你要告诉JSF保持当前视图),你可以在其中返回页面的名称希望功能重定向应该包括在内。如果您正在处理面部应用程序,则此格式应该有效(否则它应该类似,只需在线检查):
return "/faces/nameOfPageToRedirect.jsf?faces-redirect=true";