/*************************************************************************************
 * Copyright (c) 2004 Actuate Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Actuate Corporation - Initial implementation.
 ************************************************************************************/

package org.eclipse.birt.report.presentation.aggregation.parameter;

import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.eclipse.birt.report.IBirtConstants;
import org.eclipse.birt.report.context.ScalarParameterBean;
import org.eclipse.birt.report.context.ViewerAttributeBean;
import org.eclipse.birt.report.model.api.util.ParameterValidationUtil;
import org.eclipse.birt.report.service.api.IViewerReportService;
import org.eclipse.birt.report.service.api.InputOptions;
import org.eclipse.birt.report.service.api.ParameterDefinition;
import org.eclipse.birt.report.service.api.ParameterSelectionChoice;
import org.eclipse.birt.report.service.api.ReportServiceException;
import org.eclipse.birt.report.utility.DataUtil;

/**
 * Fragment help rendering scalar parameter.
 * <p>
 * 
 * @see org.eclipse.birt.report.presentation.aggregation.BaseFragment
 */
public class RadioButtonParameterFragment extends ScalarParameterFragment
{

	/**
	 * Protected constructor.
	 * 
	 * @param parameter
	 *            parameter definition reference.
	 */
	public RadioButtonParameterFragment( ParameterDefinition parameter )
	{
		super( parameter );
	}

	protected void prepareParameterBean( HttpServletRequest request,
			IViewerReportService service, ScalarParameterBean parameterBean,
			Locale locale ) throws ReportServiceException
	{
		ViewerAttributeBean attrBean = (ViewerAttributeBean) request
				.getAttribute( IBirtConstants.ATTRIBUTE_BEAN );
		assert attrBean != null;

		InputOptions options = new InputOptions( );
		options.setOption( InputOptions.OPT_REQUEST, request );

		Collection selectionList = service.getParameterSelectionList( attrBean
				.getReportDesignHandle( request ), options, parameterBean
				.getName( ) );

		ParameterDefinition paramDef = parameterBean.getParameter( );
		if ( selectionList != null )
		{
			boolean isDisplayTextInList = false;
			for ( Iterator iter = selectionList.iterator( ); iter.hasNext( ); )
			{
				ParameterSelectionChoice selectionItem = (ParameterSelectionChoice) iter
						.next( );

				Object value = selectionItem.getValue( );
				try
				{
					// try convert value to parameter definition data type
					value = DataUtil.convert( value, paramDef.getDataType( ) );
				}
				catch ( Exception e )
				{
					value = null;
				}

				// Convert parameter value using standard format
				String displayValue = DataUtil.getDisplayValue( value );
				if ( displayValue == null )
					continue;

				String label = selectionItem.getLabel( );
				if ( label == null || label.length( ) <= 0 )
				{
					// If label is null or blank, then use the format parameter
					// value for display
					label = ParameterValidationUtil.getDisplayValue( null,
							paramDef.getPattern( ), value, locale );
				}

				if ( label == null )
					continue;

				selectionItem.setLabel( label );
				selectionItem.setValue( displayValue );
				parameterBean.getSelectionList( ).add( selectionItem );

				// check whether parameter display text is in the label list
				if ( !label.equals( parameterBean.getDisplayText( ) ) )
				{
					if ( parameterBean.getParameter( ).isDistinct( ) )
					{
						selectionItem
								.setLabel( parameterBean.getDisplayText( ) );
						isDisplayTextInList = true;
					}
				}
				else
				{
					isDisplayTextInList = true;
				}
			}

			// add new item
			if ( parameterBean.isDisplayTextInReq( ) && !isDisplayTextInList )
			{
				parameterBean.getSelectionList( )
						.add(
								new ParameterSelectionChoice( parameterBean
										.getDisplayText( ), parameterBean
										.getValue( ) ) );
				isDisplayTextInList = true;
			}
			
			parameterBean.setDisplayTextInList( true );
		}
	}
}
@@ -4293,20 +4293,35 @@
 InList( 
-true
+isDisplayTextInList
  );%0A%09%09%7D%0A

Fix Bugzilla Bug 191805