在 JSF 复合组件中使用 IFrame 会生成错误

发布于 2024-11-14 11:52:58 字数 5983 浏览 3 评论 0原文

我正在尝试实现一个文件上传器,直到 PF 3.X FileUpload 变得稳定。我利用复合组件内的 IFrame 来执行文件上传。本质上是这样...

<p:layout position="center">
   <p:outputPanel layout="block">
        <iframe src="excel_uploader.xhtml" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" width="100%" height="300">
            <p style="font-size:12px">Your browser does not support iframes.</p>
        </iframe>
   </p:outputPanel>
</p:layout>

请注意,包含的文件 excel_uploader.xhtml 是...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.prime.com.tr/ui"
  xmlns:nova="http://novartis.net/jsf/html">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />

    <link href="./resources/app/css/master.css" rel="stylesheet" type="text/css" />
</h:head>
<h:body>
    <h:form enctype="multipart/form-data">
        <div style="width:750px">
              <p:messages />
              <div style="font-size:12px;padding-top:15px">
                  <nova:inputFile id="file" value="#{excelUploader.file}" validator="excelFileValidator" />
                  <p:commandButton ajax="false" actionListener="#{excelUploader.onUploadExcelFile}" value="Attach Smart Sheet" styleClass="input_datagrid_button" style="color:#ffffff;margin-left:0" />
              </div>
              <div style="font-size:12px;padding-top:10px">
                  Smart Sheet:&nbsp;<h:outputText styleClass="app_input_lbl_bold" value="#{excelUploader.fileName}" />
              </div>
              <h:inputHidden id="upload_file_name" value="#{excelUploader.fileName}" />
        </div>
     </h:form>
</h:body>
</html>

并且请求范围的支持 bean ExcelUploader.java 是...

@ManagedBean
@RequestScoped
public class ExcelUploader {

// <editor-fold desc="Class-Level Variables">
private File _File;
private String _FileName;
// </editor-fold>

// <editor-fold desc="Properties">
public String getFileName() {
    return _FileName;
}

public void setFileName(String value) {}

public File getFile() {
    return _File;
}

public void setFile(File file) {
    this._File = file;
}
// </editor-fold>

// <editor-fold desc="Methods">
public void onUploadExcelFile() {
    if (this._File != null && this._File.length() > 0)
        this._FileName = this._File.getName();
}
// </editor-fold>

}

当我导航到复合组件(这是一系列向导中的一个)时-like 组件,我收到以下错误:

WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at com.sun.faces.lifecycle.RestoreViewPhase.notifyAfter(RestoreViewPhase.java:288)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at Novartis.OTM.Http.MultipartFilter.doFilter(MultipartFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)

有人可以详细说明为什么 Faces Servlet 在 RestoreViewPhase 事件中抛出 nullException 吗?我正在使用 Primefaces + Mojarra 2.0.3。这是 Mojarra 的错误吗?谢谢你!

I am trying to implement a File Uploader until the PF 3.X FileUpload becomes stable. I am leveraging an IFrame inside a composite component to perform the file upload. Essentially this...

<p:layout position="center">
   <p:outputPanel layout="block">
        <iframe src="excel_uploader.xhtml" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" width="100%" height="300">
            <p style="font-size:12px">Your browser does not support iframes.</p>
        </iframe>
   </p:outputPanel>
</p:layout>

Note that the included file, excel_uploader.xhtml, is...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.prime.com.tr/ui"
  xmlns:nova="http://novartis.net/jsf/html">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />

    <link href="./resources/app/css/master.css" rel="stylesheet" type="text/css" />
</h:head>
<h:body>
    <h:form enctype="multipart/form-data">
        <div style="width:750px">
              <p:messages />
              <div style="font-size:12px;padding-top:15px">
                  <nova:inputFile id="file" value="#{excelUploader.file}" validator="excelFileValidator" />
                  <p:commandButton ajax="false" actionListener="#{excelUploader.onUploadExcelFile}" value="Attach Smart Sheet" styleClass="input_datagrid_button" style="color:#ffffff;margin-left:0" />
              </div>
              <div style="font-size:12px;padding-top:10px">
                  Smart Sheet: <h:outputText styleClass="app_input_lbl_bold" value="#{excelUploader.fileName}" />
              </div>
              <h:inputHidden id="upload_file_name" value="#{excelUploader.fileName}" />
        </div>
     </h:form>
</h:body>
</html>

And request-scoped backing bean, ExcelUploader.java, is...

@ManagedBean
@RequestScoped
public class ExcelUploader {

// <editor-fold desc="Class-Level Variables">
private File _File;
private String _FileName;
// </editor-fold>

// <editor-fold desc="Properties">
public String getFileName() {
    return _FileName;
}

public void setFileName(String value) {}

public File getFile() {
    return _File;
}

public void setFile(File file) {
    this._File = file;
}
// </editor-fold>

// <editor-fold desc="Methods">
public void onUploadExcelFile() {
    if (this._File != null && this._File.length() > 0)
        this._FileName = this._File.getName();
}
// </editor-fold>

}

When I navigate to the composite component, which is one in a series of wizard-like components, I get the following error:

WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at com.sun.faces.lifecycle.RestoreViewPhase.notifyAfter(RestoreViewPhase.java:288)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at Novartis.OTM.Http.MultipartFilter.doFilter(MultipartFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)

Can someone elaborate as to why the Faces Servlet is throwing the nullException at the RestoreViewPhase event? I am using Primefaces + Mojarra 2.0.3. Is this a bug in Mojarra? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-11-21 11:52:58

根据 问题 1764,此问题已在 Mojarra 2.1.1 中修复。相应升级。

As per issue 1764, this has been fixed in Mojarra 2.1.1. Upgrade accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文