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

妖精的绣舞 提交于 2019-12-01 10:56:47

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!