读取 Backing Bean 中的隐藏值时为空值
Null value when Reading Hidden Value in Backing Bean
这是我的用例:
我的 .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());
}
但这也不起作用。
我能做什么?
嗯,我找到问题了。这里真正的问题是我只是用 inputhidden 值调用组件,但它位于 Primefaces Accordion 内,而后者又位于表单内,所以我在 inputhidden id
之前缺少 :form:accordionid
这是我的用例:
我的 .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());
}
但这也不起作用。 我能做什么?
嗯,我找到问题了。这里真正的问题是我只是用 inputhidden 值调用组件,但它位于 Primefaces Accordion 内,而后者又位于表单内,所以我在 inputhidden id
之前缺少 :form:accordionid