File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Define tag cannot set a null value for bean with id: medList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Define tag cannot set a null value for bean with id: medList"" Watch "Define tag cannot set a null value for bean with id: medList"" New topic
Author

Define tag cannot set a null value for bean with id: medList"

sudha javvadi
Ranch Hand

Joined: Mar 23, 2007
Posts: 97
Hi all,

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.

Medium.jsp:<html:form action="Medium">
<html:select name="MediumForm" property="med" >

<bean:define name="MediumForm" property="medList" id="medList" />
<htmlptions collection="medList" property="medId" labelProperty="medName" />
</html:select>
</html:form>

MediumForm.javaprivate List medList;
private String med; //getters and setters for medList and med.

MediumBean.javaint medId;
String medName; //getters and setters for medId and medName.

MediumAction.java
MediumDao mdao= new MediumDao();
List medList= new ArrayList();
medList = MediumDao.getMediums();
if (medList==null)
{
System.out.println("List is null");
}
MediumForm mform= (MediumForm)form;
mform.setMedList(medList);
String med = mform.getMed();
return mapping.findForward("success");

MediumDao.java
public static List getMediums()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbcdbc:charan","scott","tiger");
//conn = getConnection();

String sql = " select * from MEDIUM ";
pStmt = conn.prepareStatement(sql);

rs = pStmt.executeQuery();
while(rs.next()){
MediumBean med = new MediumBean();
med.setMedId(rs.getInt("MED_ID"));
med.setMedName(rs.getString("MEDIUM_NAME"));
medList.add(med);
}
conn.close();
pStmt.close();
rs.close();

}

catch(Exception e){
e.printStackTrace();

}
return medList;

}
Thanks,
Sudha.
SCJP1.5
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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.

sudha javvadi
Ranch Hand

Joined: Mar 23, 2007
Posts: 97
Hi James,
Thank you for your reply. My struts-config.xml is like this:

<form-bean name="MediumForm" type="actions.MediumForm" />
<action path="/Medium"
type="actions.MediumAction"
name="MediumForm"
scope="session"
input="/pages/Medium.jsp">
<forward name="success" path="/pages/Medium.jsp" />
</action>
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??

thanks,
Sudha.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187

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)


<action path="/Medium"
type="actions.MediumAction"
name="MediumForm"
scope="session"
input="/pages/Medium.jsp">
<forward name="success" path="/pages/MediumResult.jsp" />
</action>
sudha javvadi
Ranch Hand

Joined: Mar 23, 2007
Posts: 97
Hi James,

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:errors />
<html:form action="Medium">
<html:select name="MediumForm" property="med" >


<htmlptions collection="medList" property="medId" labelProperty="medName" />
</html:select>
</html:form>
Thanks,
sudha.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Define tag cannot set a null value for bean with id: medList"
 
Similar Threads
html:select html:options error, no getter. please help
html:select error occuring
Pre-select collection of options (drop-downs)
html:select problem
html:select html:options