Re: (no subject)
Nancy Wang <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.devel |
|---|---|
| Message-ID | <CACZZE-uN8RrA253uGD3Hw9p3wtr0=YtuMYWSFdg0X_+LLkuKhg@mail.gmail.com> |
Hi, Daniel,
Thank you very much for your quick response! I tried user?keys
<table>
<tr>
<#assign keys = user?keys>
<#list keys as key>
<#if key != "class" && key != "getClass" && key != "toString" && key !=
"equals" && key != "hashCode" && !key?starts_with("get") &&
!key?starts_with("set") >
<td>${key}</td>
</#if>
</#list>
</tr>
</table>
Now I couldn't get the key's value. I tried user[key], user.get(key), none
of them work. You advice is highly appreciated!
Thanks and best regards,
Nancy
---------- Forwarded message ----------
From: Daniel Dekany <[email protected]>
Date: Thu, Feb 23, 2012 at 1:26 AM
Subject: Re: [Freemarker-devel] (no subject)
To: FreeMarker-devel <[email protected]>
Unfortunately you can't do that out-of-the-box. Some may say that you
should use user?keys, but that will return not only the property names
but the method names too. But you could write a TemplatMethodModelEx
(that's like a #function only it's implemented in Java) that tries to get
the non-wrapped Java object with
((AdapterTemplateModel) arg).getAdaptedObject(Object.class)
then gets the property names with the java.beans API-s, builds a
freemarker.template.SimpleSequence based on what it sees, and returns
it. So you create a such TemplatMethodModelEx, let's call it
com.example.GetPropertyNamesMethod, and then put it into an #import-ed
ftl where you have
<#assign getPropertyNames = "com.example.GetPropertyNamesMethod"?new()>.
--
Best regards,
Daniel Dekany
Wednesday, February 22, 2012, 10:53:40 PM, Nancy Wang wrote:
> Hi, all,
>
> I have a ftl file, would like to know if there is a generic way to
> show all field values of a user and all field names (suppose I
> don't know what fields are there in User bean)
>
> ftl file
> <table>
> <tr>
> <td>${user.firstName}</td>
> <td>${user.lastName}</td>
> <td>${user.dob}</td>
> <td>${user.dep}</td>
> </tr>
> </table>
>
>
> java file
> Map root = new HashMap();
> User user = new User();
> user.setFirstName("Byrant");
> user.setLastName("Johnson");
> user.setDob("19800920");
> user.setDep("HR");
>
> root.put("user", user);
>
> User bean
> private String firstName;
> private String lastName;
> private String dob;
> private String dep;
> public String getFirstName()
>
> .....................
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
FreeMarker-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
FreeMarker-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel