JBoss.orgCommunity Documentation

Upload Field

See also: Common parameters

When you create an upload form, you can store an image by two main ways:



<%
  String[] fieldMedia = ["jcrPath=/node/exo:image"] ;
  uicomponent.addUploadField("media", fieldMedia) ;
%>


<%
  String[] hiddenField1 = ["jcrPath=/node/exo:image", "nodetype=nt:resource", "visible=false"] ;
  String[] hiddenField2 = ["jcrPath=/node/exo:image/jcr:encoding", "visible=false", "UTF-8"] ;
  String[] hiddenField3 = ["jcrPath=/node/exo:image/jcr:lastModified", "visible=false"] ;
  uicomponent.addHiddenField("hiddenInput1", hiddenField1) ;
  uicomponent.addHiddenField("hiddenInput2", hiddenField2) ;
  uicomponent.addHiddenField("hiddenInput3", hiddenField3) ;
  String[] fieldMedia = ["jcrPath=/node/exo:image"] ;
  uicomponent.addUploadField("media", fieldMedia) ;
%>


<%
    def image = "image";
    // If you're trying to edit the document
    if(uicomponent.isEditing()) {
        def curNode = uicomponent.getNode();
        // If the image existed
        if (curNode.hasNode("exo:image")) {
            def imageNode = curNode.getNode("exo:image") ;
            // If the image existed and available
            if (imageNode.getProperty("jcr:data").getStream().available() > 0 && (uicomponent.findComponentById(image) == null)) {
                def imgSrc = uicomponent.getImage(curNode, "exo:image");
                def actionLink = uicomponent.event("RemoveData", "/exo:image");
                %>
                    <div>
                        <img src="$imgSrc" width="100px" height="80px"/>
                        <a href="$actionLink">
                            <img src="/eXoResources/skin/DefaultSkin/background/Blank.gif" alt="" class="ActionIcon Remove16x16Icon"/>
                        </a>
                    </div>
                <%
            } else {
                String[] fieldImage = ["jcrPath=/node/exo:image/jcr:data"] ;
                uicomponent.addUploadField(image, fieldImage) ;
            }
        } else {
                String[] fieldImage = ["jcrPath=/node/exo:image/jcr:data"] ;
                uicomponent.addUploadField(image, fieldImage) ;
        }
    }  else if(uicomponent.dataRemoved()) {
        String[] fieldImage = ["jcrPath=/node/exo:image/jcr:data"] ;
        uicomponent.addUploadField(image, fieldImage) ;
    } else {
        String[] fieldImage = ["jcrPath=/node/exo:image/jcr:data"] ;
        uicomponent.addUploadField(image, fieldImage) ;
    }
%>


Multi upload
fieldProperty = ["jcrPath=/node/exo:value", "multiValues=true"];
uicomponent.addUploadField("/node/exo_value", fieldProperty);

Note

In this case, you must be sure that the node type definition of the document you are currently editing should allow the document to have a child node named 'exo:value' whose node type is 'nt:unstructured'. All uploaded files of this upload component are stored in this 'exo:value' child node.