Unexpected Effects
Many of you may know this already, but I was reminded the other day how this can catch even some of the most brilliant JSF developers. When you comment out a component in your xhtml page that has EL bindings, you may not be REALLY disabling it.Expression Language (EL) is parsed and evaluated as the page is being rendered. As a result, any exposed EL syntax will be processed including functions which could have deleterious effects. For example, take a look at the following code, and guess what it will do.
So what happens?
Scary things happen....- It executes
- Parser exception. The parser will try to find a property called doSomething
- It will execute, please note that there is no <h:form/>. It is not required since we are evaluating the EL.
- Parser exception. The parser will try to find a property called doSomethingElse
Sensei what do I do?
You have a couple of options. The first option is the easiest, and it is likely what you want anyway with your JSF pages. You can disable the comments. No need to transmit your development comments to the end users anyway. The second option is to add a - between the # and the { like this#-{indexBean.doSomethingElse()}
.
The first option is handled by adding a configuration parameter to the
web.xml
file as shown below.
Here is a more complete example:
The result of the code is as follows:
The complete code example was developed using NetBeans 8.0 and GlassFish 4.0 on JDK 8. The code can be found here: auto-execute-el
0 comments :
Post a Comment