< f:facet>不适用于< h:form> [英] <f:facet> not working with <h:form>
问题描述
我有一个模板,其中定义了<h:form>
. <h:form>
在整个应用程序中用于实体的CRUD页面.
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.
因此,在一个地方,我需要另一个enctype
来填写表格,以便我可以上传文件.我以为可以用模板中的一个方面解决此问题:
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>
在具体页面上,我想通过以下方式设置自定义enctype
:
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>
但是在源代码中,我总是以默认的application/x-www-form-urlencoded
作为enctype
的<h:form>
But in the source code I always end up with the default application/x-www-form-urlencoded
as enctype
for the <h:form>
为什么会这样?在源代码中的其他位置,这表现正常.
Why is this happening? At other locations in the source code this is behaving properly.
推荐答案
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.
模板将如下所示:
<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>
,并且特定页面必须定义<ui:param name="myenctype" value="multipart/form-data"/>
:
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.
这篇关于< f:facet>不适用于< h:form>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!