ClassName

atg.droplet.BeanProperty

Component

/atg/dynamo/droplet/BeanProperty

The BeanProperty servlet bean provides the ability to get or set a property value without knowing in advance which property you are dealing with. Although this servlet bean makes both set and get methods available, it is typically used to get current property values.

You should use this bean when you want to display a series of property values that a user defines. Because you do not know which properties the user might, your code must parse through the user choices (using a ForEach droplet, for example) and display the value of each property. You can use BeanProperty to collect the user-defined properties and process them through the ForEach bean as an element page parameter.

To use BeanProperty to get a property value, you might need to define these parameters:

To use BeanProperty to set a property value, you define the following parameters:

Input Parameters

bean
Specifies the bean with the properties to get or set.

propertyName
This parameter identifies the property you want to get or set. The value of this parameter is usually a page parameter defined and set in a previous operation to point to a property or direct reference to a property.

propertyValue
This parameter sets a new value to the property located through the propertyName parameter. The propertyValue parameter can use static text or a dynamic page parameter.

Output Parameter

propertyValue
This parameter accesses the current property value for a specified bean property.

Open Parameter

output
This parameter provides an opportunity to use the property value represented by propertyValue for another operation, such as displaying it through the user interface or passing it to another bean.

Get Example

Consider a situation where you want to allow users to compare the properties of two products. The users need to select which products and which properties they want to view. Assume a user specified one product and its properties, which were saved to the myProductBean and compareProperties page parameters respectively. This example shows how to code the ATG platform to render one product’s properties on a page:

<dsp:droplet name="/atg/dynamo/droplet/BeanProperty">
   <dsp:param name="bean" param="myProductBean"/>
   <dsp:param name="propertyName" value="compareProperties"/>
   <dsp:oparam name="output">
     These are the product characteristics you wanted to see:
     <p><dsp:valueof param="propertyValue">No characteristics have been
     specified</dsp:valuof>
   </dsp:oparam>
</dsp:droplet>

In this example, the ATG platform determines the selected product using myProductBean and properties using compareProperties and displays the properties values after the text Here are the product characteristics you wanted to compare.

In order to display the properties values in a specified order, add a ForEach bean. The following code alphabetizes the properties values and displays the first five.

<dsp:droplet name="/atg/dynamo/droplet/ForEach">
  <dsp:param name="array" param="compareProperties"/>
  <dsp:param name="count" value="5"/>
  <dsp:param name="sortProperties" value="+"/>

  <dsp:oparam name="outputStart">
    Here are the properties you asked about:<br/>
  </dsp:oparam>

  <dsp:oparam name="output">
    <dsp:droplet name="/atg/dynamo/droplet/BeanProperty">
      <dsp:param name="bean" param="myProductBean"/>
      <dsp:param name="propertyName" param="element"/>
      <dsp:oparam name="output">
        <dsp:valueof param="propertyName"/>: <dsp:valueof
        param="propertyValue">not set</dsp:valueof><br/>
      </dsp:oparam>
    </dsp:droplet>
  </dsp:oparam>

  <dsp:oparam name="empty">
    You did not select any properties to display.
  </dsp:oparam>
</dsp:droplet>
Set Example

Given a Web site that sells music, you want to keep track of the genres that interest users. When a user browses a music page, that page’s musical genre is temporarily saved to the currentGenre parameter, but you also want to store that genre name and browsing status in a property associated with that user’s Profile component. To do this, you create a Map Profile property genresBrowsed that, for every genre, indicates with a true setting whether it was browsed. You can use BeanProperty to update Profile.genresBrowsed Map by:

<dsp:droplet name="/atg/dynamo/BeanProperty">
    <dsp:param bean="Profile.genresBrowsed" name="bean"/>
    <dsp:param name="propertyName" param="genre"/>
    <dsp:param name="propertyValue" value="true"/>
</dsp:droplet>
 
loading table of contents...