在支持Bean中读取隐藏值时为空值(Null value when Reading Hidden Value in Backing Bean)

编程入门 行业动态 更新时间:2024-10-11 03:25:15
在支持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-集成引导

他们说我可以使用以下方法从隐藏的后台bean中检索值。

.xhtml:

<h:commandButton id="previewTemplateButton" onclick="document.getElementById('frmCreateTemplate:footerValue').value = CKEDITOR.instances.footer.getData(); action="#{templateBean.export2PDF}" > </h:commandButton>

但是当我获得支持bean的值时,我只是得到一个NULL值。

后盾豆:

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

但是这也不起作用。 我能做什么?

this is my use case:

I have a CKEditor and hidden value in my .xhtml page like this:

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

Now, I need to be able to retrieve all text the user has entered in CKEditor, I've found this way in http://kb4dev.com/tutorial/jsf-and-ckeditor/jsf-2.x--ckeditor-integration-guide

They say I can retrieve value from hidden in backing bean using the following.

.xhtml:

<h:commandButton id="previewTemplateButton" onclick="document.getElementById('frmCreateTemplate:footerValue').value = CKEDITOR.instances.footer.getData(); action="#{templateBean.export2PDF}" > </h:commandButton>

But when I get the value in backing bean, I just get a NULL, value.

Backing bean:

System.out.println("Values: footer=" + footerContent + ", body= " + bodyContent + ", header=" + headerContent);

What could be wrong?

I have tested several approaches like accessing hidden component right in the backing bean like this:

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

But this isn't working either. What can I do?

最满意答案

那么,我发现了这个问题。 这里真正的问题是,我只是使用inputhidden值调用组件,但它位于一个Primefaces Accordion中,该组件位于表单内部,所以我缺少了:form:accordionid input.hidden id之前

Well, I have found the problem. The real problem here is that I was calling the component just with the inputhidden value, but it is inside a Primefaces Accordion which in turn is inside the form, so I was missing :form:accordionid before inputhidden id

更多推荐

value,bean,id,电脑培训,计算机培训,IT培训"/> <meta name="description&quo

本文发布于:2023-07-27 07:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287126.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空   Null   Bean   Backing   Hidden

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!