[jboss-user] [JBoss Seam] - Re: Evaluation of action attibute in s:link

dmitriy.lapko do-not-reply at jboss.com
Thu Jul 26 13:51:07 EDT 2007


Do you mean:

instead of trying to do:

<s:link action="#{someBean.someMethod(someValue)}" .../>

to use:

<s:link action="#{someBean.someMethod}">
  | <f:param name="nameForMapping" value="#{someValue}"/>
  | </s:link>
  | 
?

And in someMethod implementation just read this value and call what you need? 

(Just to finish this conversation)



 By the way, I managed to implement idea with double-interpolation, so now I can write:

<s:link dynaAction="#{'itemBrowseList'}.#{'browseAll'}">#{messages['submenu.browse.all']}</s:link>

or 

<s:link dynaAction="itemBrowseList.browseAll">#{messages['submenu.browse.all']}</s:link>

or 

<s:link dynaAction="#{'itemBrowseList.browseAll'}">#{messages['submenu.browse.all']}</s:link>

and it works like 

<s:link action="#{itemBrowseList.browseAll}">#{messages['submenu.browse.all']}</s:link>


It was a nasty hack into Facelets, just to check this idea, I don't think I will use it in production :)


But for history:

I made changes in 2 classes in jsf-facelets.jar:

added to class com.sun.facelets.tag.TagAttribute method 

    public MethodExpression getMethodPreEvaluationExpression(FaceletContext ctx, Class type,
  |             Class[] paramTypes) {
  |         try {
  |             ExpressionFactory f = ctx.getExpressionFactory();
  |             
  |             ValueExpression valueExpression = this.getValueExpression(ctx, type);
  |             
  |             return new TagMethodExpression(this, f.createMethodExpression(ctx,
  |                     "#{"+(String)valueExpression.getValue(ctx)+"}", type, paramTypes));
  |         } catch (Exception e) {
  |             throw new TagAttributeException(this, e);
  |         }
  |     }

and 2 internal classes into com.sun.facelets.tag.jsf.ActionSourceRule:

    final static class DynaActionMapper extends Metadata {
  | 
  |         private final TagAttribute attr;
  | 
  |         public DynaActionMapper(TagAttribute attr) {
  |             this.attr = attr;
  |         }
  | 
  |         public void applyMetadata(FaceletContext ctx, Object instance) {
  |             ((ActionSource) instance).setAction(new LegacyMethodBinding(
  |                     this.attr.getMethodPreEvaluationExpression(ctx, String.class,
  |                             ActionSourceRule.ACTION_SIG)));
  |         }
  |     }
  | 
  |     final static class DynaActionMapper2 extends Metadata {
  | 
  |         private final TagAttribute attr;
  | 
  |         public DynaActionMapper2(TagAttribute attr) {
  |             this.attr = attr;
  |         }
  | 
  |         public void applyMetadata(FaceletContext ctx, Object instance) {
  |             ((ActionSource2) instance).setActionExpression(this.attr
  |                     .getMethodPreEvaluationExpression(ctx, String.class,
  |                             ActionSourceRule.ACTION_SIG));
  |         }
  | 
  |     }  
  | 

also changed its method  public Metadata applyRule(String name, TagAttribute attribute,  MetadataTarget meta)  for support of dynaAction attribute:

  |             if ("dynaAction".equals(name)) {
  |                 if (elSupport && meta.isTargetInstanceOf(ActionSource2.class)) {
  |                     return new DynaActionMapper2(attribute);
  |                 } else {
  |                     return new DynaActionMapper(attribute);
  |                 }
  |             }   



It's crazy, yeh?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4067946#4067946

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4067946



More information about the jboss-user mailing list