How to pass a value inside javascript to managed bean property without using hidden tags in JSF?

前端 未结 1 1732
不思量自难忘°
不思量自难忘° 2021-01-15 02:38

we wonder that if it is possible to get managed bean property value inside the javascript method in facelets or pass a javascript value to managed bean property but without

相关标签:
1条回答
  • 2021-01-15 03:33

    You can create a json object with name value pair like in a map and send them as a request parameters. You can have a p:remoteCommand which could be called from your javascript function like below

    function sendParams() {
        passToJSFManagedBean ([ {
                      name : 'sno',
                      value : 1
                     },   
                     {
                       name : 'name',
                       value : srikanth
                     }  
                   ]);   
    } 
    

    The above passToJSFManagedBean should be a name of a remote command function like below

     <p:remoteCommand name="passToJSFManagedBean" id="passToJSFManagedBeancmd"
                    action="#{myBean.getParams}"
                    process="@this" />   
    

    You can access the params passed in your managed bean action

       public void getParams() {
            String sno= FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()  
               .get("sno");    
     //same way you can get name
       }  
    

    Hope this helps

    0 讨论(0)
提交回复
热议问题