3

I have tested Balusc's inputDate component: Composite component with multiple input fields inside a PrimeFaces dialog. The encodeAll method is not called at all and the select boxes are not initialized. The composite component works fine when placed in a form as shown in the article.

Why encodeAll doesn't work inside a dialog and how can be fixed?

EDIT 1

I use Mojarra 2.1.13 and PrimeFaces 3.4.2.

EDIT 2 Here is a sample from my real project. I used your component to learn about composite components. I have a view accounts, with a datatable and a toolbar. Pressing Add should open a dialog with a custom wizard. The dialog has its own form, but the wizard is not displayed.

accounts.xhtml

<h:form id="form">
    <ui:include src="/WEB-INF/flows/accounts/accountsTable.xhtml" />    
</h:form>
<ui:include src="/WEB-INF/flows/accounts/mainDialog4.xhtml" />  

accountsTable.xhtml

<p:dataTable id="accounts" ... />  

<p:toolbar>
    <p:toolbarGroup align="left">
        <p:commandButton value="Add"
            action="#{accountsBean.initializeEntity}"
            process="@this" update=":actionsDialog4"
            oncomplete="actionsDialogWidget4.show()">
            <f:setPropertyActionListener value="#{2}"
                target="#{accountsBean.operation}" />
            <f:setPropertyActionListener value="accountsBean"
                target="#{sessionScope.beanName}" />
        </p:commandButton>
    </p:toolbarGroup>
 </p:toolbar>

mainDialog4.xhtml

<p:dialog id="actionsDialog4" widgetVar="actionsDialogWidget4" dynamic="true"
    modal="true">       
    <h:form>
    <costom:actionWizard name="wizard" widgetVar="wiz" bean="#{accountsBean}" header="#{accountsBean.entityHeader}" />
    </h:form>
</p:dialog>
Seitaridis
  • 4,459
  • 9
  • 53
  • 85
  • Can't reproduce it with Mojarra 2.1.20 and PrimeFaces 3.5 on Tomcat 7.0.37. In future questions please please mention the exact library impl/versions used and include an [SSCCE](http://stackoverflow.com/tags/jsf/info). – BalusC Mar 19 '13 at 12:41
  • Added the library information. – Seitaridis Mar 19 '13 at 12:49
  • Now yet the SSCCE. I at least can't reproduce it with this minimal snippet in ``: `` – BalusC Mar 19 '13 at 12:50
  • I have tested differently: `` – Seitaridis Mar 19 '13 at 12:55
  • This is invalid dialog syntax. A dialog should not be placed in any form, but have its own form. – BalusC Mar 19 '13 at 12:59
  • You are right. That way it works. Please formulate an answer so I can mark it as the solution. – Seitaridis Mar 22 '13 at 18:19
  • I couldn't answer because I couldn't explain the cause from top of head and didn't have the mood/time to run the debugger to figure it. It's not my style to post an answer without any technical explanation. A [second question](http://stackoverflow.com/questions/15613725/encodeall-not-called-on-a-composite-component-when-rendered-attribute-is-wrapp) on the same problem triggered me to run the debugger and look in PF source code. I found and understood the cause and therefore also the right solution, which is now answered below. – BalusC Mar 25 '13 at 12:53

1 Answers1

3

This is caused by the PrimeFaces CoreRenderer not calling UIComponent#encodeAll() in renderChildren() method, but encodeBegin(), encodeChildren() and encodeEnd() individually. So it will always fail when it's declared as direct child of a PrimeFaces component, but it will work when it's declared as direct child of a standard JSF component.

If you perform the job in encodeBegin() instead of encodeAll(), then it should work. I have updated the composite component article accordingly.

On an unrelated note, the <p:dialog> should have its own form.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I know this is an old post, but I ran into the same issue but now it's on `com.sun.faces.renderkit.html_basic.HtmlBasicRenderer#encodeRecursive`, and it appears in nested composite components. Same fix though. – Evan Knowles Feb 28 '23 at 07:25