private void populateElements( Map data, Object target, List elements, String formId )
throws TargetPopulationException
{
for ( Iterator i = elements.iterator(); i.hasNext(); )
{
Element element = (Element) i.next();
String id = element.getId();
Object elementData = data.get( id );
// ----------------------------------------------------------------------
// Populate the default value if our data for the element is null and
// there is a default value available.
// ----------------------------------------------------------------------
if ( elementData == null && element.getDefaultValue() != null )
{
elementData = element.getDefaultValue();
}
// OGNL interprets the string literal "false" as true because it's non-null
if ( elementData instanceof String )
{
String s = (String) elementData;
//TODO: we need to check element.type
if ( s.equals( "false" ) || s.equals( "off" ) || s.equals( "0" ) )
{
elementData = Boolean.FALSE;
}
else if ( s.equals( "true" ) || s.equals( "on" ) || s.equals( "1" ) )
{
elementData = Boolean.TRUE;
}
}
if ( elementData != null )
{
String expression = element.getExpression();
if ( expression == null )
{
throw new TargetPopulationException( "Expression for " + element.getId() + " in " + formId + " cannot be null." );
}
try
{
Ognl.setValue( expression, data, target, elementData );