1

我正在使用<rich:fileupload>,我需要向我的控制器发送一些额外的参数。我试着用<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。

4

1 回答 1

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>
于 2011-07-26T14:22:02.900 回答