Header Ads

Create Upload Form 1

This tutorial is about 'How to create a form which is used to upload images' in Primefaces with Java.

form.xhtml
<h:form enctype="multipart/form-data">
<p:messages id="msgs"/>
 
        <h:panelGrid columns="3">      
        <h:outputLabel for="company_name" value="Company Name *" />
        <p:inputText id="company_name" value="#{uploadImage.company_name}" required="false" label="Company Name">
        <f:validateLength minimum=""/>
        </p:inputText>
        <p:message for="company_name" display="icon"/>

        <h:outputLabel for="account_id" value="Site ID *" />
        <p:inputText id="account_id" value="#{uploadImage.account_id}" required="true" label="Site ID">
        <f:validateLength minimum=""/>
        </p:inputText>
        <p:message for="account_id" display="icon"/>
     
        <h:outputLabel for="address" value="Address *" />
        <p:inputText id="address" value="#{uploadImage.address}" required="true" label="Address">
        <f:validateLength minimum=""/>
        </p:inputText>
        <p:message for="address" display="icon"/>

            <p:panelGrid columns="2">
                <h:outputLabel for="image" value="Select Image: *" />
                <p:fileUpload value="#{uploadImage.file}" mode="simple" allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf|html)$/"/>
                <f:facet name="footer">
                    <p:commandButton value="Submit" ajax="false"
                                     actionListener="#{uploadImage.upload}" update="messages"/>
                <p:commandButton value="Reload" update="panel" process="@this">  
        <p:resetInput target="panel" />
        </p:commandButton>
             
                </f:facet>

            </p:panelGrid>
</h:form>

Click this link to view next step >> UploadImage.java

No comments

Thank you very much for your ideas!