eclipse 如何调试 JSF/EL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8266953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to debug JSF/EL
提问by mrzasa
How to debug EL in the JSF page? I'd like to watch variable values, function calls an so on. The best solution would be an eclipse plugin, but any other possibility is better than guessing "Why this expression failed to render correctly?".
如何在JSF页面中调试EL?我想看变量值,函数调用等等。最好的解决方案是 eclipse 插件,但任何其他可能性都比猜测“为什么这个表达式无法正确呈现?”要好。
回答by BalusC
Closest what you can get in JSF/Facelets is placing an <ui:debug />
somewhere in the view:
在 JSF/Facelets 中最接近的是<ui:debug />
在视图中放置一个位置:
<ui:debug />
Pressing CtrlShiftDshould then show a popup window with debug information about the component tree and all available request parameters and request/view/flash/session/application scoped variables. It's basically a representation of the content of all those maps.
CtrlShiftD然后按下应该显示一个弹出窗口,其中包含有关组件树和所有可用请求参数和请求/视图/闪存/会话/应用程序范围变量的调试信息。它基本上代表了所有这些地图的内容。
The hotkey is by the way configureable by hotkey
attribute so that you can choose another whenever it clashes with browser default hotkeys, as it would do in Firefox; CtrlShiftDwould by default show the Add bookmarksdialogue. Here's how you could make it to listen on CtrlShiftXinstead:
顺便说一下,热键可以通过hotkey
属性进行配置,这样您就可以在与浏览器默认热键冲突时选择另一个,就像在 Firefox 中一样;CtrlShiftD默认情况下会显示添加书签对话框。以下是您可以让它听的方法CtrlShiftX:
<ui:debug hotkey="x" />
You'd usually also like to hide it in non-development stage, so add a rendered condition like that:
您通常还希望在非开发阶段隐藏它,因此添加这样的渲染条件:
<ui:debug hotkey="x" rendered="#{facesContext.application.projectStage == 'Development'}" />
In the shown debug information, the information provided about scoped variables isn't that great as you would expect. It only shows the Object#toString()
outcome of all scoped variables which defaults to com.example.Bean@hashcode
. You can't explore their properties and the values of their properties directly like as you could do in debug view of Eclipse's debugger. You'd need to implement toString()
on the class accordingly so that as much as possible relevant information is returned (if necessary, you can even let Eclipse autogenerate it by rightclick source code > Source > Generate toString()):
在显示的调试信息中,提供的有关作用域变量的信息并不像您期望的那样好。它只显示Object#toString()
默认为com.example.Bean@hashcode
. 您不能像在 Eclipse 调试器的调试视图中那样直接探索它们的属性和它们的属性值。您需要相应地toString()
在类上实现,以便返回尽可能多的相关信息(如有必要,您甚至可以让 Eclipse 通过右键单击源代码 >源 > 生成 toString() 来自动生成它):
@Override
public String toString() {
return String.format("Bean[prop1=%s,prop2=%s,prop3=%s]", prop1, prop2, prop3);
}
As to method calls, just put a breakpoint on the Java source code the usual way. Eclipse will kick in there as well when EL calls the method. If it's a managed bean, you'll also just see its properties in the Eclipse debugger.
至于方法调用,只需按照通常的方式在 Java 源代码上放置一个断点即可。当 EL 调用该方法时,Eclipse 也会启动。如果它是一个托管 bean,那么您也只会在 Eclipse 调试器中看到它的属性。
回答by Jonathan
If you are really having problems then if you can get the source for the EL implementation (easy enough for the RI) then you can use Eclipse to set breakpoints in the EL implementation methods. You need to get an understanding of how the EL code works, but it isn't thatcomplicated. Not for the very faint hearted though.
如果您确实遇到了问题,那么如果您可以获得 EL 实现的源代码(对于 RI 来说很容易),那么您可以使用 Eclipse 在 EL 实现方法中设置断点。您需要了解 EL 代码的工作原理,但并没有那么复杂。不适合非常胆小的人。
Another possibility would be to create and evaluate the EL programatically. There are examples of how to do this around. You can then use the debugger to fiddle around with what the expression is and what the result is until you've worked out where your problem lies.
另一种可能性是以编程方式创建和评估 EL。有一些关于如何做到这一点的例子。然后,您可以使用调试器摆弄表达式是什么以及结果是什么,直到找出问题所在。