2

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>
user3419507
  • 117
  • 1
  • 4
  • 16
  • try returning a String instead of a null and use it in some navigation rule – Hichamov Mar 18 '14 at 11:52
  • in the session ejb u mean??? for example return("success") – user3419507 Mar 18 '14 at 11:57
  • Yes exactly, in your backing bean instead of returning the null try returning "fail" for example and used with some navigation ruel to see whats the problem – Hichamov Mar 18 '14 at 12:04
  • it's done but it shows an error ' Nom id introuvable dans l'objet donné : success.' that mean in english name Id not found in the given object – user3419507 Mar 18 '14 at 12:28
  • So you are getting the success outcome but its not in your navigation rules anymore, this is a good sign because it means that the success outcome is working. Be sure to have navigation rules for both outcomes -the faile and the success- – Hichamov Mar 18 '14 at 14:35
  • yeah i tried it also but the same error in the both !! – user3419507 Mar 18 '14 at 20:36

1 Answers1

1

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";
Endrik
  • 2,238
  • 3
  • 19
  • 33