Domanda

I'm trying to redirect a jsf page when i click the login button but it doesn't work. in my case when i click the login button is check if user was found in the database,once it's found it,the system redirect to the page utitled2.jsf i'm using J2ee under jdeveloper.can someone help me please???

this is my function in the 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>

and this is my 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>
È stato utile?

Soluzione

In your backing bean method loginaction, instead of returning null (which means that you are telling the JSF to stay at the current view) you should return a string object, where the name of the page on which you want the function to redirect should be included. This format should work if you are working on a faces application (otherwise it should be similar, just check online):

return "/faces/nameOfPageToRedirect.jsf?faces-redirect=true";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top