Java Primefaces-文件上载程序不调用ManagedBean

Java Primefaces-文件上载程序不调用ManagedBean,java,jsf,file-upload,primefaces,Java,Jsf,File Upload,Primefaces,我想实施这个计划 我的实施: <h:form enctype="multipart/form-data"> <p:fileUpload id="fileUpload" fileUploadListener="#{fileUploadController.handleFileUpload}"

我想实施这个计划

我的实施:

<h:form enctype="multipart/form-data">
                                    <p:fileUpload id="fileUpload"
                                        fileUploadListener="#{fileUploadController.handleFileUpload}"
                                        mode="advanced" update="messages" sizeLimit="100000"
                                        allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />

                                    <p:growl id="messages" showDetail="true" />
我的问题是,我没有从控制器获取日志消息来上载我的文件

我真的很感激你的回答

顺便说一句,我的PF版本是3.5

更新

我的模板就是这样的:

@Component
@Scope("session")
public class FileUploadController {

    private int size = 1024;

    /**
     * log4j
     */
    private static Logger log = LogManager.getLogger(FileUploadController.class);

    public void handleFileUpload(FileUploadEvent event) {  
        log.info("Method handleFileUpload invoked");
        FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
        try {
            File targetFolder = new File("/resources/uploads/images");
            InputStream inputStream = event.getFile().getInputstream();
            OutputStream out = new FileOutputStream(new File(targetFolder,
                    event.getFile().getFileName()));
            int read = 0;
            byte[] bytes = new byte[size];
            log.info("read file stream");
            while ((read = inputStream.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            inputStream.close();
            out.flush();
            out.close();
        } catch (IOException e) {
            log.error(e);
            e.printStackTrace();
        }

    }
</h:head>
<h:body>
    <div class="well" style="margin-top: 50px">
        <div class="container">

            <h:form>
                <p:growl id="growl" sticky="true" showDetail="true" />

                <p:wizard widgetVar="wiz"
                    flowListener="#{productWizardHandler.onFlowProcess}">

                    <!-- Basic Product Tab -->
                    <p:tab id="basicProduct" title="BasicProduct">

                        <p:panel header="Fill in your basic Product Information">

                            <h:messages errorClass="error" />
                            <h:panelGrid columns="2" columnClasses="label, value"
                                styleClass="grid">
                                <h:outputText value="Product Name: *" />
                                <p:inputText required="true" label="Product Name"
                                    value="#{productService.instance.productName}" />

                                <h:outputText value="Categorie: *" />
                                <p:inputText label="Categorie" value="#" />

                                <h:outputText value="Description: *" />
                                <p:inputTextarea required="true"
                                    value="#{productService.instance.description}" />

<!-- Select your product  -->
<!--                                <h:outputLabel value="Select the product you want to create:" for="dd" />
                                <p:autoComplete id="dd" dropdown="true"
                                    value="#{autoCompleteBean.txt6}"
                                    completeMethod="#{autoCompleteBean.complete}" />
 -->
                            </h:panelGrid>

                        </p:panel>
                    </p:tab>

                    <!-- Image Tab -->
                    <p:tab id="image" title="Image">
                        <p:panel header="Upload your Product Image Details">

                            <h:messages errorClass="error" />

                            <h:panelGrid columns="2" columnClasses="label, value"
                                styleClass="grid">
                                <h:form enctype="multipart/form-data">

                                    <p:fileUpload id="fileUpload"
                                        fileUploadListener="#{fileUploadController.handleFileUpload}"
                                        mode="advanced" update="messages" sizeLimit="100000"
                                        allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />

                                    <p:growl id="messages" showDetail="true" />

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

                    <!-- Special Tab -->

                    <p:tab id="speziel" title="Spezial Tab">

                        <!-- ################################################################################ -->
                        <p:panel>
                            <ui:include src="product_templates/test.xhtml" />
                            <ui:include src="product_templates/clothes.xhtml" />
                            <ui:include src="product_templates/arbnb.xhtml" />

                        </p:panel>
                    </p:tab>

                    <!-- Summary -->
                    <p:tab id="summary" title="Summary">
                        <p:panel header="Product Summary">

                            <h:panelGrid id="productSummary" columns="6">
                                <h:outputText value="Product Name: " />
                                <h:outputText styleClass="outputLabel"
                                    value="#{productWizardHandler.product.productName}" />

                                <h:outputText value="Categorie: " />
                                <h:outputText styleClass="outputLabel" value="#" />

                                <h:outputText value="Description: " />
                                <h:outputText styleClass="outputLabel"
                                    value="#{productWizardHandler.product.description}" />>  

                      INSERT outputs für speziell products
                                                </h:panelGrid>

                            <p:commandButton value="Submit" update="growl"
                                actionListener="#{productWizardHandler.save}" />

                        </p:panel>
                    </p:tab>

                </p:wizard>

            </h:form>
        </div>
    </div>
</h:body>

>  
插入输出für speziell产品

我认为您尚未为primefaces文件上载筛选器指定筛选器映射

  <filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>

PrimeFaces文件上载筛选器
Facesservlet

查看浏览器javascript控制台中的“网络”选项卡。您是否看到
500内部服务器错误
响应?@kolossus thx获取您的答案!但是,当我查看“网络”选项卡时,什么也看不到。完全没有错误…您的文件正在上载吗?@psi thx获取您的答案!不,它不在项目文件夹中,也不在
/resources/uploads
目录中。因此,您在上载文件时在“网络”选项卡中看不到任何内容?换句话说,表单永远不会提交给服务器。除了网络选项卡外,您是否在控制台选项卡中查找了任何JS错误?主模板中是否有
?你不把多个
嵌套在一起吗?我在我的项目中使用的就是这个文件管理器。然而,我是否应该将FacesServlet更改为另一个名称以使其工作?它实际上映射到这个Servlet FacesServlet javax.Faces.webapp.FacesServlet 1 FacesServlet*。jsf OP说,当查看浏览器的网络选项卡中的HTTP流量时,他什么也看不到。因此,这不可能是服务器端的问题。
  <filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
  </filter-mapping>