JSF + rich:fileupload + param

时间:2011-07-26 12:14:21

标签: jsf null richfaces param

我正在使用<rich:fileupload>,我需要向Controller发送一些额外的参数。我尝试使用<f:param>

以下是观点:

<rich:fileUpload 
    fileUploadListener="#{fileUploadController.listener}"
    maxFilesQuantity="#{fileUploadController.uploadsAvailable}"
    addControlLabel="Hinzufügen"
    uploadControlLabel="Hochladen"
    cancelEntryControlLabel="Abbrechen"
    doneLabel="Fertig"
    clearAllControlLabel="Alle entfernen"
    noDuplicate="true"
    stopControlLabel="Stop"
    clearControlLabel="Entfernen"
    id="upload"                             
    immediateUpload="#{fileUploadController.autoUpload}"  
    ajaxSingle="true"
    acceptedTypes="jpg" 
    allowFlash="#{fileUploadController.useFlash}"
    rerender="info">

    <a4j:support event="onuploadcomplete" reRender="info" status="globalStatus" />

    <f:param 
    value="#{imageFormat}"  
    name="#{fileUploadController.imageFormat}"/>

</rich:fileUpload>

这是FileUploadController支持bean:

    private String imageFormat;

    public void setImageFormat(String imageFormat) {
        this.imageFormat = imageFormat;
    }

    public String getImageFormat() {
        return imageFormat;
    }

但是,永远不会调用setter,因此变量始终为null#{imageFormat}具有正确的值,我使用<h:outputText>进行了验证。

我无法使用<a4j:param>,因为没有可以挂钩的按钮。

我们使用的是JSF 1.2,而不是JSF 2.0。

1 个答案:

答案 0 :(得分:2)

要在上传的特定阶段执行某些操作,您可以附加到rich:fileUpload的事件。除标准事件外,rich:fileUpload还提供了许多特定事件:

  • 调用添加文件操作
  • 的“onadd”事件处理程序
  • “onupload”,可让您取消上传 客户端
  • 在列表中的所有文件之后调用的“onuploadcomplete” 已上传
  • 上传后调用的“onuploadcanceled”已被取消 通过取消控制
  • 如果文件上传被中断,则会调用“onerror” 根据任何错误

要在事件发生时使用AJAX调用服务器端逻辑,请使用'a4j:status'或'a4j:jsFunction',例如使用'a4j:status':

<rich:fileUpload
        yourParameters="...">
    <a4j:support event="onuploadcomplete" reRender="something" action="#{fileUploadController.setImageFormat(imageFormat)}"/>
</rich:fileUpload>

并使用'a4j:jsFunction'(也演示了如何使用setPropertyActionListener,如果您的EL解析器不支持带参数的方法调用(参见BalusC注释))

<rich:fileUpload onupload="setImageFormat();"
        yourParameters="..."></rich:fileUpload>

<a4j:jsFunction name="setImageFormat">
    <f:setPropertyActionListener value="#{imageFormat}" target="#{fileUploadController.imageFormat}"/>
</a4j:jsFunction>
相关问题