jsf2.0 - How to get the values in other jsf page's bean in request scope

后端 未结 3 783
夕颜
夕颜 2021-01-16 06:12

I have two pages myaccount.xhtml and selectbank.xhtml In my account page there is one option for recharge account in which user will enter the amount when user will press su

3条回答
  •  难免孤独
    2021-01-16 06:25

    Well, if your beans are RequestScoped than you don't have same bean for both pages. These beans are recreated for every request, so you should pass parameters. Change return statement of your gotoPayMethod() to:

    return "SelectBank?faces-redirect=true&includeViewParams=true";
    

    and on selectbank.xhtml add:

    
      
    
    

    Adapt this to your property and bean name.

    If using parameters is not a solution you can add this parameter in the session, and remove it from session in second bean when you retrieve it:

    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("amount", amount);
    ((HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest()).getSession().removeAttribute("amount");
    

    Second construction for removing the attribute is necessary as Map returned from getSessionMap() is immutable.

提交回复
热议问题