【问题标题】:primefaces remoteCommand tag is not working when Passing html of my current page got through Jquery to managed bean将我当前页面的 html 通过 Jquery 传递给托管 bean 时,primefaces remoteCommand 标记不起作用
【发布时间】:2012-10-06 04:45:42
【问题描述】:

我正在像这样使用 Jquery 的 .html() 方法获取当前页面的 HTML。

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

我的豆

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

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

【问题讨论】:

标签: java jquery html jsf-2


【解决方案1】:

你应该这样调用remoteCommand;

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

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

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

【讨论】:

    猜你喜欢
    • 2014-12-23
    • 2012-03-03
    • 2018-03-11
    • 2015-12-02
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    相关资源
    最近更新 更多