JSF does not report undefined beans
I started to learn Java, JSF2 and JPA2 and used "Pet Catalog" example project to start with. I use Eclipse + Glassfish.
So I have JSF view page with following line:
<h:outputText value="Item #{catalog.pagingInfo.firstItem + 1} .. #{cataloTYPO.pagingInfo.lastItem} of #{catalog.pagingInfo.itemCount}"/>
cataloTYPO does not exist, it's not a bean, not class, nothing. The problem is that JSF seems to be perfectly happy with it and outputs "Item 1 .. of 29" I'd expect it would raise exception or at least write the problem to log, but nothing happens.
I tried to google this problem but nobody seems to have it.
Thanks fo开发者_如何学运维r help.
EDIT: alternatively, is this normal behavior?
This is not specific to JSF. This is specific to EL (those #{}
things). It's designed to be nullsafe. If nothing is available in the scope, i.e. it is null
, then it will just take no further actions. It prints nothing and no NullPointerException
will be thrown. This is particularly useful in cases where an empty
situation is allowed.
If you want to raise exceptions or warn reports anyway, then you'll have to write your own ELResolver
which does that when the resolved value turns out to be null
. A nice article about implementing an own ELResolver
for JSF can be found here.
精彩评论