i try to fix unmanagable code like this:
<a4j:commandButton action="dia_ok" actionListener="#{...}" ajaxSingle="true" .../>
i fix it by bind the button to an ManagedBean and swap all the attributes to Java-Code, so ill only have:
<a4j:commandButton binding="#{...}"/>
I successfully coded setAjaxSingle(true) and the actionListener-attribute, but i fail on code the action-Attribute.
My question is: how can i specify the action-outcome whereat the method button.setActionExpression() does only allows argument of MethodExpression instead of String?
You can just create a MethodExpression
with a value of "dia_ok"
and a return type of String
. The expression does not necessarily refer to "#{bean.action}"
or something.
E.g.
button.setActionExpression(createMethodExpression("dia_ok", String.class));
with
private static MethodExpression createMethodExpression(String expression, Class<?> returnType) {
FacesContext facesContext = FacesContext.getCurrentInstance();
return facesContext.getApplication().getExpressionFactory().createMethodExpression(
facesContext.getELContext(), expression, returnType, new Class[0]);
}
I only fail to see how it makes the code more manageable as you're mingling the view into the model this way. Perhaps you need to writeup some general convention how attributes should be ordered/organized so that it's better manageable? E.g. id
first, then value
, etc and then be consistent with this convention.