Results 1 to 3 of 3

Thread: XTemplate loop, Collections, and functions with multiple arguments

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Jul 2012
    Vote Rating

    Default Answered: XTemplate loop, Collections, and functions with multiple arguments


    I am trying to implement XTemplates in my project and have run across an issue. All the examples / sample code I've seen only use only argument to the template function, so I can't tell what I'm doing wrong.

    The code is as follows:

    interface NewsTemplates extends XTemplates {
      @XTemplate("<div class='{style.rounded_corners_title}'>{set.sourceName}</div>"
        + "<div class='{style.rounded_corners_content}'>"
        + "<tpl for='items'>{#}</tpl>"
        + "</div>")
      SafeHtml newsBlock(GeneralCssResource style, INewsSet set, Collection<INewsItem> items);
    This code throws a runtime NullPointerException. However, if I comment out the <tpl ...></tpl> section, then it runs perfectly well. According to the GXT 3 javadocs, XTemplate should be able to iterate over a Collection. Unfortunately, all the examples use only one argument and are based on either "." or a value inside that single argument. Does anyone have any advice on how to fix this problem?

    EDIT: I've used GWT.log() to check the values of the three variables and all are fine. The exception is thrown before a call to the function can be made (during the GWT.create() process). Apparently, it looks like the generator is unable to parse the code as I've written it...


    Last edited by zakaluka; 20 Jul 2012 at 5:47 PM. Reason: added some clarification, fixed title.

  2. There may be an error in the documentation - at present, tpl#for works with a for loop, not a for-each. This generally makes XTemplates more efficient, but requires either a Java array, or a List - Collection isn't supported at this time. I'll correct the documentation, and see about a better error message for this case.

    The issue about "." is what "." can mean in different contexts:

    * If there is only one argument to the template, "." refers to that argument. Likewise, if "Person person" is the argument, and person.getName() is valid Java, then you can refer to the person's name as "name" or as "".
    * If there is more than one argument, "." can't resolve to any one object, so is invalid at the global level.
    * Within a for loop, "." will resolve to the current item, no matter how many arguments are in the method.

    This is why a method
    SafeHtml render(List<Data> data)
    uses for=".", while
    SafeHtml render(List<Data> data, String otherVar)
    must use for="data"

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts