0

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?

OZWolverine
  • 13
  • 1
  • 8
  • There is no hidden value with the id: footerValue. Your hidden value has the id: headerValue – tak3shi Feb 22 '17 at 10:03
  • Well, I have found the problem, what you point is right, but, that was due to a bad copy and paste from my original sources. 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. – OZWolverine Feb 22 '17 at 23:07

1 Answers1

0

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

OZWolverine
  • 13
  • 1
  • 8