PDA

View Full Version : [FIXED] XTemplate bug found [Beta2]



EthiC
14 Feb 2012, 7:23 AM
Today I was using XTemplates and stumbled upon a fairly harsh error:

[ERROR] [mockup] - Errors in 'generated://5024447DD15A3A8D9ED11B1F09E77F17/mockup/client/view/NewsTemplate_render_SafeHtml__NewsItem_item___SafeHtmlTemplates.java'
[ERROR] [mockup] - Line 7: String literal is not properly closed by a double-quote


I made a very simple html fragment: (named newstemplate.html)

<div>
<h3>{item.title}</h3>
<p>
{item.text}
</p>
</div>

While using this class:

public interface NewsTemplate extends XTemplates {
@XTemplate(source = "newstemplate.html")
SafeHtml render(NewsItem item);
}

Should work right? But no, it didn't. I copy/pasted the html code in the @XTemplate annotation as following:

public interface NewsTemplate extends XTemplates {
@XTemplate(value ="<div><p><h3>{item.title}</h3>{item.text}<tpl if='item.moar'><span style='float: right;'><a href=''>Read more</a></span></tpl></p></div>")
SafeHtml render(NewsItem item);
}

And it worked like it should, no problem there.
So I went back and forth trying to find out what I did wrong in the .html file.
While being spammed with (similar) errors from maven:

[INFO] [ERROR] Line 30: Failed to resolve 'x.mockup.client.view.NewsTemplate_rend
er_SafeHtml__NewsItem_item___SafeHtmlTemplates' via deferred binding
[INFO] [ERROR] Errors in 'C:\Data\Java\WorkspaceGWT\mockup\target\.generated\x\mockup
\client\view\NewsTemplate_render_SafeHtml__NewsItem_item___SafeHtmlTemplates.java'
[INFO] [ERROR] Line 7: The annotation @SafeHtmlTemplates.Template is disallowed for this loca
tion
[INFO] [ERROR] Line 7: String literal is not properly closed by a double-quote
[INFO] [ERROR] Line 8: span cannot be resolved to a type
...

I took a look at the generated file as indicated by Maven and received something like:

public interface NewsTemplate_render_SafeHtml__NewsItem_item___SafeHtmlTemplates extends com.google.gwt.safehtml.client.SafeHtmlTemplates {
@Template("<div><h3>{0}</h3><p>
\n {1}
\n </p></div>")
SafeHtml render0(java.lang.String arg0, java.lang.String arg1);
}

I was directly wondering what the '\n's did there.
So I stripped my html file to something like:

<div style="border: 1px solid black;">
<h3>{item.title}</h3>
<p>{item.text}</p>
</div>

and then it did work.
To finally come to a conclusion, it seems that you can't put any newlines between your tags or they'll be incorrectly parsed to '\n's, causing the template not to work.

Colin Alworth
15 Feb 2012, 10:06 AM
Thanks for this - we've seen one other report of this, and so far it seems specific to windows users, as on windows, newlines are typically /r/n, not just /n. Can you confirm that you are using Windows, or the developer who wrote that template was?

EthiC
16 Feb 2012, 12:55 AM
Yes, I'm using Windows

Colin Alworth
16 Feb 2012, 6:51 AM
Great, thanks - we'll update this thread when we have a fix.

Colin Alworth
16 Feb 2012, 1:11 PM
This fix is in SVN - \r\n newlines shouldn't affect XTemplates any longer.

WesleyMoy
2 Mar 2012, 5:07 PM
This fix should now be reflected in beta 4 (http://www.sencha.com/forum/showthread.php?184556-Ext-GWT-3.0-Beta-4-Now-Available). If you continue to notice any problems with line endings in XTemplate, post a message and I'll follow up with the team.