Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javax.servlet.ServletException: BeanUtils.populate

Status
Not open for further replies.

saiteja

Programmer
Sep 24, 2003
3
IN
Hi,
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
<%@ page language=&quot;java&quot; session=&quot;true&quot;%>
<!-- Imports-->
<%@ taglib uri=&quot;/WEB-INF/struts-bean.tld&quot; prefix=&quot;bean&quot; %>
<%@ taglib uri=&quot;/WEB-INF/struts-html.tld&quot; prefix=&quot;html&quot; %>
<%@ taglib uri=&quot;/WEB-INF/struts-logic.tld&quot; prefix=&quot;logic&quot; %>
<html:html locale=&quot;true&quot;>
<!--Apply Stylesheet--> <head>
<link href=&quot;./layouts/PrimeCss.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot;> </head>
<body norepeat bottommargin=&quot;0&quot; leftmargin=&quot;0&quot; rightmargin=&quot;0&quot; topmargin=&quot;0&quot; bgproperties=&quot;fixed&quot;>
<html:form action=&quot;/createQuestion&quot; focus=&quot;questionName&quot; name=&quot;createQuestionForm&quot; type=&quot;com.trx.kms.questionbank.CreateQuestionForm&quot;>
<bean:message key=&quot;questionbank.createquestion.pagetitle&quot;/>

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

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

The following is the ActionForm class

package com.trx.kms.questionbank; import javax.servlet.http.HttpServletRequest;
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)it.next();
String paramValue = (String)values.get(paramName);
sb.append(paramName);
sb.append(paramValue);
} } return sb.toString();
}


public void reset(ActionMapping mapping, HttpServletRequest request) {
this.questionName=null;
this.questionDesc=null;
}


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.io.IOException;
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(&quot;success&quot;)); }
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top