JSF 2.0 AJAX 调用失败
我正在开发一个项目,将使用 JSF1.2、JSP、Struts、Tiles、Richfaces ... 的现有项目简单地使用 JSF2.0、内置的 Facelets 支持,并将 Richfaces 更新到版本 4。
到目前为止除了一个主要障碍外,一切进展顺利。我正在尝试将以前使用
标记处理的 AJAX 组件更新为
标记,而不是如何工作我希望,我收到一个错误,我只能将其解释为我忘记了配置所有内容的某些内容。
这是 com.sun.faces.context.PartialViewContextImpl.createPartialResponseWriter() 方法中引发的 NullPointerException。
当我第一次加载页面时,我可以在调试器中看到组件正确绑定到支持值;页面加载顺利。当我尝试激活该组件上的 AJAX 事件时,它就崩溃了。我收到错误,并且没有通过 AJAX 更新任何内容。我尝试转换的每个 AJAX 组件都会发生这种情况。这是一个这样的例子:
<h:selectOneMenu
value="#{userSession.selectedNetwork}"
id="network"
>
<f:selectItems value="#{userSession.networkUIOptions}" />
<f:ajax event="change" render="selectedStation edit_site_button add_site_button"/>
</h:selectOneMenu>
我不知道这是否相关,但是我在该代码中引用的 bean 现在已注释为 ala JSF2.0 并从 faces-config.xml 中删除,但是,我还没有完全摆脱faces-config.xml。仍在努力转换一切。另外,我在 Tomcat 6.0 上运行它。
任何帮助、建议将不胜感激。我真的被这个问题困扰了。
编辑 1:
根据我下载的捆绑包标题使用 mojarra 版本 2.1.1。无法获得准确的堆栈跟踪。更改了这么多内容后,日志记录似乎无法正常工作。会继续努力。还将尝试简单的页面并报告结果。
编辑2: 因此,尝试“最小”页面会产生相同的结果,相同的错误。
仍然无法让日志记录完全正常工作,所以只是做了一些贫民区日志记录。请参阅下面的类似正确堆栈跟踪的内容:
编辑3: 好的,用行号更新了 ghetto 堆栈跟踪。您猜对了第一类中的行号以抛出错误: http://pastebin.com/49yUDcPM
NPNSessionFilter.java 的 doFilter 函数: http://pastebin.com/iwG0rcQ6
我根据建议为 BalusC 创建的测试页面: http://pastebin.com/kSeUyj7g
编辑4:
http://tinypic.com/r/2dca0yo/7 http://tinypic.com/r/16jet7s/7
以下是当前打包在 WAR 的 WEB-INF/lib 文件夹中的库的图像。以前的程序员包含了很多我还没有清理掉的垃圾。同样,不确定 struts JAR 来自哪里。删除了我能找到的与 strust 或tiles 相关的所有 pre-dist JAR。
编辑5:
好的,突破!这个评论使世界变得不同“同样,不确定 struts JAR 来自哪里。删除了我能找到的与 strusts 或tiles 相关的任何 pre-dist JAR。”
清洁耳朵,重新分配,现在效果好多了。显然,这不仅仅是我忘记删除的某个库,而是我忘记删除的一个库,然后在删除后清理了 EAR。 AJAX 请求现在可以正常通过,我可以在调试器中看到请求通过时值被重新绑定!还有很多其他问题,但可以用我自己的时间来解决。 BalusC,你引导我找到了这个解决方案;如果您想提交答案,我很乐意接受!
I am working on a project to take an existing project using JSF1.2, JSP, Struts, Tiles, Richfaces ... to simply use JSF2.0, the built-in facelets support, and updating Richfaces to version 4.
So far things are going pretty well, except for one major road block. I am trying to update AJAX components that were previously being handled with the <a4j:support>
tags, to the <f:ajax>
tags and instead of working how I'd hope, I'm getting an error which I can only interpret as me having forgotten something in terms of configuring everything.
It's a NullPointerException being thrown in com.sun.faces.context.PartialViewContextImpl.createPartialResponseWriter() method.
When I load the page the first time, I can see in the debugger the component binding correctly to the backing value; the page loads without incident. It's when I try to activate the AJAX event on said component that it blows up. I get an error, and nothing updated via AJAX. It's happening with every AJAX component I try to convert. Here is one such example:
<h:selectOneMenu
value="#{userSession.selectedNetwork}"
id="network"
>
<f:selectItems value="#{userSession.networkUIOptions}" />
<f:ajax event="change" render="selectedStation edit_site_button add_site_button"/>
</h:selectOneMenu>
I don't know if this is relevant or not, but the bean I'm referencing in that code is now annotated ala JSF2.0 and removed from faces-config.xml, however, I haven't completely gotten rid of faces-config.xml. Still working on converting everything. Also, I'm running this on Tomcat 6.0.
Any help, suggestions would be greatly appreciated. I'm really stuck on this problem.
EDIT 1:
Using mojarra version 2.1.1 as per the bundle title I downloaded. Having trouble getting exact stack trace. Logging doesn't seem to be working correctly after changing so many things. Will keep trying. Also will try simple page and report results.
EDIT 2:
So, trying to 'minimal' page yielded the same results, same error.
Still couldn't get logging to work exactly right, so just did some ghetto logging. See below for something resembling a proper stack trace:
EDIT 3:
Okay, updated ghetto stack trace with line numbers. You guessed right on the line number in the first class to toss the error:
http://pastebin.com/49yUDcPM
doFilter function of NPNSessionFilter.java:
http://pastebin.com/iwG0rcQ6
test page I created for BalusC's at suggestion:
http://pastebin.com/kSeUyj7g
EDIT 4:
http://tinypic.com/r/2dca0yo/7
http://tinypic.com/r/16jet7s/7
Here are images of the libs currently packaged in the WAR's WEB-INF/lib folder. Previous programmer included a lot of junk that I haven't cleaned out yet. Likewise, not sure where struts JARs are coming from. Deleted any pre-dist JARs I could find relating to strusts or tiles.
EDIT 5:
Okay, breakthrough! This comment made a world of difference "Likewise, not sure where struts JARs are coming from. Deleted any pre-dist JARs I could find relating to strusts or tiles."
Cleaned ear, re-dist, and things work better now. Obviously it wasn't just some lib I forgot to remove, but a lib I forgot to remove, and then clean the EAR out after having removed. AJAX requests are now properly going through, and I can see in the debugger values being re-bound as the request comes through! Load of other problems, but can manage those in my own time. BalusC, you led me to this solution; if you want to submit an answer I'll gladly accept it!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此异常表明 JSF 视图根为 null,这又表明存在一些针对 JSF 1.2 的第三方或自定义
ViewHandler< /code> 在类路径中,它对于 JSF 2.0 来说并不完全正确,因此也需要升级(或删除)总共)。
根据您的屏幕截图以及所有 JAR 的概述,
struts-faces
JAR 是主要嫌疑对象。但 Apache Commons 和 JSTL 库的混合版本看起来也不对劲。This exception indicates that the JSF view root is null which in turn indicates among others that there's some JSF 1.2 targeted 3rd party or custom
ViewHandler
in the classpath which isn't doing its job entirely right for JSF 2.0 and thus needs to be upgrade as well (or removed altogether).Based on your screenshot with the overview of all JARs, the
struts-faces
JAR is the main suspect. But those mixed versions of Apache Commons and JSTL libraries also doesn't look right.