I've written an application in JSF which generates some CRUD pages based on some configuration files. To configure those pages it is possible to provide parameters. They can be of any type and also EL expressions. Currently I create and evaluate these expressions for each getter-invocation, which is not the ideal solution, I think:
Now I have two simple questions which I can't answer for myself:
It should be possible to cache those ValueExpression instances per request. On first access (in my case I use JSF's
postAddToView
event) I create the expression and evaluate in in each getter-invokation.public void populateComponent(ComponentSystemEvent event) { FacesContext context = FacesContext.getCurrentContext(); _valueExpression = context.getApplication().getExpressionFactory() .createValueExpression(context.getELContext(), _expression, String.class); } public String getExpressionValue() { FacesContext context = FacesContext.getCurrentContext(); return (String) _valueExpression.getValue(context.getELContext()) }
This should be the same as using the expression directly in the XHTML which is processed by JSF itself. Any problems with this solution that I don't see at the moment?
Is it also possible to create the instance of the ValueExpression once and use it for all request? The cache would be on the application level instead of per request. This removes the
postAddToView
event and moves that logic to my configuration parser (which has access to the FacesContext). Or may I hit any side effects when a single value expression is used in multiple requests/threads?