0

我目前一直在努力在文件上传时更新我的​​ bean 所以就这样

memberEdit.xhtml

<rich:fileUploadfileUploadListener="#{FileUpload.listener}"
              maxFilesQuantity="1" id="upload"  immediateUpload="false"
                acceptedTypes="jpg, gif, png, bmp, jpeg"allowFlash="false">
                <a4j:supportevent="onuploadcomplete"reRender="memberPhotoField"/>
            </rich:fileUpload>

<s:decorateid="memberPhotoField"template="layout/edit.xhtml">
<ui:definename="label">Member photo</ui:define>
<h:inputTextareaid="memberPhoto"cols="80"rows="3"
required="true"value="#{memberHome.instance.memberPhoto}"/> 

我的文件上传 bean

@Name ("FileUpload")
//getters setters
    public void listener(UploadEvent event) throws Exception{
         memberHome memberinstance = new CiomemberHome(); 
        //After copying file on hard disk need to update my text field with filename
         memberinstance.setphoto(item.getFileName());
       // I do get logs correct for item.getFilename
}

我的家实体

@Name("memberHome")
//getter setters....
public void setphoto(String image)
{
        log.info("In method set photo");
        getInstance().setMemberPhoto(image);
        update(); 
}
4

3 回答 3

1

首先,您永远不想自己实例化 Seam 组件(如在 中new CiomemberHome()),因为如果您这样做,它们不再是 Seam 组件(双射将不起作用等),而不是您自己创建实例,而是要求 Seam 处理它们在 FileUpload 中使用Component.getInstance("memberHome")或注入它。

关于您的问题,我认为文件名是空的。如果这是问题所在,那么原因是richfaces 实际上并没有创建临时文件,而是将内容保存在内存中。要将上传的数据存储到文件中,您需要更改web.xml

<filter>
    <filter-name>Seam Filter</filter-name>
    <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
    <init-param>
        <param-name>createTempFiles</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>maxRequestSize</param-name>
        <param-value>10000000</param-value>
    </init-param>
</filter>

注意createTempFiles设置为true(默认为false)。在侦听器中检索数据时,而不是item.getData()使用File temp = item.getFile()返回临时文件实例的字节数组。

https://stackoverflow.com/a/7276813/1417546

于 2012-09-10T16:17:58.637 回答
0

错误/消息

13:49:42,540 INFO  [FileUploadBean] result of persist: updated
13:49:42,613 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have       been displayed.
sourceId=null[severity=(INFO 0), summary=(Successfully updated), detail=(Successfully updated)]
sourceId=null[severity=(INFO 0), summary=(Successfully updated), detail=(Successfully updated)]
sourceId=ciomember:officePhoneField:officePhone[severity=(ERROR 2), summary=(value is required), detail=(value is required)]

sourceId=ciomember:cityField:city[severity=(ERROR 2), summary=(value is required), detail=(value is required)] sourceId=ciomember:agencyNameField:agencyName[severity=(ERROR 2), summary=(value是必需的),detail=(需要值)] sourceId=ciomember:lastNameField:lastName[severity=(错误 2),summary=(需要值),detail=(需要值)] sourceId=ciomember:memberPhotoField:memberPhoto [severity=(ERROR 2), summary=(value is required), detail=(value is required)] sourceId=ciomember:zipField:zip[severity=(ERROR 2), summary=(value is required), detail=( value is required)] sourceId=ciomember:stateField:state[severity=(ERROR 2), summary=(value is required), detail=(value is required)] sourceId=ciomember:firstNameField:firstName[severity=(ERROR 2) ,摘要=(需要值),detail=(必填值)] sourceId=ciomember:titleField:title[severity=(ERROR 2), summary=(必填值), detail=(必填值)] sourceId=ciomember:agencyUrlField:agencyUrl[severity=( ERROR 2), summary=(value is required), detail=(value is required)] sourceId=ciomember:address1Field:address1[severity=(ERROR 2), summary=(value is required), detail=(value is required) ]

于 2012-09-10T20:51:49.560 回答
0

感谢您尝试解决我的问题。但我发现我需要在该模态实体上使用@Inject,以便我可以使用当前实例并对其进行操作。谢谢你。:)

于 2013-01-23T16:27:56.553 回答