Here the correct code:

public class TemplateSourceDelegate implements ITemplateSourceDelegate {

   /**
    * Method called by Tapestry when it is unable to find the template of a
component or a page
    */

   public ComponentTemplate findTemplate(IRequestCycle cycle, IComponent
component, Locale locale) {

       Resource res = component.getSpecification().getSpecificationLocation();


       String componentAttributeName = "jwcid";

       // code that retrives the template in a db:
       char[] templateData = "<h2>Test</h2>".toCharArray();

       ITemplateParserDelegate delegate = new
DefaultParserDelegate(component, componentAttributeName, cycle, new
ComponentSpecificationResolverImpl());

       TemplateToken[] tokens;
       TemplateParser parser = new TemplateParser();
       parser.setFactory(new TemplateTokenFactory());

       try {
           // code that throws no more a NullPointerException:
           tokens = parser.parse(templateData, delegate, res);
       }
       catch (TemplateParseException ex) {
           throw new ApplicationRuntimeException("Error in
TemplateSourceDelegate", ex);
       }

       return new ComponentTemplate(templateData, tokens);

   }

}



2006/12/11, Tapestry User List <[EMAIL PROTECTED]>:

Hello,

It seems nobody has ever been able to implement the
ITemplateSourceDelegate interface.

Does it mean that it is simply not possible ?

I tried to implement this interface but as others people, I got a
NullPointerException in the method TemplateParser.addTextToken().

Here my code:

public class TemplateSourceDelegate implements ITemplateSourceDelegate {

    /**
     * Method called by Tapestry when it is unable to find the template of
a component or a page
     */

    public ComponentTemplate findTemplate(IRequestCycle cycle, IComponent
component, Locale locale) {

        Resource res = component.getSpecification().getSpecificationLocation();


        String componentAttributeName = "jwcid";

        // code that retrives the template in a db:
        char[] templateData = "<h2>Test</h2>".toCharArray();

        ITemplateParserDelegate delegate = new
DefaultParserDelegate(component, componentAttributeName, cycle, new
ComponentSpecificationResolverImpl());

        TemplateToken[] tokens;
        ITemplateParser parser = new TemplateParser();

        try {
            // code that throws a NullPointerException:
            tokens = parser.parse(templateData, delegate, res);
        }
        catch (TemplateParseException ex) {
            throw new ApplicationRuntimeException("Error in
TemplateSourceDelegate", ex);
        }

        return new ComponentTemplate(templateData, tokens);

    }

}

D.

Reply via email to