Sets any property value by dynamically specifying the property and value to update.

Class Name

atg.droplet.BeanProperty

Component

/atg/dynamo/droplet/BeanProperty

Required Input Parameters

bean

The target bean.

propertyName

The target property in bean. The value of this parameter is usually a page parameter that is already set to the desired property.

Optional Input Parameters

propertyValue

The value to set on the property specified by propertyName, either static text or a dynamic page parameter.

Output Parameters

propertyValue

The current value of the specified bean property.

Open Parameters

output

Lets you use the value in propertyValue for another operation, such as displaying it through the user interface or passing it to another bean.

Usage Notes

BeanProperty 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.

Use this bean 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. Use BeanProperty to collect 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:

  • bean

  • propertyName

  • propertyValue (output parameter)

  • output

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

  • bean

  • propertyName

  • propertyValue (input parameter)

Examples

Getting property values

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. The following 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>
Setting properties

A Web site that sells music wants 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; you also want to store that genre name and browsing status in a user’s Profile component property. To do this, you create a Map Profile property genresBrowsed that has a genre set to true if it was browsed. BeanProperty updates Profile.genresBrowsed Map as follows:

<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>