简体   繁体   中英

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 for 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, ie 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM