<f:facet> not working with <h:form>

心不动则不痛 提交于 2019-12-02 09:27:10

问题


I have a template, in which a <h:form> is defined. This <h:form> is used all over the application for the CRUD pages of entities.

So, at one place I need another enctype for the form, so that I can upload files. I thought I can solve this with a facet in the template:

<h:form id="main-form">
    <f:facet name="enctype">
        <ui:insert name="form-enctype"/>
    </f:facet>

    <ui:insert name="buttons"/><p/>
    <ui:insert name="content"/><p/>
    <ui:insert name="buttons"/>
    <ui:insert name="additionalHelper"/>

</h:form>

And at the concrete page I wanted to set the custom enctype this way:

<ui:define name="form-enctype">
    <h:outputText value="multipart/form-data"/>
</ui:define>

But in the source code I always end up with the default application/x-www-form-urlencodedas enctype for the <h:form>

Why is this happening? At other locations in the source code this is behaving properly.


回答1:


The reference pages for h:form does not mention enctype facet. I don't think it is valid facet for h:form. However, there is attribute enctype.

If you want to define content type of the form in specific pages then use template parameters like shown below.

Template would look then:

<h:form id="main-form" enctype="#{myenctype}">

    <ui:insert name="buttons"/><p/>
    <ui:insert name="content"/><p/>
    <ui:insert name="buttons"/>
    <ui:insert name="additionalHelper"/>

</h:form>

and specific page has to define <ui:param name="myenctype" value="multipart/form-data"/>:

<ui:composition template="template.xhtml">
    <ui:param name="myenctype" value="multipart/form-data"/>
    <!-- other stuff like <ui:define ...> -->
</ui:composition>

If you want to provide default value for the parameter use ternary operator like described in this question.



来源:https://stackoverflow.com/questions/24937757/ffacet-not-working-with-hform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!