如何调试 JSF/EL [英] how to debug JSF/EL

查看:36
本文介绍了如何调试 JSF/EL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JSF页面调试EL?我想看变量值,函数调用等等.最好的解决方案是 Eclipse 插件,但任何其他可能性都比猜测为什么这个表达式无法正确呈现?"要好.

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/Facelets 中最接近的是放置一个 视图中的某处:

Closest what you can get in JSF/Facelets is placing an <ui:debug /> somewhere in the view:

<ui:debug />

CtrlShiftD 然后应该会显示一个弹出窗口,其中包含有关组件树的调试信息以及所有可用的请求参数和请求/视图/flash/session/application 范围的变量.它基本上代表了所有这些地图的内容.

Pressing CtrlShiftD should 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.

顺便说一下,热键可以通过 hotkey 属性进行配置,这样您就可以在与浏览器默认热键冲突时选择另一个,就像在 Firefox 中一样;CtrlShiftD 将默认显示添加书签对话框.以下是如何让它在 CtrlShiftX 上收听:

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; CtrlShiftD would by default show the Add bookmarks dialogue. Here's how you could make it to listen on CtrlShiftX instead:

<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'}" />

在显示的调试信息中,提供的有关作用域变量的信息并不像您预期​​的那么好.它只显示默认为 com.example.Bean@hashcode 的所有范围变量的 Object#toString() 结果.您不能像在 Eclipse 调试器的调试视图中那样直接探索它们的属性和它们的属性值.您需要相应地在类上实现 toString() 以便尽可能多地返回相关信息(如有必要,您甚至可以通过右键单击源代码让 Eclipse 自动生成它 > Source> 生成 toString()):

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()):

@Override
public String toString() {
    return String.format("Bean[prop1=%s,prop2=%s,prop3=%s]", prop1, prop2, prop3);
}

对于方法调用,只需按照通常的方式在 Java 源代码上放置一个断点即可.当 EL 调用该方法时,Eclipse 也会启动.如果它是托管 bean,您还将在 Eclipse 调试器中看到它的属性.

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.

这篇关于如何调试 JSF/EL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆