File upload 在jsf中与primefaces一起使用p:fileupload

File upload 在jsf中与primefaces一起使用p:fileupload,file-upload,jsf-2,primefaces,File Upload,Jsf 2,Primefaces,我正在尝试使用jsf在我的项目中上载图像。 xhtml页面: <ui:composition template="./template/templateAdmin.xhtml"> <ui:define name="content"> <f:view> <h:form enctype="multipart/form-data"> <

我正在尝试使用jsf在我的项目中上载图像。
xhtml页面

<ui:composition template="./template/templateAdmin.xhtml">
        <ui:define name="content">
            <f:view>
                <h:form enctype="multipart/form-data">

                    <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
                        <tr>
                            <th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                            <th class="topleft"></th>
                            <td id="tbl-border-top">&nbsp;</td>
                            <th class="topright"></th>
                            <th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
                        </tr>

                        <tr>
                            <td id="tbl-border-left"></td>
                            <td>
                                <!--  start content-table-inner -->
                                <div id="content-table-inner">

                                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td colspan="4" ><h1>NEW PRODUCT</h1></td>

                                        </tr>
                                        <tr></tr>
                                        <tr valign="top" style="float: left;padding-left: 76px; width: 69%;">
                                            <td>
                                                <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                                    <tr>
                                                        <td> <h:outputText value="Product Name"/>&nbsp;&nbsp;<font color="red" style="font-weight: bold">*</font></td>
                                                        <td>  <h:inputText id="name" styleClass="inp-form" value="#{beanProducts.productName}" required="true" requiredMessage="Enter Product Name!!!">
                                                                <f:validateRegex pattern="^[a-zA-Z0-9]+$"/>
                                                            </h:inputText><h:message for="name"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td> <h:outputText value="Category Name"/></td>
                                                        <td>
                                                            <h:selectOneMenu styleClass="styledselect_form_1" value="#{beanProducts.categoryID}">
                                                                <f:selectItems value="#{beanCategory.list}" var="item" itemValue="#{item.get(0)}" itemLabel="#{item.get(1)}"/>

                                                            </h:selectOneMenu>

                                                        </td>
                                                    </tr> 
                                                    <tr>
                                                        <td> <h:outputText value="Quantity"/></td>
                                                        <td>  <h:inputText id="quantity" styleClass="inp-form" value="#{beanProducts.quantity}" required="true" requiredMessage="Enter product quantity!!!" validatorMessage="Quantity must is number">

                                                                <f:validateRegex pattern="^[0-9]+$"/>
                                                            </h:inputText><h:message for="quantity"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td> <h:outputText value="UnitCost"/></td>
                                                        <td>  <h:inputText id="unitcost" styleClass="inp-form" value="#{beanProducts.unitCost}" required="true" requiredMessage="Enter product unitcost!!!" validatorMessage="Unitcost must is number">

                                                                <f:validateRegex pattern="^[0-9]+$"/>
                                                            </h:inputText><h:message for="unitcost"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td> <h:outputText value="Summary"/></td>
                                                        <td> <h:inputText id="summary" styleClass="inp-form" value="#{beanProducts.prDescription}" required="true" requiredMessage="Enter Product description!!!">
                                                                <f:validateRegex pattern="^[a-z0-9]+"/>
                                                            </h:inputText><h:message for="summary"/></td>
                                                    </tr>

                                                    <tr>
                                                        <td> <h:outputText value="Description"/></td>
                                                        <td> <h:inputText id="description" styleClass="inp-form" value="#{beanProducts.prDescription}" required="true" requiredMessage="Enter Product description!!!">
                                                                <f:validateRegex pattern="^[a-z0-9]+"/>
                                                            </h:inputText><h:message for="description"/></td>
                                                    </tr>
                                                    <tr>
                                                        <td> <h:outputText value="Image"/></td>
                                                        <td> <h:form enctype="multipart/form-data">
                                                                <p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
                                                                              mode="advanced"
                                                                              update="messages"
                                                                              sizeLimit="5000000"
                                                                              allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>

                                                                <p:growl id="messages" showDetail="true"/>
                                                            </h:form>
                                                        </td>
                                                    </tr>

                                                    <tr>
                                                        <td> </td>
                                                        <td><h:commandButton value="Save"   styleClass="form-submit" actionListener="#{beanProducts.insertProduct}"/><h:commandButton styleClass="form-reset" value="Cancel" actionListener="#{beanProducts.reset}"/></td>

                                                    </tr>
                                                    <tr>
                                                        <td><h:messages style="color: red" /></td>
                                                        <td></td>
                                                    </tr>
                                                </table>
                                            </td>

                                        </tr>
                                        <tr>
                                            <td><img src="images/shared/blank.gif" width="695" height="1" alt="blank" /></td>
                                            <td></td>
                                        </tr>
                                    </table>
                                    <div class="clear"></div>
                                </div>
                            </td>
                            <td id="tbl-border-right"></td>
                        </tr>
                        <tr>
                            <th class="sized bottomleft"></th>
                            <td id="tbl-border-bottom">&nbsp;</td>
                            <th class="sized bottomright"></th>
                        </tr>
                    </table>

                </h:form>
            </f:view>
        </ui:define>
    </ui:composition>
如果我建立在一个简单的项目上,它会工作得很好。但是当我在
ui:define
标记中包含此代码时。它不起作用

我怎样才能修好它


谢谢。

您的项目有相同的配置吗?我正在使用PF 3.4.1和JSF 2.1,工作正常!向我们展示你的
ui:define
他应该完全避免嵌套表单。@ThaiNQ只需像Alexander所说的那样立即删除包含
,就可以了
public void handleFileUpload(FileUploadEvent event) {
        FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }