当我将当前页面的html传递给Jquery到托管bean时,primefaces remoteCommand标签不起作用 [英] primefaces remoteCommand tag is not working when Passing html of my current page got through Jquery to managed bean

查看:44
本文介绍了当我将当前页面的html传递给Jquery到托管bean时,primefaces remoteCommand标签不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Jquery的.html()方法获取当前页面HTML。

I am getting my current page HTML using Jquery's .html() method like this.

<h:outputScript name="js/jquery-1.7.2.js" />
<h:outputScript>
   function getHtml(){
        $('#next').click(function(){  
           htmlString=$('#wrapper').html();
           alert(htmlString);
       command({param:htmlString});
          });
        }
</h:outputScript>

我的XHTML页面

<div id="wrapper">
 <form prependId="false">
 // My HTML form with some input fields
<h:commandButton id="next" value="Submit" action=#{bean.formvalues} onCick="getHtml();">
    <h:commandButton>
<p:remoteCommand name="command" actionListener="#{bean.getjs}" />
</form>
</div>

My Bean

    @ManagedBean
    @sessionScoped
    public class bean{

       private String formvalues; // getters and settes

      public String getformValues(){
       String htmlString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("htmlString");
    return htmlString;
    }
}

public void getjs(){
     String value = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param");
          System.out.println("**************** The Javascirpt is "+value);
    }

但是我无法获得htmlString当我使用这个primefaces remoteCommand标签时,在bean中有我的页面HTML源代码。如何将它放入bean中。

But I am not able to get the "htmlString" which has my page HTML source in the bean when I use this primefaces remoteCommand tag.How can get it into the bean.

推荐答案

您应该像这样调用remoteCommand;

You should call remoteCommand like this;

<h:outputScript>
   function getHtml(){
       $('#next').click(function(){  
           htmlString=$('#wrapper').html();
           alert(htmlString);
           command([{name:'param',value:htmlString}]); //This is important
       });
    }
</h:outputScript>   

你可以在getJs方法中获得param的值:

and you can get value of param in getJs method:

public void getjs(){
  FacesContext context = FacesContext.getCurrentInstance();
  Map<String, String> map = context.getExternalContext().getRequestParameterMap();
  String value = (String) map.get("param");
  System.out.println("**************** The Javascript is " + value);
}

这篇关于当我将当前页面的html传递给Jquery到托管bean时,primefaces remoteCommand标签不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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