Iam getting an error:"Define tag cannot set a null value for bean with id: medList". I think I didn't understand what the id is.I tried googling but couldn't figure it out.please guide me. My jsp is as follows.
MediumForm.javaprivate List medList;
private String med; //getters and setters for medList and med.
String medName; //getters and setters for medId and medName.
MediumAction.java MediumDao mdao= new MediumDao();
List medList= new ArrayList();
medList = MediumDao.getMediums();
System.out.println("List is null");
MediumForm mform= (MediumForm)form;
String med = mform.getMed();
MediumDao.java public static List getMediums()
//conn = getConnection();
String sql = " select * from MEDIUM ";
pStmt = conn.prepareStatement(sql);
rs = pStmt.executeQuery();
MediumBean med = new MediumBean();
The Medium JSP page must be called after the Medium action executes.
The MediumForm is associated with the action and the JSP page by the configuration specified in the struts-config.xml file. So, the define element is not required on this page, i.e. the form is already in scope if you configured the action class correctly.
The id attribute of the define element enables you to identify the bean in other elements on the page. But, the define element shouldn't be on the page anyway, so it really doesn't mattter much.
Joined: Mar 23, 2007
Thank you for your reply. My struts-config.xml is like this:
<form-bean name="MediumForm" type="actions.MediumForm" />
<forward name="success" path="/pages/Medium.jsp" />
I removed the define element but Iam getting some other error:"cannot find bean with name medList". How to start MediumAction without starting from a Medium.jsp? In the MediumAction Iam forwarding to Medium.jsp. Any suggestions to run this program successfully??
Joined: Apr 16, 2008
Post a copy of the revised Medium.jsp file.
How to start MediumAction without starting from a Medium.jsp?
Create a file index.jsp. And in this file, have the following element
In the MediumAction I am forwarding to Medium.jsp.
Change the action configuration to forward to a different page (for now)
As you told I created an index.jsp file and an MediumResult.jsp file. When I click on the link "Go to Medium.jsp" it is redirecting to MediumResult.jsp, but if I replace MediumResult with Medium.jsp then Iam getting error : "Cannot fine bean under name medList. what might going wrong?? what should I put in the collection attribute. was it a bean name or the arraylist?? In my case Iam returning medList to Action class and I set the attribute of formbean with that list. what iam expecting is when I forward to Medium.jsp after success in action it should populate with the list. Please help me .
Also the revised of Medium.jsp is as follows. I just removed the define element.
<h1> Medium Form </h1>
<html:select name="MediumForm" property="med" >