如何在不使用JSF中的隐藏标记的情况下将javascript中的值传递给托管bean属性? [英] How to pass a value inside javascript to managed bean property without using hidden tags in JSF?

查看:62
本文介绍了如何在不使用JSF中的隐藏标记的情况下将javascript中的值传递给托管bean属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想知道如果可以在facelets中的javascript方法中获取托管bean属性值,或者将javascript值传递给托管bean属性但不使用隐藏标记?

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 using hidden tags?

当我们搜索它们时,我们看到的是关于使用html隐藏标签或隐藏按钮的点击事件的示例或解决方案。但是当我们需要在managedbean和javascript之间进行大量数据交换时,这种方法对我们没用,因为它需要大量的隐藏标签。

When we search about them what we see are all about the examples or solutions that use html hidden tags or hidden button's click events. But this method is not useful for us when we need much data exchange between managedbean and javascript as it needs lots of hidden tags.

推荐答案

您可以像在地图中一样创建具有名称值对的json对象,并将它们作为请求参数发送。你可以有一个 p:remoteCommand ,可以从你的javascript函数调用,如下所示

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
                 }  
               ]);   
} 

以上 passToJSFManagedBean 应该是远程命令函数的名称,如下所示

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" />   

您可以访问托管bean操作中传递的参数

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
   }  

希望这有助于

这篇关于如何在不使用JSF中的隐藏标记的情况下将javascript中的值传递给托管bean属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆