<h:form enctype="multipart/form-data">
            <h:panelGrid columns="2" columnClasses="top,top">
                <rich:fileUpload fileUploadListener="#{ImageUpload.listener}" maxFilesQuantity="1" acceptedTypes="jpg, png, gif, bmp" id="uploadfile">
                    <a4j:ajax event="uploadcomplete" execute="@form" render="infoupl"/>
                </rich:fileUpload>
                <h:panelGroup id="infoupl">
                    <rich:panel bodyClass="info">
                        <f:facet name="header">
                            <h:outputText value="Uploaded Files Info" />
                        </f:facet>
                        <rich:dataGrid columns="1" value="#{ImageUpload.files}"
                                       var="file" rowKeyVar="row">
                            <rich:panel>
                                <h:panelGrid columns="2">
                                    <h:outputText value="#{file.name}"/>
                                    <a4j:mediaOutput element="img" mimeType="image/jpeg"
                                                     createContent="#{ImageUpload.paint}" value="#{row}"
                                                     style="width:100px; height:100px;" cacheable="false">
                                    </a4j:mediaOutput>
                                </h:panelGrid>
                            </rich:panel>
                        </rich:dataGrid>
                    </rich:panel>
                </h:panelGroup>
            </h:panelGrid>
        </h:form>

@ManagedBean
@SessionScoped
public class ImageUpload implements Serializable{

    private ArrayList<fileUploadBean> files = new ArrayList<fileUploadBean>();
    private int uploadsAvailable = 5;
    private boolean autoUpload = false;
    private boolean useFlash = false;

    public int getSize() {
        if (getFiles().size() > 0) {
            return getFiles().size();
        } else {
            return 0;
        }
    }

    public void paint(OutputStream stream, Object object) throws IOException {
        stream.write(getFiles().get((Integer) object).getData());
    }

    public void listener(FileUploadEvent event) throws Exception {
        System.out.println("file: "+event.getUploadedFile());
        UploadedFile item = event.getUploadedFile();
        fileUploadBean file = new fileUploadBean();
        file.setLength(item.getData().length);
        file.setName(item.getName());
        file.setData(item.getData());
        files.add(file);
        uploadsAvailable--;
    }

    public String clearUploadData() {
        files.clear();
        setUploadsAvailable(5);
        return null;
    }

    public long getTimeStamp() {
        return System.currentTimeMillis();
    }

    public ArrayList<fileUploadBean> getFiles() {
        return files;
    }

    public void setFiles(ArrayList<fileUploadBean> files) {
        this.files = files;
    }

    public int getUploadsAvailable() {
        return uploadsAvailable;
    }

    public void setUploadsAvailable(int uploadsAvailable) {
        this.uploadsAvailable = uploadsAvailable;
    }

    public boolean isAutoUpload() {
        return autoUpload;
    }

    public void setAutoUpload(boolean autoUpload) {
        this.autoUpload = autoUpload;
    }

    public boolean isUseFlash() {
        return useFlash;
    }

    public void setUseFlash(boolean useFlash) {
        this.useFlash = useFlash;
    }
    
}