Re: (no subject)
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.devel |
|---|---|
| Message-ID | <[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/