【问题标题】:<f:facet> not working with <h:form><f:facet> 不适用于 <h:form>
【发布时间】:2014-07-24 15:19:26
【问题描述】:

我有一个模板,其中定义了&lt;h:form&gt;。这个&lt;h:form&gt; 在整个应用程序中用于实体的 CRUD 页面。

所以,在某个地方我需要另一个enctype 用于表单,以便我可以上传文件。我想我可以用模板中的一个方面来解决这个问题:

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

在具体页面上,我想以这种方式设置自定义 enctype

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

但在源代码中,我总是以默认的application/x-www-form-urlencodedas enctype&lt;h:form&gt; 结束

为什么会这样?在源代码的其他位置,这是正常的。

【问题讨论】:

  • 只有指定为具有构面的元素才有构面。你不能随便编造。

标签: jsf facelets jsf-2.2


【解决方案1】:

h:form 的参考页面未提及enctype 方面。我认为这不是h:form 的有效方面。不过有enctype属性。

如果您想在特定页面中定义表单的内容类型,请使用如下所示的模板参数。

模板会是这样的:

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

具体页面必须定义&lt;ui:param name="myenctype" value="multipart/form-data"/&gt;:

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

如果您想为参数提供默认值,请使用 this question 中所述的三元运算符。

【讨论】:

    猜你喜欢
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多