Hi,

     Our prepopulation works like this.

        protected void prepopulate( HttpServletRequest request, String name
){
                ReportForm form = null;
                form = ( ReportForm )request.getSession().getAttribute(
"reportForm" );
                if( form == null) {
                        form = new ReportForm();
                        setSelectedOptions( request, name, form );
                request.getSession().setAttribute( "reportForm", form );
                } else {
                        setSelectedOptions( request, name, form );
                }
        }

        /* Should be actually some type of direct copy or something */
        protected void setSelectedOptions( HttpServletRequest request,
                                              String name,
                                              ReportForm form ){
                LabelValueBean bean =
                ( LabelValueBean )((( ArrayList )request.getSession().
        
getAttribute( name )).get( 0 ));
                ArrayList preselectedFilter = new ArrayList();
        preselectedFilter.add( bean.getValue() );
            logger_.debug( "Setting the first value as [" + bean.getValue()
+
                                                        "," +
bean.getLabel() +       "] for " + name );
                if ( "applicationOptions".equals( name ) ) {
                        form.setApplications( ( String[] ) 
        
preselectedFilter.toArray( new String[0] ) );
                }
                else if ( "departmentOptions".equals( name ) ) {
                        form.setDepartments( ( String[] ) 
        
preselectedFilter.toArray( new String[0] ) );
                }
                else if ( "divisionOptions".equals( name ) ) {
                        form.setDivisions( ( String[] ) 
        
preselectedFilter.toArray( new String[0] ) );
                }
        }

Mohan
-----Original Message-----
From: Matt Smith [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 20, 2003 8:10 PM
To: Struts Users Mailing List (E-mail)
Subject: prepopulate a form with values


Can I instantiate a form, populate it with values and then place it in
request scope and have my jsp use that form to use those values as the
default.  ie if I have a Collection that I am displaying with an <options>
tag can I populate the form with the value that should be selected, place
the form on the request and have the tag select the appropriate option?

thanks in advance

Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to