【发布时间】: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。
【问题讨论】:
-
如果你使用primefaces,你可以试试remoteCommand..primefaces.org/showcase-labs/ui/remoteCommand.jsf
-
嘿,你能看到我更新的问题吗?它对我没有任何想法。