Dashboard > RIFE > ... > Templates > Filling out templates using beans
RIFE Log In | Sign Up   View a printable version of the current page.
Filling out templates using beans


Added by Steven Grimm, last edited by Geert Bevin on Jul 17, 2006  (view change)
Labels: 
(None)

The group of setBean methods makes it possible to fill out a lot of values in a template in one go. It simply matches the bean properties to template values, with an optional prefix.

Let's demonstrate this with the bean from the database chapter of the user's guide. The bean has properties for first and last name, a description and a URL. In the friends database chapter, we used setValue to set the properties from the Friend bean like this:

template.setValue("firstname", friend.getFirstname());
template.setValue("lastname", friend.getLastname());
template.setValue("description", friend.getDescription());
template.setValue("url", friend.getUrl());

Instead of calling setValue for each property, using setBean makes it possible to set all properties in one call:

template.setBean(friend);

This also gives makes it possible to add properties to a bean and template without having to edit the element backend code.

If there are several different beans used in the same template it's probably a good idea to prefix the various values to make it possible to easily see which bean a value belongs to. For example in the Friends database, we could prefix the value names with "FRIEND:". The interesting part of the template from Example 5-8 would then become:

<r:b name="row">
<tr valign="top">
  <td><r:v name="FRIEND:firstname"/></td>
  <td><r:v name="FRIEND:lastname"/></td>
  <td>
    <a xhref="${v FRIEND:url/}">
      <r:v name="FRIEND:description"/>
    </a>
  </td>
</tr>
</r:b>

The setBean method takes an optional prefix argument. Calling setBean with a prefix of "FRIEND:" will make the engine set the template value "FRIEND:firstname" to the value of the "firstname" bean property.



Are you enjoying Confluence? Please consider purchasing it today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.1a Build:#515 May 19, 2006) - Bug/feature request - Contact Administrators