Search code examples
nullhiddenbacking

Null value when Reading Hidden Value in Backing Bean


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?


Solution

  • 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