*
The moose likes Struts and the fly likes bean cannot be found in any scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean cannot be found in any scope" Watch "bean cannot be found in any scope" New topic
Author

bean cannot be found in any scope

utkarsh sinha
Greenhorn

Joined: Oct 12, 2007
Posts: 5
Hi all,
Past few days i am trying to run my application bt it give the following error bean cannot be found in any scope.I have declared the bean in struts-config.xml.Please help.I am Pasting relevant peices of my code::

Struts-config.xml

<form-beans>
<form-bean name="TwoForm" type="TwoForm"/>
<form-bean name="loginForm" type="LoginForm"/>

</form-beans>
<global-exceptions/>
<global-forwards>
<forward name="login" path="/login.jsp"/>
</global-forwards>
<action-mappings>
<action input="/login.jsp" name="loginForm" path="/Login"
scope="session" type="LoginAction" validate="true">
<forward name="success" path="/employeelist.jsp"/>
</action>
<action input="/employeelist.jsp" name="twoForm" path="/Two"
scope="request" type="TwoAction">
<forward name="success" path="/report1.jsp"/>
</action>
</action-mappings>

TwoForm.java

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
@SuppressWarnings("serial")
public class TwoForm extends ActionForm {

private String Reqid;
private String Acti;
private String startdate;
private String hours;
private String minutes;
private String comments;
private List TwList;
private String step;
public TwoForm() {
Acti = "";
Reqid = "";
startdate="";
hours="";
minutes="";
comments="";
}
public String getReqid() {
return Reqid;
}
public void setReqid(String Reqid) {
this.Reqid = Reqid;
}
public String getActi() {
return Acti;
}

public void setActi(String Acti) {
this.Acti = Acti;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.Reqid = "";
this.Acti = "";
}
public String getStartdate() {
return startdate;
}
public void setStartdate(String startdate) {
this.startdate = startdate;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public String getMinutes() {
return minutes;
}
public void setMinutes(String minutes) {
this.minutes = minutes;
}
public String getStep() {
return step;
}

public void setStep(String string) {
step = string;
}
@SuppressWarnings("unchecked")
public void settwoFormObj(int index, Two empObj) {
TwList.set(index, empObj);
}

@SuppressWarnings("unchecked")



public List getTwList() {
return TwList;
}

public void setTwList(List TwList) {
this.TwList = TwList;
}
@SuppressWarnings("unchecked")
public Two getTwo(int index)
{
// make sure that cusList is not null
if(this.TwList == null)
{
this.TwList = new ArrayList();
}

// indexes do not come in cus, populate empty spots
while(index >= this.TwList.size())
{
this.TwList.add(new Two());
}

// return the requested item
return (Two) TwList.get(index);

}

}

TwoAction.java

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
@SuppressWarnings("serial")
public class TwoForm extends ActionForm {

private String Reqid;
private String Acti;
private String startdate;
private String hours;
private String minutes;
private String comments;
private List TwList;
private String step;
public TwoForm() {
Acti = "";
Reqid = "";
startdate="";
hours="";
minutes="";
comments="";
}
public String getReqid() {
return Reqid;
}
public void setReqid(String Reqid) {
this.Reqid = Reqid;
}
public String getActi() {
return Acti;
}

public void setActi(String Acti) {
this.Acti = Acti;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.Reqid = "";
this.Acti = "";
}
public String getStartdate() {
return startdate;
}
public void setStartdate(String startdate) {
this.startdate = startdate;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public String getMinutes() {
return minutes;
}
public void setMinutes(String minutes) {
this.minutes = minutes;
}
public String getStep() {
return step;
}

public void setStep(String string) {
step = string;
}
@SuppressWarnings("unchecked")
public void settwoFormObj(int index, Two empObj) {
TwList.set(index, empObj);
}

@SuppressWarnings("unchecked")



public List getTwList() {
return TwList;
}

public void setTwList(List TwList) {
this.TwList = TwList;
}
@SuppressWarnings("unchecked")
public Two getTwo(int index)
{
// make sure that cusList is not null
if(this.TwList == null)
{
this.TwList = new ArrayList();
}

// indexes do not come in cus, populate empty spots
while(index >= this.TwList.size())
{
this.TwList.add(new Two());
}

// return the requested item
return (Two) TwList.get(index);

}

}

Two.java


public class Two {

private String Reqid;
private String Acti;
private String startdate;
private String hours;
private String minutes;
private String comments;

public String getReqid() {
return Reqid;
}
public void setReqid(String Reqid) {
this.Reqid = Reqid;
}
public String getActi() {
return Acti;
}
public void setActi(String Acti) {
this.Acti = Acti;
}
public String getStartdate() {
return startdate;
}
public void setStartdate(String startdate) {
this.startdate = startdate;
}
public String getComments() {
return comments;
}
public void setComments(String comments) {
this.comments = comments;
}
public String getHours() {
return hours;
}
public void setHours(String hours) {
this.hours = hours;
}
public String getMinutes() {
return minutes;
}
public void setMinutes(String minutes) {
this.minutes = minutes;
}
}

The most imp jsp page which displays the result(report1.jsp)

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html xhtml="true">

<head>
<title><bean:message key="app.title" /></title>
<html:base/>

</head>

<body>
<h2>HIIII

<bean:write name="TwoForm" property="Acti" />
<bean:write name="TwoForm" property="Reqid" />
<bean:write name="TwoForm" property="hours" />
<bean:write name="TwoForm" property="minutes" />
<bean:write name="TwoForm" property="comments" />
<bean:write name="TwoForm" property="startdate" />
</h2>

<h3><bean:message key="app.title" /></h3>


<table border=1>
<tr><th>Activity<th>ReqNo</th><th>Hours</th><th>Minutes</th><th>Comments</th><th>Date</th></tr>

<logic:iterate id="Two" name="TwoForm" property="TwList">
<tr><td>
<bean:write name="Two" property="Acti"/></td>

<td><bean:write name="Two" property="Reqid"/></td>
<td><bean:write name="Two" property="hours"/></td>
<td><bean:write name="Two" property="minutes"/></td>
<td><bean:write name="Two" property="comments"/></td>
<td><bean:write name="Two" property="startdate"/></td>

</logic:iterate>
</table>




</body>

</html:html>
Error Which i am receiving is as follows:

javax.servlet.jsp.JspException: Cannot find bean TwoForm in any scope
org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:938)
org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:286)
org.apache.jsp.report1_jsp._jspx_meth_bean_write_0(report1_jsp.java:272)
org.apache.jsp.report1_jsp._jspService(report1_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Struts is generally case sensitive (and since Java is also, Struts pretty much has to be case sensitive). I notice that in your form bean definition you use "TwoForm" and in your action mapping you use "twoForm". I would adopt a convention and stick with it.

It looks like you mistakenly posted the code for TwoForm.java a second time instead of posting the code for TwoAction.java.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean cannot be found in any scope
 
Similar Threads
Indexed tags and form beans
problem in accessing a list through a iterate tag.
readio with index properties. need help
When Validation Error I Lose My Bean Value-Struts 2
Struts Validation Empty alert Box