With a little help, and some more time, I've been able to solve this. The 
solution iwas not that simple, so lets share it.

Short answer: RTFM i. e., the workbench example ;-)

Long answer: To summarize: I have a page which needs to invoke an external 
service, with some parameters. The external service will eventually render a 
new page. The service available as a hivemind service

Solution:

1) Declare an interface which describes the page's ability to provide the 
necessary parameters to the service. In my case, it's just a string parameter 
called layoutId,
so the interface just has a getter method getLayoutId(). Interface is below. 
Let the page implement that interface. Your page should also have a getter 
returning the service you need to invoke - in my case the injected 
pdfListService. Excerpt from Page below.

2) Instead av a ServiceLink, create a DirectLink with the name of the service  
attribute as an argument - link definition below.

3) Create an Asset representing the service. The asset just implements the  
getLInk method. See asset below. (BTW, an ExternalServiceAsset could be used 
with any service, and should IMHO be part of the framework). Use Asset below.

4) Write the listener method, which just returns the Asset defined above. 
Excerpts
from Page below.

5) Modify the service's getLink() and service() methods to encode/decode
the parameters. Excerpts below.

That's that. Not that simple, but  seems to work. If there is something simpler 
which works, let us know!

The interface:
==========

public interface IListParameters extends IComponent
{
        public String getLayoutId();    
}

Excerpts from the Page:
=================
public abstract class CallServicePage extends BasePage 
implements IListParameters
{
        /* The DirectLink parameter. */
        @InjectObject("service:full.path.to.ServiceId")
        public abstract IEngineService getPdfListService();

        /* implement IListParameters */
        public String getLayoutId()
        {
            return /* something */.
        }

        /* Listener method for the DirectLink. */
       public ILink serviceAction( IRequestCycle  cycle, 
                                             IEngineService listService )
       {
             DownloadListAsset asset
                 =  new DownloadListAsset(cycle, this, listService);
             return new StaticLink( asset.buildURL() );
       }

 }

The DownLoadListAsset:
=================
public class ExternalServiceAsset extends AbstractAsset
{
    private IEngineService listService;

    private IComponent    serviceParameters;

    public DownloadListAsset(IRequestCycle     cycle, 
                             IComponent   serviceParameters, 
                             IEngineService    listService)
    {
        super(null, null);
     
        this.listService = listService;
        this.serviceParameters = serviceParameters;
    }

    public String buildURL()
    {
        ILink l = listService.getLink(false, listParameters);
        return l.getURL();
    }

    public InputStream getResourceAsStream()
    {
        return null;
    }

    public InputStream getResourceAsStream(IRequestCycle cycle, Locale locale)
    {
        return null;
    }

The link definition   
=============

<component id="pdfLink" type="DirectLink">
        <binding name="parameters"
                 value="ognl:new java.lang.Object[] { pdfListService }" />
        <binding name="listener"
                 value="ognl:listeners.serviceAction" />
 </component>

Excerpts from the service:
===================
public ILink getLink(boolean post, Object parameter )
{
        Defense.isAssignable(parameter, IComponent.class, "parameter");
        IListParameters listParameters  = (IListParameters) parameter;

        Map<String,String> parameters =
                    new HashMap<String,String>();

        parameters.put( ServiceConstants.SERVICE, getName() );
        parameters.put( ServiceConstants.PAGE, 
                                listParameters.getPage().getPageName() );
        parameters.put( ServiceConstants.COMPONENT, 
                                listParameters.getIdPath());
        parameters.put( "layoutId", listParameters.getLayoutId() );
                                
        return linkFactory.constructLink(this, false, parameters, true);    
}

public void service( IRequestCycle cycle )
throws IOException
{
        String layoutId  = cycle.getParameter("layoutId");
        /* perform the service...*/
}
        
 
 



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

Reply via email to