Forum Stats

  • 3,873,340 Users
  • 2,266,537 Discussions
  • 7,911,515 Comments

Discussions

navigating to another page in a bean

Tony007
Tony007 Member Posts: 4,285 Bronze Trophy
edited May 23, 2016 4:19AM in JDeveloper and ADF

hi am in jdeveloper 11.1.1.9  I have a situation where I have to navigate to next page based on the condition how can I do that

this is what I have done so far

hi in my AppModuleTstImpl class the have this

    protected Object callStoredFunction(int sqlReturnType, String stmt, Object[] bindVars) {
            CallableStatement cst = null;
            try {
                //Creating sql statement
                cst = this.getDBTransaction().createCallableStatement("begin ? := " + stmt + ";end;", 0);
                //Register dataType for return value
                cst.registerOutParameter(1, sqlReturnType);
                //Pass input parameters value
                if (bindVars != null) {
                    //for (int z = 0; z < bindVars.length; z++) {
                    for (int z = 0; z < bindVars.length; z++){                                               
                        cst.setObject(z + 2, bindVars[z]);
                    }
                }
                cst.executeUpdate();
                //Finally get returned value
                return cst.getObject(1);
            } catch (SQLException e) {
                throw new JboException(e.getMessage());
            } finally {
                if (cst != null) {
                    try {
                        cst.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }


public String getUsrStstus(String UsrId) {
            String UserSts = "No Status found";
            Object UsrStatus = callStoredFunction(Types.VARCHAR, "Cal.Usr_status(?)", new Object[] { UsrId });
            if (UsrStatus != null) {
                UserSts = UsrStatus.toString();
            }
            return UserSts;


       public String ExecUsrPswd(String SignId,String Spswd) {
        DBTransactionImpl dbti = (DBTransactionImpl)getDBTransaction();
        CallableStatement statement =
          dbti.createCallableStatement(("BEGIN "+"cal.Pswd(?,?);" +
                                        "END;"), 0);
        try {
            statement.setString(1,SignId);
            statement.setString(2,Spswd);
            statement.registerOutParameter(2, Types.VARCHAR);
            statement.execute();
            return statement.getString(2);
        } catch (SQLException sqlerr) {
            throw new JboException(sqlerr);
        } finally {
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (SQLException closeerr) {
                throw new JboException(closeerr);
            }
        }
    }
in my bean i have this

     public void PswdValidator(FacesContext facesContext, UIComponent uIComponent,
                                  Object object) {
          //   String msg =null;
                OperationBinding oBindings = getOperationBinding("ExecUsrPswd");calling a procedure
                OperationBinding oBindingsUsr = getOperationBinding("getUsrStstus");//calling a function
                oBindings.getParamsMap().put("signid",object); 
                oBindings.execute();
              
        Object o = oBindings.getResult(); //if the validation paase i what navigate to next inputtext and able to navigate to othe page
                                    //i what to call another screen if the function return status Open this screen is diffirent from the sccren if validation paased
        if(o != null) {
           String msg = o.toString();
                          FacesMessage fm = new FacesMessage(msg);
                          throw new ValidatorException(fm);

              }
                                  }


<af:inputText value="#{bindings.Password.inputValue}"
                                label="Password:"
                                columns="#{bindings.Password.hints.displayWidth}"
                                maximumLength="#{bindings.Password.hints.precision}"
                                shortDesc="#{bindings.Password.hints.tooltip}"
                                id="it1" styleClass="CriticalInputLabelStyle"
                                required="true"
                                autoSubmit="true" secret="true"
                                validator="#{pageFlowScope.SignOnValidation.PswdValidator}">
                    <f:validator/>
                  </af:inputText>


Cvele_new_account

Best Answer

  • Ashish Awasthi
    Ashish Awasthi Oracle ACE Member Posts: 3,388 Bronze Crown
    edited May 20, 2016 7:03AM Answer ✓

    @mm07

    In your code I see a button (Good)

    and you have created an ActionEvent too (Good)

    1. RichCommandButton button = (RichCommandButton)root.findComponent("cb3"); 
    2.         
    3.         ActionEvent actinEvent = new ActionEvent(button); 

    But i don't see any code that queue this ActionEvent ??

    actionEvent.queue();


    Ashish

«1

Answers

  • Ashish Awasthi
    Ashish Awasthi Oracle ACE Member Posts: 3,388 Bronze Crown
    edited May 19, 2016 8:36AM

    I didn't read your code , Only this line

    i what to call another screen if the function return status Open  

    Don't write this code on validator as validator get called multiple time , put a button there that checks this validation and navigate to other page

    I hope you have defined control flow to another page in taskFlow so in managed bean code you can check condition like this on your button Action

    if(status.equalIgnoreCase("Open")){

    return "controlFlowName";

    }else{

    return null;

    }

    Ashish

    Cvele_new_account
  • Tony007
    Tony007 Member Posts: 4,285 Bronze Trophy
    edited May 19, 2016 11:11AM

    logon.PNGI don't need to navigate using button when I navigate out of inputtext where must I write this in my code

    if(status.equalIgnoreCase("Open")){

    return "controlFlowName";

    }else{

    return null;

    }

  • SanjeevChauhan
    SanjeevChauhan Member Posts: 1,554 Gold Trophy
    edited May 19, 2016 12:45PM

    I think valuechange listener will be better choice.

    Can valueChangeListener be used to execute task flow logic?

    Thanks

    Sanjeev

  • Ashish Awasthi
    Ashish Awasthi Oracle ACE Member Posts: 3,388 Bronze Crown
    edited May 20, 2016 2:11AM

    Earlier I said don't use validator

    As sanjev said you can put your code in valuechange listener and to navigate drop a button and write code to naviagte in it's Action and set visible false for it

    and then on VCE queue ActionEvent programmatically like this

    //Code to call ActionEvent

    FacesContext facesContext = FacesContext.getCurrentInstance();

    UIViewRoot root = facesContext.getViewRoot();

    /**Pass cb1(buttonId) */

    RichCommandButton button = (RichCommandButton)root.findComponent("cb1");

    ActionEvent actionEvent = new ActionEvent(button);

    actionEvent.queue();


    Check - http://www.awasthiashish.com/2013/04/invoking-button-action.html


    Ashish

  • Tony007
    Tony007 Member Posts: 4,285 Bronze Trophy
    edited May 20, 2016 2:46AM

    hi this is at am trying to do

    public void pwdSrc(ValueChangeEvent valueChangeEvent) {
              //  String msg =null;
         
              UIComponent c = valueChangeEvent.getComponent();
              c.processUpdates(FacesContext.getCurrentInstance());
           
                    OperationBinding oBindings = getOperationBinding("ExecUsrPswd");// this is the procedure
                    OperationBinding oBindingsUsr = getOperationBinding("getUsrStstus");//this I sthe function
                   
                    oBindings.execute();
                    oBindingsUsr.execute();
                 
                  //how do I use both procedure and function to do the validation
                 
            Object o = oBindings.getResult();
            Object o1 = oBindingsUsr.getResult();
         
          
    //I what to call procedurefaion and I navigate to next inpputext iFfunction return OEPN THAN I CALL ANOTHE SCRREN
    
    if(o1.equals("open")){
                return "controlflowName";
            }else{
                return null;
            }
            }
                                   
         
            if(o != null) {
              String msg = o.toString();
                              FacesMessage fm = new FacesMessage(msg);
                              throw new ValidatorException(fm);
                       
    
    
                  }
                                      }
    
    
    

    procedure define

              procedure Pswd(p_unserid varchar2,p_pswd varchar2,out_msg out varchar2)

    this is how am calling the procedure

    public String ExecUsrPswd(String SignId,String Spswd) {
            DBTransactionImpl dbti = (DBTransactionImpl)getDBTransaction();
            CallableStatement statement =
              dbti.createCallableStatement(("BEGIN "+"cal.Pswd(?,?);" +
                                            "END;"), 0);
      
          
            try {
                statement.setString(1,SignId);
                statement.setString(2,Spswd);
                statement.registerOutParameter(2, Types.VARCHAR);
                statement.execute();
                return statement.getString(2);
            } catch (SQLException sqlerr) {
                throw new JboException(sqlerr);
            } finally {
                try {
                    if (statement != null) {
                        statement.close();
                    }
                } catch (SQLException closeerr) {
                    throw new JboException(closeerr);
                }
              
            }
        }
    
    
    

    this is how am calling the function

      public String getUsrStstus(String UsrId) {
                String UserSts = "No Status found";
                Object UsrStatus = callStoredFunction(Types.VARCHAR, "Calm.Usr_status(?)", new Object[] { UsrId });
                if (UsrStatus != null) {
                    UserSts = UsrStatus.toString();
                }
                return UserSts;
            }
    
    
    

    this is my jsff

    <af:inputText value="#{bindings.Password.inputValue}"
                            label="#{bindings.Password.hints.label}"
                            columns="#{bindings.Password.hints.displayWidth}"
                            maximumLength="#{bindings.Password.hints.precision}"
                            shortDesc="#{bindings.Password.hints.tooltip}" id="it3"
                            styleClass="inputTextRequired" required="true"
                            valueChangeListener="#{Pswdbean.pwdSrc}">
                <f:validator binding="#{bindings.Password.validator}"/>
              </af:inputText>
    
    
    
  • Ashish Awasthi
    Ashish Awasthi Oracle ACE Member Posts: 3,388 Bronze Crown
    edited May 20, 2016 3:05AM

    Have you read my last comment ?

    You can not return controlFlow name in ValueChange Listener , for that use Button on page and define Action and then queue that in VCL

    on that button action write this code

    public String buttonAction() {

       return "controlflowName";

      }

    and then queue this action in VCL

    1. if(o1.equals("open")){ 
    2.          

    //Code to call ActionEvent

    FacesContext facesContext = FacesContext.getCurrentInstance();

    UIViewRoot root = facesContext.getViewRoot();

    /**Pass cb1(buttonId) */

    RichCommandButton button = (RichCommandButton)root.findComponent("cb1");

    ActionEvent actionEvent = new ActionEvent(button);

    actionEvent.queue();

    1.         }else{ 
    2.             return null; 
    3.         } 
    4.         } 
    5.                                 
    6.       
    7.         if(o != null) { 
    8.           String msg = o.toString(); 
    9.                           FacesMessage fm = new FacesMessage(msg); 
    10.                           throw new ValidatorException(fm); 
    11.                     
    12.  
    13.  
    14.               } 
    15.                                   } 

    Last is set visible false for button so that user can't see it


    Ashish

  • Tony007
    Tony007 Member Posts: 4,285 Bronze Trophy
    edited May 20, 2016 3:44AM

    Ya i read your post what do you mean I must que button in vcl

  • Ashish Awasthi
    Ashish Awasthi Oracle ACE Member Posts: 3,388 Bronze Crown
    edited May 20, 2016 3:47AM

    I have provided you sample code too, I think you should understand now

    Once read and try and let me know if you face any problem

    Ashish

  • SanjeevChauhan
    SanjeevChauhan Member Posts: 1,554 Gold Trophy
    edited May 20, 2016 4:09AM

    Sorry for interrupting this thread but there is a difference between Ashish's solution and my solution  Can valueChangeListener be used to execute task flow logic?.

    In Ashish's solution you are trying to mimic a button click by creating an ActionEvent queuing server side.

    In my solution you try to call task-flow navigation from valuechangelistener programatically. You are just saying that "Hey do navigation activity which is defined in task-flow".

    Creating ActionEvent will make sure that if there is any bean code written on button's action that will also fire. In my case you will only have navigation.

    But if you are only interested in navigation then you just need below two links in your valuechangelistener.

    FacesContext context = FacesContext.getCurrentInstance();

    context.getApplication().getNavigationHandler().handleNavigation(context,"", "Go");  //Replace Go with your navigation name in task-flow


    Thanks

    Sanjeev.

  • Tony007
    Tony007 Member Posts: 4,285 Bronze Trophy
    edited May 20, 2016 6:56AM

    i did this

    <af:commandButton text="commandButton 1" id="cb3"
                              action="#{pageFlowScope.SignOnValidation.buttonAction}"
                              visible="false"/>
    

          

      public void PswdValidator(ValueChangeEvent valueChangeEvent) {
             
           
            FacesContext facesContext = FacesContext.getCurrentInstance();
            UIViewRoot root = facesContext.getViewRoot();
           
           
            RichCommandButton button = (RichCommandButton)root.findComponent("cb3");
           
            ActionEvent actinEvent = new ActionEvent(button);
           
              UIComponent c = valueChangeEvent.getComponent();
              c.processUpdates(FacesContext.getCurrentInstance());
             
                    OperationBinding oBindings = getOperationBinding("ExecUsrPswd"); // I what to navigate to next inpuuteext if the validation pass
                    OperationBinding oBindingsUsr = getOperationBinding("getUsrStstus");else  if the above fail or pass and if the function return 'OPEN' THEN CALL/navigate to another page
                     
                    oBindings.execute();
                    oBindingsUsr.execute();
                   
                 
                   
            Object o = oBindings.getResult();
            Object o1 = oBindingsUsr.getResult();
           
          /* if (o1.equals("open")){
                return "controlflowName";
            }else{
                return null;
            }
            }*/
                                     
           
            if(o != null) {
              String msg = o.toString();
                              FacesMessage fm = new FacesMessage(msg);
                              throw new ValidatorException(fm);
                         
       
       
                  }
                                      }
    
This discussion has been closed.