Support listener methods that might redirect OR return a page
-------------------------------------------------------------

         Key: TAPESTRY-945
         URL: http://issues.apache.org/jira/browse/TAPESTRY-945
     Project: Tapestry
        Type: Improvement

  Components: Framework  
    Versions: 4.0.1    
    Reporter: Paul Field
    Priority: Minor


I have a search component that finds companies:
* If there is one company in the results, it *redirects* to that company's main 
page
* If there is more than one company, it *returns* a search results page

I would like to write a listener method like this:

    public Object doSearch() {
        List<Company> results = getResults();
        
        if (results.size() == 1){
            ExternalServiceParameter parameter = new 
ExternalServiceParameter("CompanyPage", new Company[]{results.get(0)});
            return getExternalService().getLink(false, parameter);   // 
********* Returns ILink to redirect ***********
        } else {
            SearchResultsPage searchResultsPage = getResultsPage();
            searchResultsPage.setSearchResults(results);
            return searchResultsPage;   // ******* Returns IPage **********
        }
    }

The problem is that a return type of Object means that the method is not 
recognised as a listener.


**** SUGGESTION ****

Add a marker interface to ILink and IPage for example: 
interface IDestination  {}
interface ILink extends IDestination {}
interface IPage extends IDestination {}

Change this method in the class ListenerMapSourceImpl:

    boolean isAcceptibleListenerMethodReturnType(Method m)  {
        Class returnType = m.getReturnType();
        if (returnType == void.class || returnType == String.class)
            return true;
        return IDestination.class.isAssignableFrom(returnType);    // THIS IS 
THE LINE THAT CHANGES
    }


-- 
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