【发布时间】:2017-02-22 09:06:43
【问题描述】:
这是我的用例:
我的 .xhtml 页面中有一个 CKEditor 和隐藏值,如下所示:
<p:panelGrid columns="1" id="pnTemplateHeader" style="width:700px">
<h:inputHidden required="false" value="#{templateBean.headerContent}" id="headerValue" binding="#{templateBean.hiddenHeader}"/>
<h:inputTextarea cols="90" rows="20" class="ckeditor" id="head" name="head" >
#{templateBean.headerContent}
</h:inputTextarea>
<script type="text/javascript" >
CKEDITOR.replace('head', {
removeButtons: 'Underline,Strike,Subscript,Superscript,Anchor,Styles,Specialchar',
});
</script>
</p:panelGrid>
现在,我需要能够检索用户在 CKEditor 中输入的所有文本,我在 http://kb4dev.com/tutorial/jsf-and-ckeditor/jsf-2.x--ckeditor-integration-guide 中找到了这种方式
他们说我可以使用以下方法从隐藏在支持 bean 中的值检索。
.xhtml:
<h:commandButton id="previewTemplateButton" onclick="document.getElementById('frmCreateTemplate:footerValue').value = CKEDITOR.instances.footer.getData(); action="#{templateBean.export2PDF}" >
</h:commandButton>
但是当我在 backing bean 中获取值时,我只得到一个 NULL 值。
支持 bean:
System.out.println("Values: footer=" + footerContent + ", body= " + bodyContent + ", header=" + headerContent);
可能出了什么问题?
我已经测试了几种方法,例如直接在支持 bean 中访问隐藏组件,如下所示:
UIViewRoot root = FacesContext.getCurrentInstance().getViewRoot();
UIComponent hiddenHeaderComp = root.findComponent("headerValue");
hiddenHeaderComp = getUIComponentOfId(root, "headerValue");
hiddenHeader = (UIInput)hiddenHeaderComp;
if(hiddenHeader != null){
System.out.println("After retrieving value: " + hiddenHeader.getValue());
}
但这也不起作用。 我能做什么?
【问题讨论】:
-
id:footerValue 没有隐藏值。您的隐藏值具有 id: headerValue
-
好吧,我找到了问题所在,你的观点是对的,但是,这是由于我的原始来源的复制和粘贴错误造成的。这里真正的问题是我只是使用 inputhidden 值调用组件,但它位于 Primefaces Accordion 内部,而后者又位于表单内部,所以我在 inputhidden id 之前缺少 :form:accordionid。