【发布时间】:2012-01-05 06:26:28
【问题描述】:
我在使用 primefaces 上传小部件上传时遇到问题。经过一番调查,我注意到它发送了错误的帖子类型“url-data-encoded”,而不是多模式请求。即使我的表格清楚地声明了它:
p:dialog name= "upload" id="mapping" header="Upload Mapping File" widgetVar="mappingFileDialog" fixedCenter="true">
<h:form prependId="true" id="uploadMapping" enctype="multipart/form-data">
<p:fileUpload value="#{panaceaController.file}" mode="simple"/>
<p:commandButton id="uploadbuttom" value="Submit" ajax="true"
action="#{panaceaController.handleFileUpload}"/>
</h:form>
</p:dialog>
控制器中的文件字段为空。 我猜与此相关的另一件事是我在此页面中有多个表单,我猜 primefaces 提交了错误的表单。
顺便说一句,如果我为上传表单禁用 ajax,请求 enctype 是正确的,但它不再调用该操作?!
这是我的 html 表单:
<h:form prependId="false">
<p:dataTable id="instances" lazy="false" paginator="false" var="instance"
value="#{panaceaController.instances}">
<p:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{instance.name}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Directory"/>
</f:facet>
<h:outputText value="#{instance.directory}"/>
</p:column>
<p:column>
<f:facet name="header">
Options
</f:facet>
<p:commandLink async="true" update="propertiesTable" oncomplete="propertiesDialog.show();">
<h:graphicImage value="img/properties.png" />
<f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
</p:commandLink>
<p:commandLink async="true" onclick="confirmDelete.show();" >
<h:graphicImage value="img/edit-delete.png"/>
<f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
</p:commandLink>
<p:commandLink async="true" onclick="mappingFileDialog.show();" >
<h:graphicImage value="img/mapping.png"/>
<f:setPropertyActionListener value="#{instance}" target="#{panaceaController.instance}"/>
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
<p:dialog id="properties" header="Properties" widgetVar="propertiesDialog" fixedCenter="true">
<h:panelGroup id="propertiesTable" >
<p>
Properties for #{panaceaController.instance.directory} :
</p>
<h:form>
<p:dataTable id="propertyTable" var="propertyInstance" value="#{panaceaController.instance.properties}" paginator="false">
<p:column>
<h:outputText value="#{propertyInstance.name}"/>
</p:column>
<p:column>
<h:inputText value = "#{propertyInstance.value}" required="true"/>
</p:column>
</p:dataTable>
<h:commandButton action="#{panaceaController.saveProperties}" value="Save"/>
</h:form>
</h:panelGroup>
</p:dialog>
<h:form>
<p:confirmDialog widgetVar="confirmDelete" message="Are you sure you want to delete this Panacea instance?"
severity="warn">
<p:commandButton value="Yes" update="instances" oncomplete="confirmDelete.hide()"
actionListener="#{panaceaController.delete}" />
<p:commandButton value="Not" onclick="confirmDelete.hide()" type="button" />
</p:confirmDialog>
</h:form>
<p:dialog name= "upload" id="mapping" header="Upload Mapping File" widgetVar="mappingFileDialog" fixedCenter="true">
<h:form prependId="true" id="uploadMapping" enctype="multipart/form-data">
<p:fileUpload value="#{panaceaController.file}" mode="simple"/>
<p:commandButton id="uploadbuttom" value="Submit" ajax="false" async="false"
action="#{panaceaController.handleFileUpload}"/>
</h:form>
</p:dialog>
【问题讨论】:
-
这里常见的 primefaces 问题: - 您是否在 web.xml 中设置了过滤器?什么版本? Primefaces 正在大力开发中,但我还没有看到表单渲染不正确。如果您真的需要弄脏,请扩展过滤器,在其中放置一个断点并检查实际发生的情况。我的猜测是您在提交时会看到另一个表单。
-
是的,是的,java代码,xhtml代码,web.xml代码,版本……
-
primefaces 版本是 3.0M1。我没有在 web.xml 中设置任何过滤器,我也没有在 primefaces 示例中看到任何过滤器。我将发布我的 xhtml 作为答案。
-
这里有一些进展:如果我禁用 ajax,它实际上会正确提交表单并发送附件,但它现在不会调用我的操作。我尝试了 action 和 actionListener,它们都不起作用。
标签: file-upload jsf-2 primefaces