我有一个添加primefaces文件上传。
<h:form id="form" enctype="multipart/form-data">
<h:selectOneMenu id="Collection" value="#{imputData.collList.currentColl}">
<f:selectItems value="#{imputData.collList.collList}" />
</h:selectOneMenu>
<p:fileUpload id="fileUpload" label="Durchsuchen" uploadLabel="Upload" cancelLabel="zurück" fileUploadListener="#{imputData.handleFileUpload}" mode="advanced" dragDropSupport="true" update="Collection,messages" sizeLimit="100000" allowTypes="/(\.|\/)(txt|cvs)$/" />
<p:growl id="messages" showDetail="true"/>
<h:commandButton id="read" action="#{imputData.imput}" value="#{msgs.read}"/>
</h:form>
看起来像这样
我有两个问题。
我怎样才能使文件上传更小。意思是不宽过孔页?
要从 selectOneMenu 中获取名称,我必须点击阅读按钮 (Lesen)。如果我点击上传按钮,我将无法从 SelectOneMenu (null) 中获得任何信息。我必须在
<p:fileUpload..
中写 ajax="true"或者从上传按钮中的 selectOneMenu 获取信息?我在fileUpload的更新中写了集合中的Id
update="Collection,messages"
但它并没有解决我的问题。
最佳答案
您可以使用 onstart
的fileUpload,它将调用remoteCommand 来处理您的selectOneMenu 并将其保存为必须在 View 范围内的同一bean 的属性。
<p:fileUpload id="fileUpload" mode="advanced" onstart="submitCollection()" />
<p:remoteCommand name="submitCollection" process="@this Collection" />
至于fileUpload的宽度,可以使用如下css:
.ui-fileupload {
width: 400px;//change the px into what fits you
}
希望这可以帮助。
关于jsf - 通过 p :fileUpload mode=advanced 上传文件时传递另一个输入组件的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22994966/