Java Mailing List Archive

Home » Home (12/2007) » Struts Users »

javax.servlet.ServletException: BeanUtils.populate




I am writing a small page based on struts guidelines for creating map-backed
forms. I am using struts 1.1. I have a jsp in which I have some dynamic
fields. I used a for loop for these,currently. In the ActionForm, I have
declared a HashMap for collecting values of these fields. However, when I
submit the page, I am getting the error- javax.servlet.ServletException:
BeanUtils.populate Root cause: java.lang.IllegalArgumentException: No bean
specified. Pl. help me understand what went wrong.

The following is the jsp page
<!-- Imports-->
<%@(protected)" %>
<%@(protected)" %>
<%@(protected)" %>
<html:html locale="true">
<!--Apply Stylesheet--> <head>
<link href="./layouts/PrimeCss.css" type="text/css" rel="stylesheet">
<body norepeat bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0"
<html:form action="/createQuestion" focus="questionName"
<bean:message key="questionbank.createquestion.pagetitle"/>

<bean:message key=""/> <html:text
property="questionName" style="width:195px" maxlength="100"/>
<bean:message key="questionbank.createquestion.description"/> <html:textarea
property="questionDesc" cols="65" rows="12"/>
<% for (int i=0; i <=2; i++) { String name = "value(foo-" + i + ")"; %>
<bean:message key="questionbank.createquestion.option"/> <html:text
property="<%= name %>" />

<%} %> <html:image page="/layouts/submit.jpg" property="submit"
onclick="onSubmitClick();"/> <html:image page="/layouts/cancel.jpg"
property="reset" />
</html:form> </body> </html:html>

The following is the ActionForm class

package com.trx.kms.questionbank; import
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;

public final class CreateQuestionForm extends ActionForm{
private String questionName=null;
private String questionDesc=null;
private String submit=null;
private String reset=null;
private final Map values = new HashMap();

public void setValue(String key, Object value) {
values.put(key, value); }
public Object getValue(String key) {
return values.get(key); }
public String getQuestionDesc() {
return questionDesc; }
public String getQuestionName() {
return questionName; }
public void setQuestionDesc(String string) {
questionDesc = string; }
public void setQuestionName(String string) {
questionName = string; }
public String getReset() {
return reset; }
public String getSubmit() {
return submit; }
public void setReset(String string) {
reset = string; }
public void setSubmit(String string) {
submit = string; }

public String getQuestions()
StringBuffer sb = new StringBuffer();
if ((values!=null && !values.isEmpty())) {
Iterator it = values.keySet().iterator();
while (it.hasNext()) {
String paramName = (String);
String paramValue = (String)values.get(paramName);
} } return sb.toString();

public void reset(ActionMapping mapping, HttpServletRequest request) {

public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {
ActionErrors errors = new ActionErrors();
return errors; } }

The following is the action class

package com.trx.kms.questionbank;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;

public final class CreateQuestionAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException {
String questions=((CreateQuestionForm)form).getQuestions();
ActionErrors errors = new ActionErrors();
if (!errors.isEmpty()) {
saveErrors(request, errors);
return (new ActionForward(mapping.getInput())); }
return (mapping.findForward("success")); }

To unsubscribe, e-mail: struts-user-unsubscribe@(protected)
For additional commands, e-mail: struts-user-help@(protected)

©2008 - Jax Systems, LLC, U.S.A.