[seam-issues] [JBoss JIRA] Commented: (JBSEAM-2974) <s:fileUpload> doesnt work inside <h:dataTable>

Achim Heynen (JIRA) jira-events at lists.jboss.org
Thu Apr 22 15:11:10 EDT 2010


    [ https://jira.jboss.org/jira/browse/JBSEAM-2974?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12527114#action_12527114 ] 

Achim Heynen commented on JBSEAM-2974:
--------------------------------------

Although this is set up for version 2.0.2.CR2 this bug obviously exists in version 2.2.0. Here is a possible solution:

The reason for this bug is that the local value get not returned by getLocalValue(). That method is used in the UIData class to store the table row's state temporarily. To fix this problem I extended the UIFileUpload with a simple inner class and overrode some methods to handle the local values:

public abstract class UIFileUpload extends UIInput {

[...everything as is...] 

    /**
     * {@inheritDoc}
     * 
     * @see javax.faces.component.UIOutput#getLocalValue()
     */
    @Override
    public Object getLocalValue() {
        return new LocalUploadValue(localContentType, localFileName, localFileSize,
                localInputStream);
    }

    /**
     * {@inheritDoc}
     * 
     * @see javax.faces.component.UIInput#setValue(java.lang.Object)
     */
    @Override
    public void setValue(Object value) {
        // Check if the local values get restored
        if (value != null && value instanceof LocalUploadValue) {
            LocalUploadValue localValue = (LocalUploadValue) value;
            localFileName = localValue.getFileName();
            localFileSize = localValue.getFileSize();
            localContentType = localValue.getContentType();
            localInputStream = localValue.getInputStream();
        } else {
            super.setValue(value);
        }
    }

    /**
     * {@inheritDoc}
     * 
     * @see javax.faces.component.UIInput#isLocalValueSet()
     */
    @Override
    public boolean isLocalValueSet() {
        return localContentType != null || localFileName != null || localFileSize != null
                || localInputStream != null;
    }

    /**
     * Helper class to store the local values.
     */
    protected class LocalUploadValue {

        /** Stores the local content type. */
        private String contentType;

        /** Stores the local file name. */
        private String fileName;

        /** Stores the local file size. */
        private Integer fileSize;

        /** Stores the local stream information. */
        private InputStream inputStream;

        /**
         * Constructor for this class.
         * 
         * @param contentType
         *            The local content type to save
         * @param fileName
         *            The local file name to save
         * @param fileSize
         *            The local file size to save
         * @param inputStream
         *            The local input stream to save
         */
        public LocalUploadValue(String contentType, String fileName, Integer fileSize,
                InputStream inputStream) {
            super();
            this.contentType = contentType;
            this.fileName = fileName;
            this.fileSize = fileSize;
            this.inputStream = inputStream;
        }

        /**
         * Returns the contentType value.
         * 
         * @return the contentType value
         */
        public String getContentType() {
            return contentType;
        }

        /**
         * Returns the fileName value.
         * 
         * @return the fileName value
         */
        public String getFileName() {
            return fileName;
        }

        /**
         * Returns the fileSize value.
         * 
         * @return the fileSize value
         */
        public Integer getFileSize() {
            return fileSize;
        }

        /**
         * Returns the inputStream value.
         * 
         * @return the inputStream value
         */
        public InputStream getInputStream() {
            return inputStream;
        }
    }
}

---

As the UIFileUpload is an abstract class that gets extended by HtmlFileUpload I had to replace it by using the same package and name - which is quite dirty, of course. But I hope this solution helps to fix the bug in the near future.

> <s:fileUpload> doesnt work inside <h:dataTable>
> -----------------------------------------------
>
>                 Key: JBSEAM-2974
>                 URL: https://jira.jboss.org/jira/browse/JBSEAM-2974
>             Project: Seam
>          Issue Type: Bug
>    Affects Versions: 2.0.2.CR2
>            Reporter: Denis Forveille
>            Assignee: Shane Bryzak
>
> (see the forum entry in ref)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the seam-issues mailing list