freemarker not able to render a Javabean inside javabean

3 messages Options
Embed this post
Permalink
ganu05

freemarker not able to render a Javabean inside javabean

Reply Threaded More More options
Print post
Permalink
Hi,


I have a EmployeeDTO class with a getter, setter for AddressDTO class where AddressDTO class contains a list of addresses.

when i am trying to display the Employee address information i am getting an exception. please help!
My code goes like this:

  class EmployeeDTO{

      private AddressDTO addressDTO;

 getAddressDTO() {...}
setAddressDTO(){....}

and other fields goes here...
}
class AddressDTO{

      private List<String> addresses;

 getAddresses() {...}
setAddresses(){....}

and other fields goes here...
}


struts action class:

class MyAction extends Action{
       
    public ActionForward execute(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest req,
            HttpServletResponse resp) throws Exception {
   
// getting employee info from DB
    req.setAttribute("employeeDTO", employeeDTO);
}

template code:

<table>
<tr><td>${employeeDTO.name}<td></tr>
<#list employeeDTO.addressDTO.addresses as address>
<tr><td>${address}<td></tr>
</#list>
</table>


Page is printing Employee Name but giving following exception:

Expression employeeDTO.addressDTO is undefined on line 15, column 19 in Employee.ftl.
The problematic instruction:
----------
==> ${employeeDTO.addressDTO.addresses} [on line 15, column 17 in Employee.ftl]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression employeeDTO.addressDTO is undefined on line 15, column 19 in Employee.ftl.
        at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)


please help!!!!!!!
Guo Du

Re: freemarker not able to render a Javabean inside javabean

Reply Threaded More More options
Print post
Permalink
On Mon, Oct 19, 2009 at 2:10 PM, ganu05 <[hidden email]> wrote:

> freemarker.core.InvalidReferenceException: Expression employeeDTO.addressDTO
> is undefined on line 15, column 19 in Employee.ftl.
>        at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)

You will see this error if employeeDTO.addressDTO is null.

-Guo

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
ganu05

Re: freemarker not able to render a Javabean inside javabean

Reply Threaded More More options
Print post
Permalink
In reply to this post by ganu05
Thanks it worked.. for employees addressDTO was null..


ganu05 wrote:
Hi,


I have a EmployeeDTO class with a getter, setter for AddressDTO class where AddressDTO class contains a list of addresses.

when i am trying to display the Employee address information i am getting an exception. please help!
My code goes like this:

  class EmployeeDTO{

      private AddressDTO addressDTO;

 getAddressDTO() {...}
setAddressDTO(){....}

and other fields goes here...
}
class AddressDTO{

      private List<String> addresses;

 getAddresses() {...}
setAddresses(){....}

and other fields goes here...
}


struts action class:

class MyAction extends Action{
       
    public ActionForward execute(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest req,
            HttpServletResponse resp) throws Exception {
   
// getting employee info from DB
    req.setAttribute("employeeDTO", employeeDTO);
}

template code:

<table>
<tr><td>${employeeDTO.name}<td></tr>
<#list employeeDTO.addressDTO.addresses as address>
<tr><td>${address}<td></tr>
</#list>
</table>


Page is printing Employee Name but giving following exception:

Expression employeeDTO.addressDTO is undefined on line 15, column 19 in Employee.ftl.
The problematic instruction:
----------
==> ${employeeDTO.addressDTO.addresses} [on line 15, column 17 in Employee.ftl]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression employeeDTO.addressDTO is undefined on line 15, column 19 in Employee.ftl.
        at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)


please help!!!!!!!