Primefaces fileUpload错误与layoutUnit

时间:2013-09-26 16:54:26

标签: jsf-2 primefaces

我正在使用具有centerLayout,westLayout的Layout结构。在center layoutUnit中使用primefaces fileupload。我将过滤器添加到web.xml并将fileupload所需的lib添加到WEB / INF lib。

我实施了该链接中的步骤:How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null 它对我的问题不起作用。

当加载layoutComplex.xhtml页面时,请执行以下错误:“ / UI布局初始化错误。中心窗格元素不存在。中心窗格是必需元素。” “错误渲染视图[/layoutComplex.xhtml]:java.lang.IllegalStateException:在提交响应后无法创建会话”

如果我写地址栏“http:.... hostName / portal / dataImportingProjectCurrent.jsf”url,则没有错误。

在layoutComplex.xhtml代码部分:

<p:layoutUnit position="center" id="centerLayout">

                <h:form id="formCenter" enctype="multipart/form-data">
                    <p:panel id="optionPanel">
                        <p:panel id="panelWelcome"
                            rendered="#{menuSelection.selectedOption == menuSelection.WELCOME}">
                            <ui:include src="/welcomePage.xhtml" />
                        </p:panel>

                        <p:panel id="panelUserAdd"
                            rendered="#{menuSelection.selectedOption == menuSelection.USER_ADD}">
                            <ui:include src="/kullanici.xhtml" />
                        </p:panel>
                        <p:panel id="panelProjectAdd"
                            rendered="#{menuSelection.selectedOption == menuSelection.PROJECT_ADD}">
                            <ui:include src="/proje.xhtml" />
                        </p:panel>

                            <p:panel id="panelAuthorizationAdd" 
                            rendered="#{menuSelection.selectedOption == menuSelection.AUTHORIZATION_ADD}">
                            <ui:include src="/yetki.xhtml" />
                        </p:panel>

                        <p:panel id="panelRoleAdd"
                            rendered="#{menuSelection.selectedOption == menuSelection.ROL_ADD}">
                            <ui:include src="/rol.xhtml" />
                        </p:panel>

                        <p:panel id="panelDataDefining"
                            rendered="#{menuSelection.selectedOption == menuSelection.DATA_DEFINING}">
                            <ui:include src="/dataDefining.xhtml" />
                        </p:panel>

                        <p:panel id="panelDataEvaluation"
                            rendered="#{menuSelection.selectedOption == menuSelection.DATA_EVALUATION}">
                            <ui:include src="/dataEvaluation.xhtml" />
                        </p:panel>
                        **<p:panel id="panelDataImporting"
                            rendered="#{menuSelection.selectedOption == menuSelection.DATA_IMPORTING}">
                            <ui:include src="/dataImporting.xhtml" />
                        </p:panel>**
                        <p:panel id="panelDataReporting"
                            rendered="#{menuSelection.selectedOption == menuSelection.DATA_REPORTING}">
                            <ui:include src="/dataReporting.xhtml" />
                        </p:panel>
                        <p:panel id="panelAdmin"
                            rendered="#{menuSelection.selectedOption == menuSelection.ADMIN}">
                            <ui:include src="/admin.xhtml" />
                        </p:panel>
                        <p:panel id="panelCreateNewReportSchema"
                            rendered="#{menuSelection.selectedOption == menuSelection.DATA_REPORTING_NEW_SCHEMA}">
                            <ui:include src="/dataReportingNewSchema.xhtml" />
                        </p:panel>
                        <p:panel id="panelCreateReport"
                            rendered="#{menuSelection.selectedOption == menuSelection.DATA_REPORT_CREATING}">
                            <ui:include src="/dataReportCreating.xhtml" />
                        </p:panel>

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

            </p:layoutUnit>

属于primefaces fileUpload的页面代码是dataImportingProjectCurrent.xhtml:

<h:body>
<h:form id="formDataImportProjectCurrent" enctype="multipart/form-data" >
    <h1>
        Project current fdasdata importinfdsa  is under construction. Coming soon...
    </h1>

    <p:fileUpload label="Seçiniz"
            fileUploadListener="#{dataImportingBean.handleFileUpload}"
            mode="advanced" auto="true" sizeLimit="1000000"
            allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />

</h:form>

我的bean是DataImportingBean.java:

@ManagedBean @SessionScoped 公共类DataImportingBean扩展GenericBean实现Serializable {

private static final long serialVersionUID = 730586496885706439L;

private UploadedFile file;

@Inject
DataImportingService DataImportingService;

@Override
public GenericService<Data, Long> getService() {
    return DataImportingService;
}


@Override
public void newObject() {
    setObject(new Data());
}


public void handleFileUpload(FileUploadEvent event) {  
    FacesMessage msg = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");  
    FacesContext.getCurrentInstance().addMessage(null, msg);  
    System.err.println("event.getFile().getFileName(): " + event.getFile().getFileName());
}

}

非常感谢您的回复。

1 个答案:

答案 0 :(得分:0)

将以下上下文参数添加到web.xml后,可以正常工作。感谢

<context-param>
<param-name>com.sun.faces.writeStateAtFormEnd</param-name>
<param-value>false</param-value>
</context-param>