我正在使用具有 centerLayout、westLayout 的 Layout 结构。在中心 layoutUnit 中使用 primefaces 文件上传。我将过滤器添加到 web.xml 并将所需的库文件上传到 WEB/INF 库。
我实施了该链接中的步骤:如何使用 PrimeFaces p:fileUpload? 侦听器方法从未被调用或 UploadedFile 为 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());
}
}
非常感谢您的回复。