Re: Display String array in FTL
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Monday, May 25, 2009, 10:53:17 AM, strutstwouser wrote:
> I looked at the PostalAddress object closer and find that in addition to the
> usual get/sets :
>
> public java.lang.String[] getAddressLine() {
> return addressLine;
> }
>
> and
>
> public void setAddressLine(java.lang.String[] addressLine) {
> this.addressLine = addressLine;
> }
>
> there are also methods like :
>
> public java.lang.String getAddressLine(int i) {
> return addressLine[i];
> }
>
> and
>
> public void setAddressLine(int i, java.lang.String value) {
> addressLine[i] = value;
> }
>
> When i removed these additional get/sets, it worked fine.
>
> I've attached the stacktrace ;
> http://www.nabble.com/file/p23703551/stacktrace.txt stacktrace.txt the NPE
> is at the bottom. Sorry i initially thought that was the primary exception.
At the first glance looks like a FreeMarker bug to me... Could you
tell what ${.version} prints?
For Attila, the trace was:
freemarker.template.TemplateModelException: Method public java.lang.String com.xyz.domain.PostalAddress.getAddressLine(int) threw an exception when invoked on com.xyz.domain.PostalAddress@30da30da
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
[...]
Caused by: java.lang.NullPointerException
at freemarker.ext.beans.SimpleMemberModel.unwrapArguments(SimpleMemberModel.java:85)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
> Thanks,
> Joseph
>
>
>
>
>
> Daniel Dekany wrote:
>>
>> Wednesday, May 20, 2009, 6:57:16 PM, strutstwouser wrote:
>>
>>> Yes, the array has data.
>>
>> And even if it hadn't, it should be an InvalidReferenceException,
>> never an NPE. But your report missed the exception trace with
>> locations... it's hard to find out what caused the NPE this way.
>>
>>> I printed the same using Struts2 tag , like :
>>>
>>> <@s.property
>>> value="model.borrowers[0].party.legalAddress.addressLine[0]" />
>>>
>>> and it gives the value fine.
>>>
>>> The latest code i was trying was :
>>>
>>> <#if model.borrowers[0].party.legalAddress.addressLine?exists>
>>>
>>> <#assign addressLines =
>>> model.borrowers[0].party.legalAddress.addressLine>
>>>
>>> <#list addressLines as addressLine>
>>> AddressLine0->
>>> ${addressLine}
>>> </#list>
>>> </#if>
>>>
>>> This breaks with the error :
>>>
>>> freemarker.ext.servlet.ServletContextHashModel
>>> cause: freemarker.template.TemplateModelException: ?size is unsupported
>>> for: freemarker.ext.beans.SimpleMethodModel
>>
>> At which template line? In general, just include the whole stack trace
>> for all reports... maybe it's needless, but often it helps.
>>
>>>>> There shouldn't be. Are you 100% sure the array has a first item which
>>>>> is not Java null, etc.?
>>>>
>>>> Oh, and even if you have one of those, it should still throw
>>>> freemarker.core.InvalidReferenceException, not NPE. So... maybe the
>>>> problem is not exactly there, just around somewhere?
>>
>> --
>> Best regards,
>> Daniel Dekany
>>
>>
>> ------------------------------------------------------------------------------
>> Crystal Reports - New Free Runtime and 30 Day Trial
>> Check out the new simplified licensing option that enables
>> unlimited royalty-free distribution of the report engine
>> for externally facing server and web deployment.
>> http://p.sf.net/sfu/businessobjects
>> _______________________________________________
>> FreeMarker-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>>
>>
>
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com