[ 
http://issues.apache.org/jira/browse/TAPESTRY-313?page=comments#action_12415523 
] 

sorphi commented on TAPESTRY-313:
---------------------------------

Very nice, I have implemented a same idea with it recently.

refer:http://forum.javaeye.com/viewtopic.php?t=20744

Objective:

    1/page specifiaction
   Test.page 

<page-specification> 
  <property name="testProperty1"/> 
  <property name="testProperty2"/> 
  <property name="testProperty3"/> 
  <property name="testProperty4"/> 
  <component id="parameterBinder" type="ParameterBinder"> 
    <binding name="p1" value="ognl:testProperty1"/> 
    <binding name="p2" value="ognl:testProperty2"/> 
    <binding name="p3" value="ognl:testProperty3"/> 
    <binding name="p4" value="ognl:testProperty4"/> 
  </component> 
</page-specification>
 


2/page template

Test.html 

<span jwcid="@Insert" value="ognl:testProperty1">testProperty1</span><br> 
<span jwcid="@Insert" value="ognl:testProperty2">testProperty2</span><br> 
<span jwcid="@Insert" value="ognl:testProperty3">testProperty3</span><br> 
<span jwcid="@Insert" value="ognl:testProperty4">testProperty4</span><br> 


<a href="#" jwcid="@ParameterizedLink" page="literal:Test" 
parameterBinder="component:parameterBinder">this page</a>
 
3/URL 
http://host/Test.external?p1=Sstring&p2=d123.0&p3=123&p4=f123.0 




Implements:

1/ Define a ParameterBinder component.

public abstract class ParameterBinder extends AbstractComponent { 
  protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) { 
  } 
} 

<component-specification class="tapestry.jwc.ParameterBinder" allow-body="no" 
allow-informal-parameters="yes"> 
</component-specification>
 
2/ Define a ParameterizedLink component like ExternalLink 

public abstract class ParameterizedLink extends AbstractLinkComponent { 
  public abstract IEngineService getParameterizedService(); 

  public ILink getLink(IRequestCycle cycle) { 
    Map parameters = null; 
    ParameterBinder binder = getParameterBinder(); 
    if (binder != null) { 
      Map bindingMap = binder.getBindings(); 
      parameters = new HashMap(bindingMap.size()); 
      for (Iterator i = bindingMap.entrySet().iterator(); i.hasNext(); ) { 
        Map.Entry entry = (Map.Entry) i.next(); 
        String bindingName = (String) entry.getKey(); 
        IBinding binding = (IBinding) entry.getValue(); 
        parameters.put(bindingName, binding.getObject()); 
      } 
    } 
    else { 
      parameters = Collections.EMPTY_MAP; 
    } 

    ParameterizedServiceParameter psp = new ParameterizedServiceParameter( 
        getTargetPage(), 
        parameters); 

    return getParameterizedService().getLink(false, psp); 
  } 

  public abstract String getTargetPage(); 

  public abstract ParameterBinder getParameterBinder(); 

} 

<component-specification class="tapestry.jwc.ParameterizedLink"> 
  <description>Creates link using the parameterized service, which can pass 
service parameters to the targeted page and autobind those.</description> 
  <parameter name="page" required="yes" property="targetPage"/> 
  <parameter name="parameterBinder"/> 
.... 
</component-specification>
 

3/ Define a ParameterizedService egine service like ExternalService

    private String _parameterBinderId = "parameterBinder";// could inject other 
id name by hivemind

  public void service(IRequestCycle cycle) throws IOException { 
    String pageName = cycle.getParameter(ServiceConstants.PAGE); 
    IPage rawPage = cycle.getPage(pageName); 

    cycle.activate(rawPage); 

    autoBindParameters(cycle, rawPage); 

    _responseRenderer.renderResponse(cycle); 
  } 

  private void autoBindParameters(IRequestCycle cycle, 
                                  IPage page) { 

    ParameterBinder binder = (ParameterBinder) page 
                             .getComponents().get(_parameterBinderId); 
    if (binder == null) { 
      return; 
    } 
    if (LOG.isDebugEnabled()) { 
      LOG.debug("Begin binding parameters by component " + binder.getId()); 
    } 
    Map bindingMap = binder.getBindings(); 
    for (Iterator i = bindingMap.entrySet().iterator(); i.hasNext(); ) { 
      Map.Entry entry = (Map.Entry) i.next(); 
      String bindingName = (String) entry.getKey(); 
      IBinding binding = (IBinding) entry.getValue(); 
      String rawValue = cycle.getParameter(bindingName); 
      if (rawValue != null) { 
        Object value = _dataSqueezer.unsqueeze(rawValue); 
        binding.setObject(value); 
        if (LOG.isDebugEnabled()) { 
          LOG.debug("bindingName:" + bindingName); 
          LOG.debug("binding:" + binding); 
          LOG.debug("parameter value:" + value); 
        } 
      } 
    } 
  }
 
Shortage:
 
1.Each page which required parameter auto bind function , need declare a 
ParameterBinder with special ID

2.ParameterBinder cannot bind some reserved parameter name, such as page/id 
etc. So, parameters in URL cannot use these name.

3. Hardcode parameter literal value should abide with DateSqueezer 
speciafication.





> External service --> listener method
> ------------------------------------
>
>          Key: TAPESTRY-313
>          URL: http://issues.apache.org/jira/browse/TAPESTRY-313
>      Project: Tapestry
>         Type: Improvement

>   Components: Framework
>     Versions: 4.0
>     Reporter: Howard M. Lewis Ship
>      Fix For: 4.1

>
> It would be nice if you could use the external service (i.e., ExternalLink) 
> with a page that doesn't implement
> the IExternalPage interface.
> Instead, it could simply get and invoke the listener named 
> "activateExternalPage" (or would a different name be more appropriate?)
> This would make it easier for "external pages" to access the listener 
> parameters, since (as a listener method), they can be provided as Java method 
> parameters.
> In fact, I would deprecate IExternalPage after implementing this change.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to