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

后端 未结 3 780
夕颜
夕颜 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:19

    You can use the #{flash} object that will keep your data until the next view. This way you won't need to deal with view parameters.

    Details from myaccount.xhtml:

    
        
        
        

    Bean of both views:

    @ManagedBean
    @RequestScoped
    public class Bean {
    
        @ManagedProperty("#{flash}")
        private Flash flash;
    
        private int amount = -1;
    
        public Bean () {   }
    
        public String getAmount() {
            if(amount == -1) {
                int val = Integer.parseInt((String)flash.get("amount"));
                flash.keep("amount");
                amount = val;
            }
            return amount;
        }
    
        public Flash getFlash() {
            return flash;
        }
    
        public void setFlash(Flash flash) {
            this.flash = flash;
        }
    
        public String gotoPayMethod() {
            //do business job
            return "SelectBank?faces-redirect=true";
        }
    
    }
    

    Details from selectbank.xhtml:

    
    

提交回复
热议问题