JSF +丰富:文件上传 +参数

发布于 2024-11-26 18:17:58 字数 1533 浏览 2 评论 0原文

我正在使用 并且我需要向我的控制器发送一些额外的参数。我尝试为此使用

视图如下:

<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} 具有正确的值,我使用 对其进行了验证。

我无法使用 ,因为没有可以挂接的按钮。

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

I am using <rich:fileupload> and I need to send some extra parameters to my Controller. I tried to use <f:param> for this.

Here is the view:

<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>

Here is the FileUploadController backing bean:

    private String imageFormat;

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

    public String getImageFormat() {
        return imageFormat;
    }

However, the setter is never called, so the variable is always null. The #{imageFormat} has the correct value, I verified it with an <h:outputText>.

I can't use <a4j:param>, because there is no button to hook on.

We are using JSF 1.2, not JSF 2.0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当爱已成负担 2024-12-03 18:17:58

要在上传的特定阶段执行某些操作,您可以附加到 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>

To perform some operations on specific phases of upload, you can attach to an event of rich:fileUpload. Along with standard events, rich:fileUpload provides a number of specific events:

  • The "onadd" event handler called on an add file operation
  • The "onupload" which gives you a possibility to cancel the upload at
    client side
  • The "onuploadcomplete" which is called after all files from the list
    are uploaded
  • The "onuploadcanceled" which is called after upload has been canceled
    via cancel control
  • The "onerror" which is called if the file upload was interrupted
    according to any errors

To invoke server side logic using AJAX when event occurs, use 'a4j:status' or 'a4j:jsFunction', for example using 'a4j:status':

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

and using 'a4j:jsFunction' (also demonstrated how to use setPropertyActionListener, it is for case if your EL resolver does not support method invocations with parameters (refer to BalusC comment))

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

<a4j:jsFunction name="setImageFormat">
    <f:setPropertyActionListener value="#{imageFormat}" target="#{fileUploadController.imageFormat}"/>
</a4j:jsFunction>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文