You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Villegas, Courtney" <Vi...@tri-met.org> on 2002/05/01 02:09:12 UTC

Struts bean usage

I have a jsp page and am trying to add text created by a form bean.  I am
using <bean:define id="reports" name="reportsForm"
type="java.util.Collection"/> to define the bean and <bean:write
name="reports" property="report[7].reportID"/> to write the desired
information.  

I am getting the error "Cannot find bean reportsForm in scope null"

Am I referencing my bean incorrectly?

I have appended the form bean that I am using.

Thanks
Courtney

package com.trimet.gis.buds.forms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import java.util.*;
import com.trimet.gis.buds.states.Report;
import java.lang.reflect.Array;
import java.util.Vector;

/**
 * Form bean for the Reports page.  This form has the following fields,
 * with default values in square brackets:
 *
 * @author Courtney Villegas
 * @version $Revision: 1.0 $ $Date: 2002/04/24 4:34:00 $
 */

public class ReportsForm extends ActionForm  {


    // --------------------------------------------------- Instance
Variables
    /**
     * The maintenance action we are performing (Create or Edit).
     */
    private String action = "Load";

    /**
     * Should we auto-connect at startup time?
     */
    private boolean autoConnect = false;

    // Reports collection
    private Collection reports = null;

    //Group report ID
    private Integer groupReportId = null;

    // Selected ReportId
    private Integer reportId = null;

    // -----------------------------------------------------------
Properties
    public String getAction() {
	return (this.action);
    }
    public void setAction(String action) {
        this.action = action;
    }

    public boolean getAutoConnect() {
        return (this.autoConnect);
    }

    public void setAutoConnect(boolean autoConnect) {
        this.autoConnect = autoConnect;
    }

    public void setReports(Integer groupReportId) {
    	this.groupReportId=groupReportId;
    }

    public Integer getGroupReportId() {
    	return (this.groupReportId);
    }

    public void setReportId(Integer reportId) {
    	this.reportId = reportId;
    }

    public Collection getReports() {
        reports = (Collection) new ArrayList();

        //Hardcoded data for now... should be populated from db
        Report[] report= new Report[9];

        report[0] = new Report(1);
        report[0].setReportName("on-time performance by individual trip");
        reports.add(report[0]);

        report[1] = new Report(2);
        report[1].setReportName("on-time performance by route (all trips)");
        reports.add(report[1]);

        report[2] = new Report(3);
        report[2].setReportName("ridership by individual trip ");
        reports.add(report[2]);

        report[3] = new Report(4);
        report[3].setReportName("ridership by route (all trips)");
        reports.add(report[3]);

        report[4] = new Report(5);
        report[4].setReportName("passenger census");
        reports.add(report[4]);

        report[5] = new Report(6);
        report[5].setReportName("service events by train, by route and/or by
supervisory district");
        reports.add(report[5]);

        report[6] = new Report(7);
        report[6].setReportName("run times by time point segment and date");
        reports.add(report[6]);

        report[7] = new Report(8);
        report[7].setReportName("passenger census");
        reports.add(report[7]);

        report[8] = new Report(9);
        report[8].setReportName("service events");
        reports.add(report[8]);

        return reports;
    }


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Struts bean usage

Posted by Alex Paransky <ap...@standardset.com>.
Well, the documentation of the define tag states:

"
Retrieve the value of a specified bean property, and define it as an
attribute (in the scope specified by the toScope property) accessible to the
remainder of the current page
"

So, the bean "reportsForm" must already be present in the scope at the time
you are performing your define.  Who creates/populates the reportsForm bean
in the first place?  To make your code work, you may want to use jsp:useBean
to create a new bean in the scope that you desire, however, you will still
need to do something to populate it (a loadReports.do action that forwards
to the proper .jsp page perhaps).

-AP_
http://www.alexparansky.com
Java/J2EE Architect/Consultant
http://www.myprofiles.com/member/profile/apara_personal

-----Original Message-----
From: Villegas, Courtney [mailto:VillegaC@tri-met.org]
Sent: Tuesday, April 30, 2002 5:09 PM
To: 'Struts Users Mailing List'
Subject: Struts bean usage


I have a jsp page and am trying to add text created by a form bean.  I am
using <bean:define id="reports" name="reportsForm"
type="java.util.Collection"/> to define the bean and <bean:write
name="reports" property="report[7].reportID"/> to write the desired
information.

I am getting the error "Cannot find bean reportsForm in scope null"

Am I referencing my bean incorrectly?

I have appended the form bean that I am using.

Thanks
Courtney

package com.trimet.gis.buds.forms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import java.util.*;
import com.trimet.gis.buds.states.Report;
import java.lang.reflect.Array;
import java.util.Vector;

/**
 * Form bean for the Reports page.  This form has the following fields,
 * with default values in square brackets:
 *
 * @author Courtney Villegas
 * @version $Revision: 1.0 $ $Date: 2002/04/24 4:34:00 $
 */

public class ReportsForm extends ActionForm  {


    // --------------------------------------------------- Instance
Variables
    /**
     * The maintenance action we are performing (Create or Edit).
     */
    private String action = "Load";

    /**
     * Should we auto-connect at startup time?
     */
    private boolean autoConnect = false;

    // Reports collection
    private Collection reports = null;

    //Group report ID
    private Integer groupReportId = null;

    // Selected ReportId
    private Integer reportId = null;

    // -----------------------------------------------------------
Properties
    public String getAction() {
	return (this.action);
    }
    public void setAction(String action) {
        this.action = action;
    }

    public boolean getAutoConnect() {
        return (this.autoConnect);
    }

    public void setAutoConnect(boolean autoConnect) {
        this.autoConnect = autoConnect;
    }

    public void setReports(Integer groupReportId) {
    	this.groupReportId=groupReportId;
    }

    public Integer getGroupReportId() {
    	return (this.groupReportId);
    }

    public void setReportId(Integer reportId) {
    	this.reportId = reportId;
    }

    public Collection getReports() {
        reports = (Collection) new ArrayList();

        //Hardcoded data for now... should be populated from db
        Report[] report= new Report[9];

        report[0] = new Report(1);
        report[0].setReportName("on-time performance by individual trip");
        reports.add(report[0]);

        report[1] = new Report(2);
        report[1].setReportName("on-time performance by route (all trips)");
        reports.add(report[1]);

        report[2] = new Report(3);
        report[2].setReportName("ridership by individual trip ");
        reports.add(report[2]);

        report[3] = new Report(4);
        report[3].setReportName("ridership by route (all trips)");
        reports.add(report[3]);

        report[4] = new Report(5);
        report[4].setReportName("passenger census");
        reports.add(report[4]);

        report[5] = new Report(6);
        report[5].setReportName("service events by train, by route and/or by
supervisory district");
        reports.add(report[5]);

        report[6] = new Report(7);
        report[6].setReportName("run times by time point segment and date");
        reports.add(report[6]);

        report[7] = new Report(8);
        report[7].setReportName("passenger census");
        reports.add(report[7]);

        report[8] = new Report(9);
        report[8].setReportName("service events");
        reports.add(report[8]);

        return reports;
    }


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>