1. 程式人生 > >Setting parameter value for binding with code

Setting parameter value for binding with code



Back in the 10.1.3 days I wrote an entry that showed how to set the value of a parameter that is referenced in your page's binding by writing some code in your backing bean.
Well with 11g we moved to JSF 1.2 and things have changed a bit.
And today I needed to look up the update syntax for a demo I was working on.

Since this is a useful little piece of code I'm pasting it here for my own future reference.
A special shout out to Edwin Biemond for this post that has a lot of other useful code bits.
If you want more of these download the Fusion Order demo and look up the JSFUtil java class that is used throughout the demo when coding in the backing bean is needed.

FacesContext facesCtx = FacesContext.getCurrentInstance();
Application app = facesCtx.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesCtx.getELContext();
ValueExpression ve =
elFactory.createValueExpression(elContext, "#{bindings.p_zip.inputValue}",
Object.class);
ve.setValue(elContext, newValue);