在使用rich:fileUpload上传文件之前,如何设置Bean属性? [英] How to set a bean property before uploading a file using rich:fileUpload?

查看:110
本文介绍了在使用rich:fileUpload上传文件之前,如何设置Bean属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个模式面板,用户可以在其中上载文件并在下拉选择中选择文档类型".

我在上载事件期间使用<f:setPropertyActionListener>来设置文档类型值,但有时会在 处理完后设置该属性.可能是因为正在生成另一个请求,而这个请求是由另一个Web容器线程处理的.

<rich:modalPanel id="attachFiles" autosized="true">
    <h:form id="formUpload" enctype="multipart/form-data">
        <h:selectOneMenu id="docType"  value="#{myMB.docType}" required="true" >
            <f:selectItems value="#{myMB.docTypesSelectItems}"  />
    </h:selectOneMenu>`
        <rich:fileUpload id="upload" fileUploadListener="#{myMB.handleUpload}">
            <a4j:support event="onupload">
                <f:setPropertyActionListener value="#{myMB.docType}" 
                    target="#{myMB.docType}" />
            </a4j:support>
        </rich:fileUpload>
</rich:modalPanel>

发生这种情况时,myMB.docType的值在执行myMB.handleUpload期间为null,这是不期望的,因为应该认为该字段是必需的.

是否有办法确保仅在设置docType属性后后执行myMB.handleUpload方法?

解决方案

<f:setPropertyActionListener value="#{myMB.docType}" target="#{myMB.docType}" />

我不明白你的意思.目标与值相同.您基本上是通过self设置目标的值.值本身不是已经简单地null了吗?

无论如何,我不执行RichFaces,所以我不做详细介绍,但是我知道它在上载组件的内部使用Flash,并且这种构造通常会触发一个单独的(独立的)请求,不会考虑所有其他HTML表单参数.此后,正常" JSF输入来自单独的HTTP请求.因此,您在这里没有引入一些讨厌的JS/ajax黑客就迷路了.至少从理论上讲.

您最好的选择是在侦听器方法中将上载的文件作为bean属性保存下来,然后以普通bean的action方法(以相同形式附加到某些UICommand组件的方法)进行进一步处理. /p>

My application has a modal panel where the user can upload files and choose a "document type" in a drop-down select.

I was using an <f:setPropertyActionListener> to set the document type value during the upload event, but sometimes the property is set after the upload has been processed. Probably it's happening because another request is being generated, and this request is handled by another web container thread.

<rich:modalPanel id="attachFiles" autosized="true">
    <h:form id="formUpload" enctype="multipart/form-data">
        <h:selectOneMenu id="docType"  value="#{myMB.docType}" required="true" >
            <f:selectItems value="#{myMB.docTypesSelectItems}"  />
    </h:selectOneMenu>`
        <rich:fileUpload id="upload" fileUploadListener="#{myMB.handleUpload}">
            <a4j:support event="onupload">
                <f:setPropertyActionListener value="#{myMB.docType}" 
                    target="#{myMB.docType}" />
            </a4j:support>
        </rich:fileUpload>
</rich:modalPanel>

When it happens, the value of myMB.docTypeis null during the execution of myMB.handleUpload, which is not expected, since the field is supposed to be required.

Is there a way to assure that the method myMB.handleUpload is executed only after the property of docType has been set?

解决方案

<f:setPropertyActionListener value="#{myMB.docType}" target="#{myMB.docType}" />

I don't get you. The target is the same as the value. You're basically setting the target's value with self. Isn't the value itself simply already null?

Anyway, I don't do RichFaces, so I can't go in detail, but I know that it's using Flash under the covers for the upload component and that such a construction usually fires a separate (and standalone) request which doesn't take all other HTML form parameters into account. The "normal" JSF inputs comes thereafter in a separate HTTP request. So you're kind of lost here without bringing in some nasty JS/ajax hacks. At least, in theory.

Your best bet is to get hold of the uploaded file as a bean propery in the listener method and then process that further in the normal bean's action method (the one attached to some UICommand component in the same form).

这篇关于在使用rich:fileUpload上传文件之前,如何设置Bean属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆