But why should we stop on such a simple solution? Let's evolve this idea (dynamic EL
construction) till the whole madness?
Why only parameter value should be dynamic? What about bean name or action name? If action
value used only on invoke application phase, and on rendering phase it is converted to
MethodBinding object for validation (I'm not sure it is true)?
For example:
<s:link
action="#{#{beanNameToEvaluate}.#{methodNameToEvaluate}(#{valueToEvaluate)})}"
.../>
Looks ugly, eha?
But sometimes I thought about it - because of my humble knowledge of problems with it, as
I can see the result of such construction only as a GET paramet in URL of the link.
So, may be it just possible to allow next code:
<s:link
dynaAction="#{beanNameToEvaluate}.#{methodNameToEvaluate}(#{valueToEvaluate)})"
.../>
like additional attribute for tag s:link which will try to evaluate the code before
considering it's contents as method name during page rendering phase?
Wouldn't it be convenient?
Again, in another words,
<s:link action="#{someBean.doSomeAction('value1')}" ... />
may be convenient to write as
<s:link dynaAction="someBean.doSomeAction('value1')" ... />
or
<s:link dynaAction="#{'someBean.doSomeAction(\'value1\')'}"
... />
which looks more real...
It will work the same way but with pre-evaluation of given expression.
For JSP tags it can be something like this:
package org.jboss.seam.ui.tag;
|
| import javax.el.ELContext;
| import javax.el.ELException;
| import javax.el.ValueExpression;
| import javax.faces.FacesException;
| import javax.faces.component.ActionSource;
| import javax.faces.component.UIComponent;
| import javax.faces.context.FacesContext;
| import javax.faces.el.MethodBinding;
|
| @SuppressWarnings("deprecation")
| public class DynaLinkTag extends LinkTag {
|
| private String dynaAction;
|
| protected void setProperties(UIComponent component) {
| super.setProperties(component);
| setDynaActionProperty(getFacesContext(), component, getDynaAction());
| }
|
| public static void setDynaActionProperty(FacesContext context, UIComponent
component, String dynaAction) {
| if (dynaAction != null) {
| if (!(component instanceof ActionSource)) {
| throw new IllegalArgumentException("Component " +
component.getClientId(context) + " is no ActionSource");
| }
| if (isValueReference(dynaAction)) {
| ValueExpression vb = component.getValueExpression(dynaAction);
| ELContext elContext = FacesContext.getCurrentInstance().getELContext();
| String actionValue = null;
| try {
| actionValue = (String) vb.getValue(elContext);
| } catch (ELException ele) {
| throw new FacesException(ele);
| }
| MethodBinding mb = context.getApplication().createMethodBinding(actionValue,
null);
| ((ActionSource) component).setAction(mb);
| } else {
| component.getAttributes().put("outcome", dynaAction);
| }
| }
| }
|
| public String getDynaAction() {
| return this.dynaAction;
| }
|
| public void setDynaAction(String dynaAction) {
| this.dynaAction = dynaAction;
| }
| }
|
|
For Facelets it needs changes in Facelets code, I think, it is not so obvious as for
JSP...
What do you think?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4067933#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...