Home DevShare Deploying BIRT Reports

Removing Blank Line in Multi-select Cascading Parameters

Share

by georgeh12

Contributor Contest - 1 winLeaderboard - 1 timeForum - 10 postsDevShare - 1 post
Posted 04 Jun 2012 - 04:31 PM

(0)  (0)   (834 views)

Correcting the common issue of the combo box parameter displaying a blank option.

Birt Version:-2.6

I realize the title appears to be extremely specific, but this is a common request by my clients. I strongly recommend patching this on your BIRT server, as it will take less than 10 minutes. (I promise!) I have not started using BIRT 3.7.2, but I assume most of this code remains unchanged.

The issue is that the combo box parameter displays a blank option.

BIRT Combo Box Parameter displays blank option

The error message resulting from selecting such an ominous blank space seems to freak out customers more than not. More frequently this message appears when a user attempts to select all parameter values from the list, resulting in even more confusion.

BIRT Combo Box error message

But do not fear! These parameter pages may not be manipulated by the .rptdesign file, but there are webpages that render the parameter window. A solution is afoot. First off, we want to locate the JSP that renders the cascading parameter object. If no default value is found, the cascading parameter box should not be populated with a blank line. Find your relative path from here: [C:/BIRT-2.6.1]/plugins/org.eclipse.birt.report.viewer_2.6.1.v20100913/birt/webcontent/birt/pages/parameter/ComboBoxParameterFragment.jsp

        if( !parameterBean.isRequired( ) || ( parameterBean.isCascade( ) && DataUtil.trimString( defaultValue ).length( )<=0 ) )
        {
            if( allowMultiValue && DataUtil.contain( values, "", true ) )
            {
%>
        <OPTION SELECTED></OPTION>
<%             
            }
            else
            {
%>
        <OPTION></OPTION>
<%
            }
        }

Aha! I see the problem right here:

if( !parameterBean.isRequired( ) || ( parameterBean.isCascade( ) && DataUtil.trimString( defaultValue ).length( )<=0 ) )

This does not check whether the cascading parameter is required. Required parameters will not accept a blank line anyway, so let's tweak this a bit.

if( !parameterBean.isRequired( ) )

Done!

BIRT Combo Box does not display blank option

Wow, that was easy! I wonder why it took so long to figure out such a simp-- now hold on just a minute. When the first parameter is changed, the solution crashes and we are back to square one. At this point, I was stumped.

BIRT Combo Box revenge of the blank option

...and whenever there is an HTML glitch, I always turn to Firebug. The error has to be caused by JavaScript, but using the console we can narrow this problem even further.

BIRT Combo Box debugging with Firebug

An AJAX request is being POSTed at the same time our error is occurring. This needs to be investigated. The POST request is handled by the following file: [C:/BIRT-2.6.1]/plugins/org.eclipse.birt.report.viewer_2.6.1.v20100913/birt/webcontent/birt/ajax/ui/dialog/AbstractParameterDialog.js

    /**
     *    Binding data to the dialog UI. Data includes zoom scaling factor.
     *    @data, data DOM tree (schema TBD)
     *    @return, void
     */
    __propogateCascadeParameter : function( data )
    {
        if ( this.__operationCancelled )
        {
            return;
        }

        if( data )
        {
            var cascade_param = data.getElementsByTagName( 'CascadeParameter' )[0];//assume there is only one cascadeparameter
            var selectionLists = data.getElementsByTagName( 'SelectionList' );
            if ( !selectionLists )
            {
                return;
            }

            for ( var k = 0; k < selectionLists.length; k++ )
            {
                var param_name = selectionLists[k].getElementsByTagName( 'Name' )[0].firstChild.data;
                var selections = selectionLists[k].getElementsByTagName( 'Selections' );

                var append_selection = document.getElementById( param_name + "_selection" );
                append_selection.title = "";
                var len = append_selection.options.length;

                // Clear our selection list.
                for( var i = 0, index = 0; i < len; i++ )
                {
                    /*
                    if ( append_selection.options[index].value == "" )
                    {
                        index++;
                        continue;
                    }
                    */
                    append_selection.remove( index );
                }

                // Add new options based on server response.
                for( var i = 0; i < selections.length; i++ )
                {
                    if ( !selections[i].firstChild )
                    {
                        continue;
                    }

                    var oOption = document.createElement( "OPTION" );
                    var oLabel = selections[i].getElementsByTagName( 'Label' )
                    if ( oLabel && oLabel.length > 0 )
                    {
                        oLabel = oLabel[0].firstChild;
                    }
                    if( oLabel )
                        oOption.text = oLabel.data;
                    else
                        oOption.text = "";

                    var oValue = selections[i].getElementsByTagName( 'Value' );
                    if ( oValue && oValue.length > 0 )
                    {
                        oValue = oValue[0].firstChild;
                    }
                    if( oValue )
                        oOption.value = oValue.data;
                    else
                        oOption.value = "";

                    append_selection.options[append_selection.options.length] = oOption;
                }
            }
        }
    },

Here is where the cascading parameter options are added in response to the AJAX request. By manipulating the last line here, we will be able to remove that silly blank option from being returned by the server.

append_selection.options[append_selection.options.length] = oOption;

And the much awaited solution:

if( !( append_selection.type == 'select-multiple' && i == 0 ) ) //Removes the first blank in multiple-select cascading parameters
append_selection.options[append_selection.options.length] = oOption;

Ha! We defeated that bug in just one line, and even commented the code. Here is a look at the fixed parameter dialog:

BIRT Combo Box bug fixed


Forum - 1 post

AnnaB

Posted: 10 May 2013 - 01:34 AM

Hi! Thanks for posting this. I'd like to remove the blank line for a non-required, non-multi-valued cascading parameter - basically make it behave like any other non-required parameter, eg. defaulting to null. Have you figured that out as well?

Contributor Contest - 1 winLeaderboard - 1 timeForum - 10 postsDevShare - 1 post

georgeh12

Posted: 10 May 2013 - 01:46 PM

In ComboBoxParameterFragment.jsp, remove the entire section that adds blank options: if( !parameterBean.isRequired( ) || ( parameterBean.isCascade( )

Contributor Contest - 1 winLeaderboard - 1 timeForum - 10 postsDevShare - 1 post

georgeh12

Posted: 10 May 2013 - 02:01 PM

In AbstractParameterDialog.js, change the comparison statement append_selection.type == 'select-multiple' to append_selection.className == 'birtviewer_parameter_dialog_Select'
 
Filter More