I need to create a dependent converter for a view-param which JSF has no built in solution for.
In this example bar
is dependent on foo
.
<f:viewParam name="foo" value="#{bean.foo}" converter="#{appScopeBean.fooConverter}"/>
<f:viewParam name="bar" value="#{bean.bar}" converter="#{bean.barConverter}"/>
In @PostConstruct
the converted value for bean.foo
is not yet available, but i could manually retrieve the request parameter bar
and the Converter
by performing el lookup.
@PostConstruct
public void init()
{
// mimic UIViewParameter behavior
// grab request parameter manually
final String fooId = context.getExternalContext().getRequestParameterMap().get("foo");
// grab converter manually
final Converter fooConverter = context.getApplication().evaluateExpressionGet(context,
"#{appScopeBean.fooConverter}", Converter.class);
final Foo foo = fooConverter.getAsObject(context, null, fooId);
// create Bar converter dependent on Foo
}
Now i tried to obtain the converter by resolving the UIViewParameter
, but its converter instance is null since not yet set by JSF lifecycle (why? if converter scope is broader it should be safe).
So i want to obtain the el-expression to lookup the converter to do something like (to reduce the need to hardcode it as above DRY):
@PostConstruct
public void init()
{
// mimic UIViewParameter behavior
final UIViewParameter fooViewParam = FacesContextUtils.getViewParam(context, "foo");
// final Converter fooConverter = fooViewParam.getConverter(); is null
// pseudo code
final Converter fooConverter = context.getApplication().evaluateExpressionGet(context,
fooViewParam.getConverterExpression(), Converter.class);
final Foo foo = fooConverter.getAsObject(context, null, fooId);
// create Bar converter dependent on Foo
}
JSF should handle support for dependent converters like some iterative life-cycle bean event that is invoked after each UIViewParameter
converter instantiation.