Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JspException: Cannot find bean: "UserForm" in any scope

843840Aug 1 2009 — edited Aug 2 2009
Hi ,
i am new to sturts .checking the dynavaliodator form .
have created one jsp page ,where there are 5 buttons and 1 test field and one comments fiels. i am doing validation for the 2 test fields.

below is my jsp page .. i am using dynaaction form for creating the bean

please find the jsp page, the action class and the validator.xml file

please help me as i am stuck her not able to get any clue what exactly causing this to fail ..

........................................................................................................index.jsp........................................................................................................


<html:form action="UserAction">
<table>
<tr>
<td>MESSAGE :<bean:write name="UserForm" property="message" /></td>
</tr>
<tr>
<td>Name :<bean:write name="UserForm" property="name" /></td>
</tr>
<tr>
<td>Sex:<bean:write name="UserForm" property="sex" /></td>
</tr>
<tr>
<td>Comments:<bean:write name="UserForm" property="comments" /></td>
</tr>
<tr>
<td><html:submit property="method">
<bean:message key="UserForm.add" />
</html:submit></td>
</tr>
<tr>
<td><html:submit property="method">
<bean:message key="UserForm.update" />
</html:submit></td>
</tr>
<tr>
<td><html:submit property="method">
<bean:message key="UserForm.delete" />
</html:submit></td>
</tr>


</table>
<table>
<tr>
<td>Name :<html:text name="UserForm" property="name" /> <logic:equal
name="UserForm" property="name" value="Lalatendu">
Name is :Lalatendu Puhan .
</logic:equal> <logic:notEqual name="UserForm" property="name" value="Lalatendu">
Name not equal to Lalatendu Puhan.
</logic:notEqual></td>
</tr>

<tr>
<td>SEX : <html:radio name="UserForm" property="sex" value="M">M</html:radio>
<html:radio name="UserForm" property="sex" value="F">F</html:radio> <html:radio
name="UserForm" property="sex" value="BEECHKA">C</html:radio></td>
</tr>
<tr>
<td>Comments : <html:textarea cols="20" rows="3" name="UserForm"
property="comments"></html:textarea></td>
</tr>
<tr>
<td><html:submit property="method">
<bean:message key="UserForm.submit" />
</html:submit></td>
<td><html:reset property="method">
<bean:message key="UserForm.reset" />
</html:reset></td>
</tr>
</table>
</html:form>
.........................................................................................UserAction [Action class] .................................................................................................................

package com.lookupDispatch.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.LookupDispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.validator.DynaValidatorForm;



import java.util.*;

public class UserAction extends LookupDispatchAction {

/* forward name="success" path="" */
private final static String SUCCESS = "success";

/**
* Provides the mapping from resource key to method name.
*
* @return Resource key / method name map.
*/
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("UserForm.add", "add");
map.put("UserForm.update", "update");
map.put("UserForm.delete", "delete");
map.put("UserForm.submit", "submit");
map.put("UserForm.reset", "reset");
return map;
}

public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaValidatorForm userForm = (DynaValidatorForm) form;
// DynaActionForm userForm = (DynaActionForm) form;
// userForm.setMessage("Inside add user method.");
System.out.println("Inside add user method");
return mapping.findForward(SUCCESS);
}

public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaValidatorForm userForm = (DynaValidatorForm) form;
// DynaActionForm userForm = (DynaActionForm) form;
// userForm.setMessage("Inside update user method.");
System.out.println("Inside update user method.");
return mapping.findForward(SUCCESS);
}

public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaValidatorForm userForm = (DynaValidatorForm) form;
// DynaActionForm userForm = (DynaActionForm) form;
// userForm.setMessage("Inside delete user method.");
System.out.println("Inside delete user method.");
return mapping.findForward(SUCCESS);
}

public ActionForward submit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaValidatorForm userForm = (DynaValidatorForm) form;
// DynaActionForm userForm = (DynaActionForm) form;
// userForm.setMessage("Inside submit user method.");
System.out.println("Inside submit user method.");
return mapping.findForward("submit");
}

public ActionForward reset(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaValidatorForm userForm = (DynaValidatorForm) form;
// DynaActionForm userForm = (DynaActionForm) form;
System.out.println("Inside Reset user method.");
// userForm.setMessage("Inside Reset user method.");
return mapping.findForward(SUCCESS);
}
}
.......................................................................................................................validation.xml...................................................................................................................................................................................................
<formset>
<!-- An example form -->
<form name="UserForm">
<field
property="name"
depends="required">
<arg key="UserForm.name"/>
</field>
<field
property="comments"
depends="required,minlength">
<arg0 key="UserForm.comments"/>
<arg1 key="${var:minlength}" name="minlength" resource="false"/>

<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>
</form>

</formset>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

on click of any button i am geting this exception as

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "UserForm" in any scope


any sujestion will be highly appreciated . thanks in advance ..
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2009
Added on Aug 1 2009
2 comments
874 views