【发布时间】:2011-03-20 09:31:02
【问题描述】:
我的目标是使用 queryString 参数调用此页面(http://localhost:8080/page.html?scrapeU ...://cnn.com,然后尝试从 facescontext 中提取 requestparametermap 中的值但在我的 init 方法中它为 null。我的第二个选择是在我的 jQuery(document).ready 函数中设置一个 inputhidden,但下面的语法不起作用。有人知道如何让它工作吗?感谢您的帮助!
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:dc="http://dc.dreamcatcher.com/facelet-taglib">
<ui:composition template="/WEB-INF/facelet/layout/external/main.xhtml">
<ui:define name="content">
<h:form id="scrapeFrm" binding="#{bookmarklet.bookmarkletFrm}">
<h:inputHidden id="scrapeURL" value="default"/>
<p:remoteCommand name="scapeImages" process="@this,scrapeURL" actionListener="#{bookmarklet.loadImages}" update="imageGrid"/>
<script type="text/javascript">
jQuery(document).ready(function(){
alert("here");
var value=$('#scrapeURL').val();
alert(value);
scapeImages();
});
</script>
</h:form>
</ui:define>
</ui:composition>
</html>
@Named
@Scope("request")
public class Bookmarklet extends BaseAction{
private UIForm bookmarkletFrm;
public void init(){
if (!FacesUtils.isPostback()) {
ExternalContext context = FacesUtils.getExternalContext();
String scrapeURL = context.getRequestParameterMap().get("sourceURL");
bookmarkletBean.setScrapeURL(scrapeURL);
}
}
【问题讨论】:
-
在 init() 方法中调用 sourceURL,但在示例 URL 中使用 scrapeURL。这可能是错误吗?
-
谢谢,马特,我错过了。感谢帮助。您可以回复作为答案,以便我给予您适当的信任吗?
标签: jquery jsf primefaces