NumberFormatException: For input string: "request"

Good day all.

I'm having difficulty with trying to include a formbean inside a request to

another jsp page.

I'm running JBoss 4.0.4GA, JSDK 1.5, Windows XP, Apache 2.0.59,

and I'm using some of David Harms' code that he published in his 2001

Book, "JSP, Servlets and MySQL".

I'll post as much of the code here as the forum will allow.....

JSP:

index.jsp:

<%@ page language="java"%>

<%@ page import="java.util.Enumeration"%>

<%@ page import="javax.servlet.*"%>

<%@ page import="javax.servlet.http.*"%>

<%@ page import="edu.msu.hit.lib.forms.*"%>

<%@ page import="edu.msu.hit.testformbean.forms.*"%>

<jsp:include page="./header.jsp">

<jsp:param name="pageTitle" value="TestFormBean" />

<jsp:param name="page" value="index" />

</jsp:include>

<body>

<%

String errorPage = "/syserror.jsp";

String forwardPage = "/testformadd.jsp";

ProductFormBean form = new ProductFormBean();

System.out.println("testformbean: bean created: " + form.getName());

request.setAttribute("product", form);

request.setAttribute("formclass", "edu.msu.hit.testformbean.forms.ProductFormBean");

request.setAttribute("pageTitle", forwardPage);

RequestDispatcher dispatcher;

try {

dispatcher = getServletContext().getRequestDispatcher(forwardPage);

if (dispatcher != null) {

dispatcher.forward(request, response);

}

} catch (Exception ie) {

//System.out.println("ProdControl: Exception!!");

//System.out.println("ProdControl: msg: " + e.getMessage());

request.setAttribute("pageError",ie.getMessage());

request.setAttribute("pageErrorObj",ie);

request.setAttribute("pageTitle", "testformbean: ERROR!!!");

//uri = systemErrorHtml;

dispatcher = getServletContext().getRequestDispatcher(errorPage);

if (dispatcher != null) {

dispatcher.forward(request, response);

}

}

%>

</body>

</html>

testformadd.jsp:

<%@ page language="java"%>

<%@ page import="edu.msu.hit.lib.forms.*"%>

<%@ page import="edu.msu.hit.testformbean.forms.*"%>

<%@ taglib uri="/WEB-INF/tlds/hitlib.tld" prefix="hit" %>

<%@ taglib uri="/WEB-INF/tlds/products.tld" prefix="prodtag" %>

<jsp:include page="./header.jsp">

<jsp:param name="pageTitle" value="<%= request.getAttribute("pageTitle")%>" />

<jsp:param name="page" value="index" />

</jsp:include>

<%

FormBean form2 = (ProductFormBean)request.getAttribute("product");

//Object oc = request.getAttribute("formclass");

//Class cc = Class.forName("java.lang.String");

//String formClass = (String) cc.newInstance();

//System.out.println("testformbean: class passed: " + formClass);

//Object o = request.getAttribute("form");

//Class c = Class.forName(formClass);

//ProductFormBean form2 = (ProductFormBean) c.newInstance();

System.out.println("testformbean: bean passed: " + form2.getName());

%>

<body>

<center>

<h3>Form Bean Test Page</h3>

<prodtag:prodform formName="product">

<hit:formField formName="product" fieldName="formID"/>

<table border="1" cellpadding="2" cellspacing="0">

<tr>

<td valign="top" colspan="2" align="center">

Product Add

</td>

</tr>

<tr>

<td align="center">Field Name</td>

<td align="center">Field Html</td>

</tr>

<hit:iterate

collection="product"

iteratedItemName="formField"

iteratedItemClass="edu.msu.hit.lib.forms.FormFieldBean"

scope="request">

<tr>

<td align="right" valign="top">

<%if ( request.getAttribute("formField") != null) { %>

<jsp:getProperty name="formField" property="prompt"/>

<!-- prodtag:formField formName="product" fieldName="prompt"/ -->

<%} else { %>

NULL Prompt

<%} %>

</td>

<td align="left" valign="top">

<%if ( request.getAttribute("formField") != null) { %>

<jsp:getProperty name="formField" property="html"/>

<!-- prodtag:formField formName="product" fieldName="html"/ -->

<%} else { %>

NULL Html

<%} %>

</td>

</tr>

</hit:iterate>

<tr>

<td valign="top" colspan="2">

<p align="center">

<hit:formField formName="product" fieldName="sid"/>

<hit:formField formName="product" fieldName="submit"/>

</td>

</tr>

</table>

</prodtag:prodform>

</center>

</body>

</html>

as you can see, the testformadd.jsp uses tags to display the

form fields, which are created in the ProductFormBean.java

class. I've posted the classes (including the tags and the form beans)

below....

ProductFormBean.java:

--

/*

* This is a class that models a form to

* add/modify Products.

*

* A form bean to display a form for adding a product,

* and to validate data.

*

* Revisions

* WhenWho What

* -- -

* 20061017 tjc Started writing it.

* 20070108 tjc Made one bean for products, to handle add/modify.

*

*/

package edu.msu.hit.testformbean.forms;

import javax.naming.InitialContext;

import java.io.*;

import java.util.*;

import edu.msu.hit.demo.util.*;

import edu.msu.hit.demo.ejb.product.*;

import edu.msu.hit.demo.ejb.productmanager.*;

import java.sql.*;

import edu.msu.hit.lib.forms.*;

public class ProductFormBean extends FormBean {

private static final String EJBPATH = "test/ejb/";

private static final String MGRPATH = "test/manager/";

private static final String PRODMGR_COMP = EJBPATH + "ProductManagerHome";

private boolean adding=true;

private Integer updateid=null;

private Integer productid=null;

private String productdesc=null;

private Integer producttype=null;

FormFieldTextBean f0 = null;

FormFieldTextBean f1 = null;

FormFieldSelectBean f2 = null;

public ProductFormBean() {

super();

setName("product");

setFormPage("/productform.jsp");

setFormDonePage("/productadded.jsp");

setPageTitle("Product Management Page");

f0 = new FormFieldTextBean("fprod0id",10);

//f0.setMessage("Id cannot be blank and must be numeric !");

f0.setPrompt("Id:");

addField(f0);

addRepeatField(f0);

f1 = new FormFieldTextBean("fprod1desc",50);

//f1.setMessage("Description cannot be blank !");

f1.setPrompt("Description:");

addField(f1);

addRepeatField(f1);

f2 = new FormFieldSelectBean("fprod2type", "Product Type",

getTypes(), 0);

//f2.setOptionsClass("edu.msu.hit.demo.ejb.product.FormSelectTO");

//f2.setMessage("Please select one type!");

f2.setPrompt("Type:");

addField(f2);

addRepeatField(f2);

FormFieldSubmitBean f99 = new FormFieldSubmitBean("Save Product");

f99.setRequired(true);

addField(f99);

addRepeatField(f99);

}

public void setAdd(boolean inputadd) {

adding = inputadd;

}

public boolean setId(Integer inputid) {

updateid = inputid;

if (!retrieve()) {

return false;

} else {

f0.setValue(productid.toString());

f1.setValue(productdesc);

f2.setValue(producttype.toString());

}

return true;

}

/*

public String getProductid() { return f0.getHtml(); }

public String getProductdesc() { return f1.getHtml(); }

public String getProducttype() { return f2.getHtml(); }

*/

// --

// this routine gets the product types as a collection

// so the drop-down list can be populated.

private Collection getTypes() {

Collection allTypes = null;

try {

// Create initial context

InitialContext ctx = new InitialContext();

// set up product manager sessionbean

Object obj = ctx.lookup("test/ejb/ProductManagerHome");

ProductManagerHome home = (ProductManagerHome)

javax.rmi.PortableRemoteObject.narrow(obj,ProductManagerHome.class);

//ProductManagerHome home = (ProductManagerHome) obj;

ProductManager productManager = home.create();

allTypes = productManager.getProductTypeList();

} catch(Exception e) {

System.out.print("ProdAddFormBean: save(): ");

System.out.println("Exception: " + e.getMessage());

//out.println();

//e.printStackTrace();

return null;

}

return allTypes;

}

public boolean validate()

{

// validate data entered in this form

formErrors = false;

String idvalue = getFieldValue("fprod0id");

if ( (idvalue == null)

|| (idvalue.length() == 0)

|| (idvalue.equals(" "))

) {

f0.setError("This field cannot be blank or zero!");

formErrors = true;

//return false;

} else {

try {

//update_productid = Integer.parseInt(idvalue);

productid = new Integer(idvalue);

} catch (NumberFormatException nfe) {

f0.setError("This field must be numeric!!");

formErrors = true;

}

//} catch (Exception e) {

//f0.setError("This field must be numeric!!");

//formErrors = true;

//}

}

setNewForm(false);

if (formErrors == false) {

try {

// Create initial context for JNDI lookups.

InitialContext ctx = new InitialContext();

// set up product manager sessionbean

Object obj = ctx.lookup(PRODMGR_COMP);

ProductManagerHome home = (ProductManagerHome)

javax.rmi.PortableRemoteObject.narrow(obj,ProductManagerHome.class);

//ProductManagerHome home = (ProductManagerHome) obj;

ProductManager productManager = home.create();

ProductTO prodTO = productManager.getProduct(productid);

if (prodTO != null) {

f0.setError("This product ID already exists!!");

formErrors = true;

}

} catch(Exception e) {

System.out.print("ProdAddFormBean: validate(): ");

System.out.println("Exception: " + e.getMessage());

e.printStackTrace();

}

}

String descvalue = getFieldValue("fprod1desc");

if ( (descvalue == null)

|| (descvalue.length() == 0)

|| (descvalue.equals(" "))

) {

f1.setError("This field cannot be blank!");

formErrors = true;

} else {

productdesc = descvalue;

}

String typevalue = getFieldValue("fprod2type");

if ( (typevalue == null)

|| (typevalue.length() == 0)

|| (typevalue.equals(" "))

) {

//formErrors = true;

f2.setError("You must select a type !");

} else {

//producttype = typevalue;

try {

//update_productid = Integer.parseInt(idvalue);

producttype = new Integer(typevalue);

} catch (NumberFormatException nfe) {

f2.setError("This field must be numeric!!");

formErrors = true;

}

}

if (areErrors())

return false;

else

return true;

}

public boolean update()

{

//String idvalue = getFieldValue("fproductid");

//Integer idint = new Integer(idvalue);

//String descvalue = getFieldValue("fproductdesc");

//String typevalue = getFieldValue("fproducttype");

//Integer typeint = new Integer(producttype);

try {

// Create initial context for JNDI lookups.

InitialContext ctx = new InitialContext();

// set up product manager sessionbean

Object obj = ctx.lookup(PRODMGR_COMP);

ProductManagerHome home = (ProductManagerHome)

javax.rmi.PortableRemoteObject.narrow(obj,ProductManagerHome.class);

//ProductManagerHome home = (ProductManagerHome) obj;

ProductManager productManager = home.create();

boolean upd_rc

= productManager.updateProduct( productid, productdesc, producttype );

if (!upd_rc) return false;

} catch(Exception e) {

System.out.print("ProdAddFormBean: update(): ");

System.out.println("Exception: " + e.getMessage());

//out.println();

e.printStackTrace();

return false;

}

return true;

}

private boolean retrieve()

{

//String idvalue = getFieldValue("fproductid");

//Integer idint = new Integer(idvalue);

//String descvalue = getFieldValue("fproductdesc");

//String typevalue = getFieldValue("fproducttype");

//Integer typeint = new Integer(producttype);

try {

// Create initial context for JNDI lookups.

InitialContext ctx = new InitialContext();

// set up product manager sessionbean

Object obj = ctx.lookup(PRODMGR_COMP);

ProductManagerHome home = (ProductManagerHome)

javax.rmi.PortableRemoteObject.narrow(obj,ProductManagerHome.class);

//ProductManagerHome home = (ProductManagerHome) obj;

ProductManager productManager = home.create();

ProductTO prodto

= productManager.getProduct( updateid );

if (prodto == null) return false;

productid = prodto.productId;

productdesc = prodto.productName;

producttype = prodto.productType;

} catch(Exception e) {

System.out.print("ProductFormBean: retrieve(): ");

System.out.println("Exception: " + e.getMessage());

//out.println();

e.printStackTrace();

return false;

}

return true;

}

public void save() {

return;

}

}

FormBean.java:

--

/*

* A generic class for modeling an HTML form.

*

* This is the base class for form field beans for all

* HTML forms.

*

* Revisions

* WhenWho What

* -- -

* 20061017 tjc Started writing it.

* 20061218 tjc Added getTypes() method.

* 20061228 tjc Adapted for general use.

*

*/

package edu.msu.hit.lib.forms;

import java.util.*;

//import java.sql.Connection;

import javax.naming.InitialContext;

import javax.servlet.http.*;

import javax.servlet.ServletContext;

import java.util.ArrayList;

import edu.msu.hit.lib.forms.*;

/** A bean that handles common form tasks.

*

*/

public abstract class FormBean implements edu.msu.hit.lib.util.Message {

private String method="POST";

private String action="";

protected HashMap fieldsMap;

protected HashMap fielderrorsMap;

private String uri="";

private HashMap params;

private boolean newForm=true;

protected boolean formErrors=false;

private String name="form";

private String formPage;

private String formDonePage;

private String message;

private String footer="</form>";

private String pageTitle;

private TreeSet repeatFields=null;

protected HttpServletRequest request=null;

protected HttpServletResponse response=null;

protected ServletContext context=null;

public FormBean() {

super();

fieldsMap = new HashMap();

fielderrorsMap = new HashMap();

FormFieldHiddenBean field = new FormFieldHiddenBean("formID","true");

addField(field);

repeatFields = new TreeSet();

}

public FormBean(String newFormPage,String newFormDonePage) {

this();

setFormPage(newFormPage);

setFormDonePage(newFormDonePage);

}

public void addField(FormFieldBean formField){

fieldsMap.put(formField.getID(),formField);

}

public void addError(String formFieldId, String errormsg){

fielderrorsMap.put(formFieldId,errormsg);

formErrors = true;

}

public String getError(String formFieldId){

return (String)fielderrorsMap.get(formFieldId);

}

public void addRepeatField(FormFieldBean formField){

repeatFields.add(formField);

}

public java.lang.String getAction() {

return action;

}

public Object getField(String fieldID){

Object f = fieldsMap.get(fieldID);

return f;

}

public String getFieldValue(String fieldName) {

FormFieldBean field = (FormFieldBean) getField(fieldName);

if (field != null)

return field.getValue();

else return "";

}

public String getFieldValueEscaped(String fieldName) {

FormFieldBean field = (FormFieldBean) getField(fieldName);

if (field != null)

return field.getValueEscaped();

else return "";

}

public java.lang.String getFooter() {

return footer;

}

public java.lang.String getFormDonePage() {

return formDonePage;

}

public java.lang.String getFormPage() {

return formPage;

}

public java.lang.String getHeader() {

StringBuffer sb = new StringBuffer("<form method=\"");

sb.append(getMethod());

sb.append("\" action=\"");

sb.append(getAction());

sb.append("\">");

return(sb.toString());

}

public java.util.Iterator getIterator() {

if (repeatFields == null) repeatFields = new TreeSet();

return repeatFields.iterator();

}

public java.lang.String getMessage() {

return message;

}

public java.lang.String getMethod() {

return method;

}

public java.lang.String getName() {

return name;

}

public java.lang.String getFormName() {

return name;

}

public java.lang.String getPageTitle() {

return pageTitle;

}

public java.util.TreeSet getRepeatFields() {

return repeatFields;

}

public java.lang.String getUri() {

return uri;

}

public boolean isNewForm() {

return newForm;

}

public boolean areErrors() {

return formErrors;

}

//public abstract void save(Connection conn);

public abstract void save();

public void setAction(java.lang.String newAction) {

action = newAction;

}

public void setFieldValue(String fieldName, String newValue) {

FormFieldBean field = (FormFieldBean)getField(fieldName);

if (field != null)

field.setValue(newValue);

}

public void setFormDonePage(java.lang.String newFormDonePage) {

formDonePage = newFormDonePage;

}

public void setFormPage(java.lang.String newFormPage) {

formPage = newFormPage;

}

public void setMessage(java.lang.String newMessage) {

message = newMessage;

}

public void setMethod(java.lang.String newMethod) {

method = newMethod;

}

public void setName(java.lang.String newName) {

name = newName;

}

public void setFormName(java.lang.String newName) {

name = newName;

}

public void setPageTitle(java.lang.String newTitle) {

pageTitle = newTitle;

}

public void setNewForm(boolean newNewForm) {

newForm = newNewForm;

}

public void setParameters(HashMap requestParams) {

/*

System.out.println("setting form parameters");

String[] paramValues;

FormFieldBean field;

// Look for the FormID hidden field in the form.

// If found, this is a GET or POST of the form.

if (requestParams.containsKey("formID")) {

System.out.println("found the formID hidden field");

paramValues = (String[]) requestParams.get("formID");

if (paramValues[0].equals("true"))

setNewForm(false);

System.out.println("setting NewForm to false");

} else {

System.out.println("did not find the formID hidden field");

}

System.out.println("new form: " + isNewForm());

if (!isNewForm()) {

Iterator iterator = fieldsMap.values().iterator();

while (iterator.hasNext()) {

// get the next form field

field = (FormFieldBean) iterator.next();

// look for a match in the request parameters

if (requestParams.containsKey(field.getID())) {

System.out.println("found a match for form field " + field.getID());

// get the parameter values from the request

paramValues = (String[]) requestParams.get(field.getID());

// only the first element of the array is used at present

field.setValue(paramValues[0]);

} else {

System.out.println("found a match for form field " + field.getID());

field.clear();

}

}

}

*/

}

public void setServletInfo(

javax.servlet.http.HttpServletRequest newRequest,

javax.servlet.http.HttpServletResponse newResponse,

javax.servlet.ServletContext newContext)

{

request = newRequest;

response = newResponse;

context = newContext;

Enumeration e = request.getParameterNames();

java.util.HashMap requestParams = new java.util.HashMap();

System.out.println("FormBean: form: [" + getName() + "]");

System.out.println("FormBean: setting form parameters");

while (e.hasMoreElements()) {

String key = (String) e.nextElement();

String[] values = request.getParameterValues(key);

requestParams.put(key, values);

System.out.println("key: [" + key + "] values: [" + values.toString() + "]");

}

String[] paramValues;

FormFieldBean field;

// Look for the FormID hidden field in the form.

// If found, this is a GET or POST of the form.

//if (requestParams.containsKey("formID")) {

//System.out.println("found the formID hidden field");

//paramValues = (String[]) requestParams.get("formID");

//if (paramValues[0].equals("true"))

//setNewForm(false);

//System.out.println("setting NewForm to false");

//} else {

//System.out.println("did not find the formID hidden field");

//}

System.out.println("FormBean: new form: " + isNewForm());

if (!isNewForm()) {

Iterator iterator = fieldsMap.values().iterator();

while (iterator.hasNext()) {

// get the next form field

field = (FormFieldBean) iterator.next();

// look for a match in the request parameters

if (requestParams.containsKey(field.getID())) {

//System.out.println("found a match for form field " + field.getID());

// get the parameter values from the request

paramValues = (String[]) requestParams.get(field.getID());

// only the first element of the array is used at present

field.setValue(paramValues[0]);

} else {

//System.out.println("found a match for form field " + field.getID());

field.clear();

}

}

}

}

public void setUri(java.lang.String newUri) {

uri = newUri;

}

public boolean validate() {

Iterator iterator = fieldsMap.values().iterator();

FormFieldBean field;

while (iterator.hasNext()) {

// get the next form field

field = (FormFieldBean) iterator.next();

if (!field.validate()) {

//setMessage(field.getMessage());

addError(field.getName(), field.getMessage());

//return false;

}

}

return true;

}

//public boolean validate(Connection conn) {

//return(validate());

//}

}

FormFieldBean.java:

--

/** A generic class for modeling an HTML form field.

*

* This is a form field bean

*

* Revisions

* WhenWho What

* -- -

* 20061101 tjc Started writing it.

* 20061228 tjc Adapt for general use, in particular for use

* in the MOCF Ball app.

*

*/

package edu.msu.hit.lib.forms;

public abstract class FormFieldBean

implements edu.msu.hit.lib.util.Message, Comparable {

private String type=null;

private String name=null;

private String prompt=null;

private String ID="";

private String value="";

private String error="";

private int width=25;

private int height=1;

private String html="";

private boolean required=false;

private String message="";

private boolean greyed=false;

private boolean hidden=false;

private boolean visible=true;

public FormFieldBean() {

super();

}

public void clear() {

value = "";

}

public int compareTo(java.lang.Object o){

FormFieldBean otherField = (FormFieldBean)o;

return(getID().compareTo(otherField.getID()));

}

public int getHeight() {

return height;

}

public abstract java.lang.String getHtml();

public java.lang.String getID() {

return ID;

}

public java.lang.String getMessage() {

return message;

}

public java.lang.String getName() {

return name;

}

public java.lang.String getPrompt() {

if (prompt != null)return prompt;

if (name != null) return name;

if (ID != null) return ID;

return("unknown field");

}

public java.lang.String getType() {

return type;

}

public java.lang.String getValue() {

return value;

}

public java.lang.String getError() {

return error;

}

public java.lang.String getValueEscaped() {

if (value == null) return (null);

StringBuffer result = new StringBuffer();

for (int i = 0; i < value.length(); i++) {

char ch = value.charAt(i);

if (ch == '\'')

result.append("''");

else

result.append(ch);

}

return (result.toString());

}

public int getWidth() {

return width;

}

public boolean isRequired() {

return required;

}

public void setHeight(int newHeight) {

height = newHeight;

}

public void setID(java.lang.String newID) {

ID = newID;

}

public void setMessage(java.lang.String newMessage) {

message = newMessage;

}

public void setName(java.lang.String newName) {

name = newName;

}

public void setPrompt(java.lang.String newPrompt) {

if (newPrompt != null) prompt = newPrompt;

}

public void setRequired(boolean newRequired) {

required = newRequired;

}

public void setType(java.lang.String newType) {

if (newType != null) type = newType;

}

public void setValue(java.lang.String newValue) {

if (newValue != null) {

value = newValue;

}

}

public void setError(java.lang.String newError) {

if (newError != null) error = newError;

}

public void setGreyed(boolean newGreyed) {

greyed = newGreyed;

}

public void setHidden(boolean newHidden) {

hidden = newHidden;

}

public void setVisible(boolean newVisible) {

visible = newVisible;

}

public boolean getGreyed() {

return greyed;

}

public boolean getHidden() {

return hidden;

}

public boolean getVisible() {

return visible;

}

public void setWidth(int newWidth) {

width = newWidth;

}

public boolean validate(){

if ( (isRequired()) && (value.equals("")) ) {

setMessage("The field \"" + getPrompt()

+ "\" is required");

setError("The field \"" + getPrompt()

+ "\" is required");

return false;

}

else return true;

}

}

FormTag.java:

-

/*

* A tag to create an HTML form.

*

* Revisions

* WhenWho What

* -- -

* 20061215 tjc Started writing it.

*

*/

package edu.msu.hit.lib.taglib;

import javax.servlet.jsp.tagext.*;

import javax.servlet.jsp.*;

import javax.servlet.*;

import java.io.IOException;

import edu.msu.hit.lib.forms.*;

public class FormTag extends TagSupport {

private String formName;

private String formClass;

private FormBean form=null;

public int doEndTag() throws JspException {

JspWriter out = pageContext.getOut();

try {

if (form != null)

out.print(form.getFooter());

else out.print("</form>");

} catch (IOException e) {

throw new JspException(e.toString());

}

return EVAL_PAGE;

}

public int doStartTag() throws JspException {

System.out.println("FormTag doStartTag");

ServletRequest request = pageContext.getRequest();

try {

//form = (FormBean)request.getAttribute(getFormName());

//Object o = request.getAttribute("form");

//Object o2 = request.getAttribute("formclass");

//Class c2 = Class.forName("java.lang.String");

//formClass = (String) o2.toString();

//Class c = Class.forName(formClass);

//form = (FormBean)request.getAttribute("form");

//form = (FormBean) c.newInstance();

//formClass = (String) pageContext.getAttribute("formclass");

//form = (FormBean) pageContext.getAttribute("form");

form = (FormBean)request.getAttribute(getFormName());

} catch (ClassCastException e) {

throw new JspException("FormTag class cast exception");

/*

} catch (ClassNotFoundException e) {

throw new JspException("FormTag class NOTFOUND exception");

} catch (InstantiationException e) {

throw new JspException("FormTag class Instantiation exception");

} catch (IllegalAccessException e) {

throw new JspException("FormTag class IllegalAccess exception");

*/

}

if (form == null) {

System.out.println("formbean is null, skipping form");

return SKIP_BODY;

} else {

System.out.println("FormTag form retrieved: [" + form.getName() + "]");

}

JspWriter out = pageContext.getOut();

try {

out.print(form.getHeader());

} catch (IOException e) {

throw new JspException(e.toString());

}

return EVAL_BODY_INCLUDE;

}

public java.lang.String getFormName() {

return formName;

}

public void setFormName(java.lang.String newFormName) {

formName = newFormName;

}

}

FormFieldTag.java:

/*

* A custom tag to display an HTML form field

*

* Revisions

* WhenWho What

* -- -

* 20061215 tjc Started writing it.

*

*

*/

package edu.msu.hit.lib.taglib;

import javax.servlet.jsp.tagext.*;

import javax.servlet.jsp.*;

import javax.servlet.*;

import java.io.IOException;

import edu.msu.hit.lib.forms.*;

public class FormFieldTag extends TagSupport {

private String formName;

private String fieldName;

private String attribute=null;

public int doStartTag() throws JspException {

ServletRequest request = pageContext.getRequest();

System.out.println("FormFieldTag doStartTag");

FormBean fb = null;

try {

fb = (FormBean)request.getAttribute(getFormName());

} catch (ClassCastException e) {

System.out.println("FormFieldTag: FormTag class cast exception on " + getFormName());

return SKIP_BODY;

}

if (fb == null){

System.out.println("FormFieldTag: Unable to create FormBean " + getFormName());

return SKIP_BODY;

}

FormFieldBean field = (FormFieldBean)fb.getField(getFieldName());

if (field == null) {

System.out.println("Unable to get field "

+ getFieldName()

+ " in FormBean " + getFormName());

return SKIP_BODY;

}

System.out.println("FormFieldTag: using formbean " + fb + ", field " + field);

//pageContext.setAttribute(field.getName(),field);

JspWriter out = pageContext.getOut();

try {

if ((attribute != null)

&& (attribute.equalsIgnoreCase("prompt"))){

//System.out.println("prompt text: " + field.getPrompt());

out.print(field.getPrompt());

} else {

//System.out.println("field text: " + field.getHtml());

out.print(field.getHtml());

}

} catch (IOException e) {

throw new JspException(e.toString());

}

return (EVAL_BODY_INCLUDE);

}

public java.lang.String getAttribute() {

return attribute;

}

public java.lang.String getFieldName() {

return fieldName;

}

public java.lang.String getFormName() {

return formName;

}

public void setAttribute(java.lang.String newAttribute) {

attribute = newAttribute;

}

public void setFieldName(java.lang.String newFieldName) {

fieldName = newFieldName;

}

public void setFormName(java.lang.String newFormName) {

formName = newFormName;

}

}

The error trace I'm getting is:

08:06:06,778 INFO [TomcatDeployer] deploy, ctxPath=/testformbean, warUrl=.../tm

p/deploy/tmp15636testformbean-exp.war/

08:06:16,932 INFO [STDOUT] testformbean: bean created: product

08:06:17,150 ERROR [STDERR] java.lang.NumberFormatException: For input string: "

request"

08:06:17,150 ERROR [STDERR]at java.lang.NumberFormatException.forInputStrin

g(NumberFormatException.java:48)

08:06:17,150 ERROR [STDERR]at java.lang.Integer.parseInt(Integer.java:447)

08:06:17,150 ERROR [STDERR]at java.lang.Integer.valueOf(Integer.java:553)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.JspUtil.coerceToIn

t(JspUtil.java:752)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.convertString(Generator.java:2949)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.evaluateAttribute(Generator.java:2752)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.generateSetters(Generator.java:2858)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.generateCustomStart(Generator.java:2176)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.visit(Generator.java:1685)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$CustomTag.acc

ept(Node.java:1441)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Nodes.visit(N

ode.java:2163)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Visitor.visit

Body(Node.java:2213)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.visit(Generator.java:1705)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$CustomTag.acc

ept(Node.java:1441)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Nodes.visit(N

ode.java:2163)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Visitor.visit

Body(Node.java:2213)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Visitor.visit

(Node.java:2219)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Root.accept(N

ode.java:456)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Nodes.visit(N

ode.java:2163)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator.generate

(Generator.java:3305)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Compiler.generateJ

ava(Compiler.java:198)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Compiler.compile(C

ompiler.java:295)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Compiler.compile(C

ompiler.java:276)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Compiler.compile(C

ompiler.java:264)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.JspCompilationContext.compi

le(JspCompilationContext.java:563)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.servlet.JspServletWrapper.s

ervice(JspServletWrapper.java:303)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.servlet.JspServlet.serviceJ

spFile(JspServlet.java:314)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.servlet.JspServlet.service(

JspServlet.java:264)

08:06:17,150 ERROR [STDERR]at javax.servlet.http.HttpServlet.service(HttpSe

rvlet.java:810)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationFilterCha

in.internalDoFilter(ApplicationFilterChain.java:252)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationFilterCha

in.doFilter(ApplicationFilterChain.java:173)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationDispatche

r.invoke(ApplicationDispatcher.java:672)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationDispatche

r.processRequest(ApplicationDispatcher.java:463)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationDispatche

r.doForward(ApplicationDispatcher.java:398)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationDispatche

r.forward(ApplicationDispatcher.java:301)

08:06:17,150 ERROR [STDERR]at org.apache.jsp.index_jsp._jspService(index_js

p.java:101)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.runtime.HttpJspBase.service

(HttpJspBase.java:97)

08:06:17,166 ERROR [STDERR]at javax.servlet.http.HttpServlet.service(HttpSe

rvlet.java:810)

08:06:17,166 ERROR [STDERR]at org.apache.jasper.servlet.JspServletWrapper.s

ervice(JspServletWrapper.java:332)

08:06:17,166 ERROR [STDERR]at org.apache.jasper.servlet.JspServlet.serviceJ

spFile(JspServlet.java:314)

08:06:17,166 ERROR [STDERR]at org.apache.jasper.servlet.JspServlet.service(

JspServlet.java:264)

08:06:17,166 ERROR [STDERR]at javax.servlet.http.HttpServlet.service(HttpSe

rvlet.java:810)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.core.ApplicationFilterCha

in.internalDoFilter(ApplicationFilterChain.java:252)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.core.ApplicationFilterCha

in.doFilter(ApplicationFilterChain.java:173)

08:06:17,166 ERROR [STDERR]at org.jboss.web.tomcat.filters.ReplyHeaderFilte

r.doFilter(ReplyHeaderFilter.java:96)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.core.ApplicationFilterCha

in.internalDoFilter(ApplicationFilterChain.java:202)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.core.ApplicationFilterCha

in.doFilter(ApplicationFilterChain.java:173)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.core.StandardWrapperValve

.invoke(StandardWrapperValve.java:213)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.core.StandardContextValve

.invoke(StandardContextValve.java:178)

08:06:17,166 ERROR [STDERR]at org.jboss.web.tomcat.security.SecurityAssocia

tionValve.invoke(SecurityAssociationValve.java:175)

08:06:17,166 ERROR [STDERR]at org.jboss.web.tomcat.security.JaccContextValv

e.invoke(JaccContextValve.java:74)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.core.StandardHostValve.in

voke(StandardHostValve.java:126)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.valves.ErrorReportValve.i

nvoke(ErrorReportValve.java:105)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.core.StandardEngineValve.

invoke(StandardEngineValve.java:107)

08:06:17,166 ERROR [STDERR]at org.apache.catalina.connector.CoyoteAdapter.s

ervice(CoyoteAdapter.java:148)

08:06:17,166 ERROR [STDERR]at org.apache.jk.server.JkCoyoteHandler.invoke(J

kCoyoteHandler.java:199)

08:06:17,166 ERROR [STDERR]at org.apache.jk.common.HandlerRequest.invoke(Ha

ndlerRequest.java:282)

08:06:17,166 ERROR [STDERR]at org.apache.jk.common.ChannelSocket.invoke(Cha

nnelSocket.java:754)

08:06:17,166 ERROR [STDERR]at org.apache.jk.common.ChannelSocket.processCon

nection(ChannelSocket.java:684)

08:06:17,166 ERROR [STDERR]at org.apache.jk.common.ChannelSocket$SocketConn

ection.runIt(ChannelSocket.java:876)

08:06:17,166 ERROR [STDERR]at org.apache.tomcat.util.threads.ThreadPool$Con

trolRunnable.run(ThreadPool.java:684)

08:06:17,166 ERROR [STDERR]at java.lang.Thread.run(Thread.java:595)

08:06:17,166 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception

java.lang.NumberFormatException: For input string: "request"

at java.lang.NumberFormatException.forInputString(NumberFormatException.

java:48)

at java.lang.Integer.parseInt(Integer.java:447)

at java.lang.Integer.valueOf(Integer.java:553)

at org.apache.jasper.compiler.JspUtil.coerceToInt(JspUtil.java:752)

at org.apache.jasper.compiler.Generator$GenerateVisitor.convertString(Ge

nerator.java:2949)

at org.apache.jasper.compiler.Generator$GenerateVisitor.evaluateAttribut

e(Generator.java:2752)

at org.apache.jasper.compiler.Generator$GenerateVisitor.generateSetters(

Generator.java:2858)

at org.apache.jasper.compiler.Generator$GenerateVisitor.generateCustomSt

art(Generator.java:2176)

at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.

java:1685)

at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)

at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)

at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)

at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.

java:1705)

at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)

at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)

at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)

at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)

at org.apache.jasper.compiler.Node$Root.accept(Node.java:456)

at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)

at org.apache.jasper.compiler.Generator.generate(Generator.java:3305)

at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)

at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext

.java:563)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper

.java:303)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3

14)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl

icationFilterChain.java:252)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF

ilterChain.java:173)

at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp

atcher.java:672)

at org.apache.catalina.core.ApplicationDispatcher.processRequest(Applica

tionDispatcher.java:463)

at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationD

ispatcher.java:398)

at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDis

patcher.java:301)

at org.apache.jsp.index_jsp._jspService(index_jsp.java:101)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper

.java:332)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3

14)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl

icationFilterChain.java:252)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF

ilterChain.java:173)

at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFi

lter.java:96)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl

icationFilterChain.java:202)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF

ilterChain.java:173)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV

alve.java:213)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV

alve.java:178)

at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(Securit

yAssociationValve.java:175)

at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValv

e.java:74)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j

ava:126)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j

ava:105)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal

ve.java:107)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav

a:148)

at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)

at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)

at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:754)

at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.ja

va:684)

at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSock

et.java:876)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP

ool.java:684)

at java.lang.Thread.run(Thread.java:595)

.....and the error page I'm displaying shows:

--

SYSTEM ERROR !!

A system error has occurred !

The error message is:

[ org.apache.jasper.JasperException: Unable to compile class for JSP ]

Stack Trace:

Class Name Method Name Line nbr

org.apache.jasper.servlet.JspServletWrapper handleJspException 510

org.apache.jasper.servlet.JspServletWrapper service 375

org.apache.jasper.servlet.JspServlet serviceJspFile 314

org.apache.jasper.servlet.JspServlet service 264

javax.servlet.http.HttpServlet service 810

org.apache.catalina.core.ApplicationFilterChain internalDoFilter 252

org.apache.catalina.core.ApplicationFilterChain doFilter 173

org.apache.catalina.core.ApplicationDispatcher invoke 672

org.apache.catalina.core.ApplicationDispatcher processRequest 463

org.apache.catalina.core.ApplicationDispatcher doForward 398

org.apache.catalina.core.ApplicationDispatcher forward 301

org.apache.jsp.index_jsp _jspService 101

org.apache.jasper.runtime.HttpJspBase service 97

javax.servlet.http.HttpServlet service 810

org.apache.jasper.servlet.JspServletWrapper service 332

org.apache.jasper.servlet.JspServlet serviceJspFile 314

org.apache.jasper.servlet.JspServlet service 264

javax.servlet.http.HttpServlet service 810

org.apache.catalina.core.ApplicationFilterChain internalDoFilter 252

org.apache.catalina.core.ApplicationFilterChain doFilter 173

org.jboss.web.tomcat.filters.ReplyHeaderFilter doFilter 96

org.apache.catalina.core.ApplicationFilterChain internalDoFilter 202

org.apache.catalina.core.ApplicationFilterChain doFilter 173

org.apache.catalina.core.StandardWrapperValve invoke 213

org.apache.catalina.core.StandardContextValve invoke 178

org.jboss.web.tomcat.security.SecurityAssociationValve invoke 175

org.jboss.web.tomcat.security.JaccContextValve invoke 74

org.apache.catalina.core.StandardHostValve invoke 126

org.apache.catalina.valves.ErrorReportValve invoke 105

org.apache.catalina.core.StandardEngineValve invoke 107

org.apache.catalina.connector.CoyoteAdapter service 148

org.apache.jk.server.JkCoyoteHandler invoke 199

org.apache.jk.common.HandlerRequest invoke 282

org.apache.jk.common.ChannelSocket invoke 754

org.apache.jk.common.ChannelSocket processConnection 684

org.apache.jk.common.ChannelSocket$SocketConnection runIt 876

org.apache.tomcat.util.threads.ThreadPool$ControlRunnable run 684

java.lang.Thread run 595

HEADERS

Header Value

host localhost

user-agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.9) Gecko/20061206 Firefox/1.5.0.9

accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5

accept-language en-us,en;q=0.5

accept-encoding gzip,deflate

accept-charset ISO-8859-1,utf-8;q=0.7,*;q=0.7

Keep-Alive 300

connection keep-alive

cookie JSESSIONID=76AA6A57011A7CF3ABF8F5C3B9B35389

Cache-Control max-age=0

content-length 0

ATTRIBUTES

Attribute Value

javax.servlet.forward.request_uri /testformbean/

javax.servlet.forward.context_path /testformbean

javax.servlet.forward.servlet_path /index.jsp

product edu.msu.hit.testformbean.forms.ProductFormBean@354949

pageTitle testformbean: ERROR!!!

formclass edu.msu.hit.testformbean.forms.ProductFormBean

pageErrorObj org.apache.jasper.JasperException: Unable to compile class for JSP

pageError Unable to compile class for JSP

Please check the system logs for more information.

......whew !sorry for the long-winded post, but I cannot seem to

figure out why I'm getting that NumberFormatException.

There is nothing in the headers or attributes that I can see that might

cause it. I'm just putting the bean itself and a couple of strings into

the request; otherwise, it should be normal, unless I'm missing

something else.

I used another JSP file to display the bean items that were passed,

and they seem to display correctly after being passed by index.jsp:

testformbean.jsp:

<%@ page language="java"%>

<%@ page import="java.util.*"%>

<%@ page import="java.util.Iterator"%>

<%@ page import="java.lang.reflect.*"%>

<%@ page import="edu.msu.hit.lib.forms.*"%>

<%@ page import="edu.msu.hit.testformbean.forms.*"%>

<% String pTitle = (String)request.getAttribute("pageTitle"); %>

<jsp:include page="./header.jsp">

<jsp:param name="pageTitle" value="<%= pTitle%>" />

<jsp:param name="page" value="index" />

</jsp:include>

<body>

<center>

<h3>Form Bean Test Page</h3>

<table border="0" cellpadding="2" cellspacing="0">

<tr>

<td valign="top" colspan="2" align="center">

ProductFormBean field list

</td>

</tr>

<tr>

<th align="center">Element</th>

<th align="center">Class</th>

</tr>

<%

Iterator iterator=null;

FormBean form = (ProductFormBean)request.getAttribute("product");

//Object oc = request.getAttribute("formclass");

//Class cc = Class.forName("java.lang.String");

//String formClass = (String) cc.newInstance();

//System.out.println("testformbean: class passed: " + formClass);

//Object o = request.getAttribute("form");

//Class c = Class.forName(formClass);

//ProductFormBean form2 = (ProductFormBean) c.newInstance();

System.out.println("testformbean: bean passed: " + form.getName());

String collection = form.getName();

try {

Object object = null;

System.out.println("testFormbean: collection = [" + collection + "]");

//object = pageContext.getAttribute(collection, scope);

//object = form;

object = (ProductFormBean)request.getAttribute("product");

//if (object == null)

// object = pageContext.findAttribute(collection);

if (object == null) {

System.out.println(

"testFormbean: could not find "

+ "the ["

+ collection

+ "] object to iterate");

//return SKIP_BODY;

}

Class[] params = new Class[0];

Method method;

//--

// Use the formbean's 'getIterator()' method to get

// the list of formfieldbeans.

// the collection is in the TreeSet 'repeatFields' in

// FormBean.java.

// The Reflection API is used in this case because

// IterateTag has no way of knowing the object's type

// until runtime, if IterateTag is to remain a general-

// purpose Iteration utility.

//--

//System.out.println("iteratetag: object = [" + object.getClass() + "]");

if (object instanceof java.util.TreeSet)

method = object.getClass().getMethod("iterator", params);

else

method = object.getClass().getMethod("getIterator", params);

System.out.println("iteratetag: doStartTag(): method = " + method);

Object[] args = new Object[0]; // empty argument list

iterator = (Iterator) method.invoke(object, args);

} catch (NoSuchMethodException e1) {

System.out.println("testFormbean: Exception " + e1);

//return SKIP_BODY;

} catch (IllegalAccessException e2) {

System.out.println("testFormbean: Exception " + e2);

//return SKIP_BODY;

} catch (InvocationTargetException e3) {

System.out.println("testFormbean: Exception " + e3);

//return SKIP_BODY;

} catch (ClassCastException e4) {

System.out.println("testFormbean: Exception " + e4);

//return SKIP_BODY;

} catch (NullPointerException e5) {

System.out.println("testFormbean: Exception " + e5);

//return SKIP_BODY;

} catch (Exception e99) {

System.out.println("testFormbean: Exception " + e99);

//return SKIP_BODY;

}

if ( (iterator != null)

&& (iterator.hasNext()))

{

while (iterator.hasNext()) {

Object element = iterator.next();

String elemStr = element.toString();

Class c = element.getClass();

String classStr = c.toString();

FormFieldBean field = (FormFieldBean)element;

String ffPrompt = field.getPrompt() + " (" + field.getID() + ")";

String ffHtml = field.getHtml();

%>

<tr>

<td><%= elemStr%></td>

<td><%= classStr%></td>

</tr>

<tr>

<td><%= ffPrompt%></td>

<td><%= ffHtml%></td>

</tr>

<%

}

}

%>

</table>

</center>

</body>

</html>

the TLD file is pretty standard for the tags, I don't see anything there, but

if anyone wants to see it, please let me know.

So the problem appears to be where the

dispatcher.forward(request, response);

statement is executed, but there seems to be no indication of

exactly what in the request is causing the trouble.

Any advice would be welcomed.

I can also post the beans for the Product DB, but that does not

appear to be relevant to this issue, unless I'm missing something.

Happy New Year, all.

[56055 byte] By [tjclifforda] at [2007-11-26 14:50:00]
# 1

[nobr]Sorry about the formatting in my post....I'm hoping this one will

show it better......

I'm having difficulty with trying to include a formbean inside a request to

another jsp page.

I'm running JBoss 4.0.4GA, JSDK 1.5, Windows XP, Apache 2.0.59,

and I'm using some of David Harms' code that he published in his 2001

Book, "JSP, Servlets and MySQL".

I'll post as much of the code here as the forum will allow.....

JSP:

index.jsp:

--

<%@ page language="java"%>

<%@ page import="java.util.Enumeration"%>

<%@ page import="javax.servlet.*"%>

<%@ page import="javax.servlet.http.*"%>

<%@ page import="edu.msu.hit.lib.forms.*"%>

<%@ page import="edu.msu.hit.testformbean.forms.*"%>

<jsp:include page="./header.jsp">

<jsp:param name="pageTitle" value="TestFormBean" />

<jsp:param name="page" value="index" />

</jsp:include>

<body>

<%

String errorPage = "/syserror.jsp";

String forwardPage = "/testformadd.jsp";

ProductFormBean form = new ProductFormBean();

System.out.println("testformbean: bean created: " + form.getName());

request.setAttribute("product", form);

request.setAttribute("formclass", "edu.msu.hit.testformbean.forms.ProductFormBean");

request.setAttribute("pageTitle", forwardPage);

RequestDispatcher dispatcher;

try {

dispatcher = getServletContext().getRequestDispatcher(forwardPage);

if (dispatcher != null) {

dispatcher.forward(request, response);

}

} catch (Exception ie) {

//System.out.println("ProdControl: Exception!!");

//System.out.println("ProdControl: msg: " + e.getMessage());

request.setAttribute("pageError",ie.getMessage());

request.setAttribute("pageErrorObj",ie);

request.setAttribute("pageTitle", "testformbean: ERROR!!!");

//uri = systemErrorHtml;

dispatcher = getServletContext().getRequestDispatcher(errorPage);

if (dispatcher != null) {

dispatcher.forward(request, response);

}

}

%>

</body>

</html>

testformadd.jsp:

--

<%@ page language="java"%>

<%@ page import="edu.msu.hit.lib.forms.*"%>

<%@ page import="edu.msu.hit.testformbean.forms.*"%>

<%@ taglib uri="/WEB-INF/tlds/hitlib.tld" prefix="hit" %>

<%@ taglib uri="/WEB-INF/tlds/products.tld" prefix="prodtag" %>

<jsp:include page="./header.jsp">

<jsp:param name="pageTitle" value="<%= request.getAttribute("pageTitle")%>" />

<jsp:param name="page" value="index" />

</jsp:include>

<%

FormBean form2 = (ProductFormBean)request.getAttribute("product");

//Object oc = request.getAttribute("formclass");

//Class cc = Class.forName("java.lang.String");

//String formClass = (String) cc.newInstance();

//System.out.println("testformbean: class passed: " + formClass);

//Object o = request.getAttribute("form");

//Class c = Class.forName(formClass);

//ProductFormBean form2 = (ProductFormBean) c.newInstance();

System.out.println("testformbean: bean passed: " + form2.getName());

%>

<body>

<br>

<center>

<h3>Form Bean Test Page</h3>

<prodtag:prodform formName="product">

<hit:formField formName="product" fieldName="formID"/>

<table border="1" cellpadding="2" cellspacing="0">

<tr>

<td width="100%" valign="top" colspan="2" align="center">

Product Add

</td>

</tr>

<tr>

<td align="center">Field Name</td>

<td align="center">Field Html</td>

</tr>

<hit:iterate

collection="product"

iteratedItemName="formField"

iteratedItemClass="edu.msu.hit.lib.forms.FormFieldBean"

scope="request">

<tr>

<td align="right" valign="top">

<%if ( request.getAttribute("formField") != null) { %>

<jsp:getProperty name="formField" property="prompt"/>

<!-- prodtag:formField formName="product" fieldName="prompt"/ -->

<%} else { %>

NULL Prompt

<%} %>

</td>

<td align="left" valign="top">

<%if ( request.getAttribute("formField") != null) { %>

<jsp:getProperty name="formField" property="html"/>

<!-- prodtag:formField formName="product" fieldName="html"/ -->

<%} else { %>

NULL Html

<%} %>

</td>

</tr>

</hit:iterate>

<tr>

<td width="100%" valign="top" colspan="2">

<br>

<p align="center">

<hit:formField formName="product" fieldName="sid"/>

<hit:formField formName="product" fieldName="submit"/>

</td>

</tr>

</table>

</prodtag:prodform>

</center>

</body>

</html>

as you can see, the testformadd.jsp uses tags to display the

form fields, which are created in the ProductFormBean.java

class. I've posted the classes (including the tags and the form beans)

below....

ProductFormBean.java:

--

/*

* This is a class that models a form to

* add/modify Products.

*

* A form bean to display a form for adding a product,

* and to validate data.

*

* Revisions

* WhenWho What

* -- -

* 20061017 tjc Started writing it.

* 20070108 tjc Made one bean for products, to handle add/modify.

*

*/

package edu.msu.hit.testformbean.forms;

import javax.naming.InitialContext;

import java.io.*;

import java.util.*;

import edu.msu.hit.demo.util.*;

import edu.msu.hit.demo.ejb.product.*;

import edu.msu.hit.demo.ejb.productmanager.*;

import java.sql.*;

import edu.msu.hit.lib.forms.*;

public class ProductFormBean extends FormBean {

private static final String EJBPATH = "test/ejb/";

private static final String MGRPATH = "test/manager/";

private static final String PRODMGR_COMP = EJBPATH + "ProductManagerHome";

private boolean adding=true;

private Integer updateid=null;

private Integer productid=null;

private String productdesc=null;

private Integer producttype=null;

FormFieldTextBean f0 = null;

FormFieldTextBean f1 = null;

FormFieldSelectBean f2 = null;

public ProductFormBean() {

super();

setName("product");

setFormPage("/productform.jsp");

setFormDonePage("/productadded.jsp");

setPageTitle("Product Management Page");

f0 = new FormFieldTextBean("fprod0id",10);

//f0.setMessage("Id cannot be blank and must be numeric !");

f0.setPrompt("Id:");

addField(f0);

addRepeatField(f0);

f1 = new FormFieldTextBean("fprod1desc",50);

//f1.setMessage("Description cannot be blank !");

f1.setPrompt("Description:");

addField(f1);

addRepeatField(f1);

f2 = new FormFieldSelectBean("fprod2type", "Product Type",

getTypes(), 0);

//f2.setOptionsClass("edu.msu.hit.demo.ejb.product.FormSelectTO");

//f2.setMessage("Please select one type!");

f2.setPrompt("Type:");

addField(f2);

addRepeatField(f2);

FormFieldSubmitBean f99 = new FormFieldSubmitBean("Save Product");

f99.setRequired(true);

addField(f99);

addRepeatField(f99);

}

public void setAdd(boolean inputadd) {

adding = inputadd;

}

public boolean setId(Integer inputid) {

updateid = inputid;

if (!retrieve()) {

return false;

} else {

f0.setValue(productid.toString());

f1.setValue(productdesc);

f2.setValue(producttype.toString());

}

return true;

}

/*

public String getProductid() { return f0.getHtml(); }

public String getProductdesc() { return f1.getHtml(); }

public String getProducttype() { return f2.getHtml(); }

*/

// --

// this routine gets the product types as a collection

// so the drop-down list can be populated.

private Collection getTypes() {

Collection allTypes = null;

try {

// Create initial context

InitialContext ctx = new InitialContext();

// set up product manager sessionbean

Object obj = ctx.lookup("test/ejb/ProductManagerHome");

ProductManagerHome home = (ProductManagerHome)

javax.rmi.PortableRemoteObject.narrow(obj,ProductManagerHome.class);

//ProductManagerHome home = (ProductManagerHome) obj;

ProductManager productManager = home.create();

allTypes = productManager.getProductTypeList();

} catch(Exception e) {

System.out.print("ProdAddFormBean: save(): ");

System.out.println("Exception: " + e.getMessage());

//out.println();

//e.printStackTrace();

return null;

}

return allTypes;

}

public boolean validate()

{

// validate data entered in this form

formErrors = false;

String idvalue = getFieldValue("fprod0id");

if ( (idvalue == null)

|| (idvalue.length() == 0)

|| (idvalue.equals(" "))

) {

f0.setError("This field cannot be blank or zero!");

formErrors = true;

//return false;

} else {

try {

//update_productid = Integer.parseInt(idvalue);

productid = new Integer(idvalue);

} catch (NumberFormatException nfe) {

f0.setError("This field must be numeric!!");

formErrors = true;

}

//} catch (Exception e) {

//f0.setError("This field must be numeric!!");

//formErrors = true;

//}

}

setNewForm(false);

if (formErrors == false) {

try {

// Create initial context for JNDI lookups.

InitialContext ctx = new InitialContext();

// set up product manager sessionbean

Object obj = ctx.lookup(PRODMGR_COMP);

ProductManagerHome home = (ProductManagerHome)

javax.rmi.PortableRemoteObject.narrow(obj,ProductManagerHome.class);

//ProductManagerHome home = (ProductManagerHome) obj;

ProductManager productManager = home.create();

ProductTO prodTO = productManager.getProduct(productid);

if (prodTO != null) {

f0.setError("This product ID already exists!!");

formErrors = true;

}

} catch(Exception e) {

System.out.print("ProdAddFormBean: validate(): ");

System.out.println("Exception: " + e.getMessage());

e.printStackTrace();

}

}

String descvalue = getFieldValue("fprod1desc");

if ( (descvalue == null)

|| (descvalue.length() == 0)

|| (descvalue.equals(" "))

) {

f1.setError("This field cannot be blank!");

formErrors = true;

} else {

productdesc = descvalue;

}

String typevalue = getFieldValue("fprod2type");

if ( (typevalue == null)

|| (typevalue.length() == 0)

|| (typevalue.equals(" "))

) {

//formErrors = true;

f2.setError("You must select a type !");

} else {

//producttype = typevalue;

try {

//update_productid = Integer.parseInt(idvalue);

producttype = new Integer(typevalue);

} catch (NumberFormatException nfe) {

f2.setError("This field must be numeric!!");

formErrors = true;

}

}

if (areErrors())

return false;

else

return true;

}

public boolean update()

{

//String idvalue = getFieldValue("fproductid");

//Integer idint = new Integer(idvalue);

//String descvalue = getFieldValue("fproductdesc");

//String typevalue = getFieldValue("fproducttype");

//Integer typeint = new Integer(producttype);

try {

// Create initial context for JNDI lookups.

InitialContext ctx = new InitialContext();

// set up product manager sessionbean

Object obj = ctx.lookup(PRODMGR_COMP);

ProductManagerHome home = (ProductManagerHome)

javax.rmi.PortableRemoteObject.narrow(obj,ProductManagerHome.class);

//ProductManagerHome home = (ProductManagerHome) obj;

ProductManager productManager = home.create();

boolean upd_rc

= productManager.updateProduct( productid, productdesc, producttype );

if (!upd_rc) return false;

} catch(Exception e) {

System.out.print("ProdAddFormBean: update(): ");

System.out.println("Exception: " + e.getMessage());

//out.println();

e.printStackTrace();

return false;

}

return true;

}

private boolean retrieve()

{

//String idvalue = getFieldValue("fproductid");

//Integer idint = new Integer(idvalue);

//String descvalue = getFieldValue("fproductdesc");

//String typevalue = getFieldValue("fproducttype");

//Integer typeint = new Integer(producttype);

try {

// Create initial context for JNDI lookups.

InitialContext ctx = new InitialContext();

// set up product manager sessionbean

Object obj = ctx.lookup(PRODMGR_COMP);

ProductManagerHome home = (ProductManagerHome)

javax.rmi.PortableRemoteObject.narrow(obj,ProductManagerHome.class);

//ProductManagerHome home = (ProductManagerHome) obj;

ProductManager productManager = home.create();

ProductTO prodto

= productManager.getProduct( updateid );

if (prodto == null) return false;

productid = prodto.productId;

productdesc = prodto.productName;

producttype = prodto.productType;

} catch(Exception e) {

System.out.print("ProductFormBean: retrieve(): ");

System.out.println("Exception: " + e.getMessage());

//out.println();

e.printStackTrace();

return false;

}

return true;

}

public void save() {

return;

}

}

FormBean.java:

--

/*

* A generic class for modeling an HTML form.

*

* This is the base class for form field beans for all

* HTML forms.

*

* Revisions

* WhenWho What

* -- -

* 20061017 tjc Started writing it.

* 20061218 tjc Added getTypes() method.

* 20061228 tjc Adapted for general use.

*

*/

package edu.msu.hit.lib.forms;

import java.util.*;

//import java.sql.Connection;

import javax.naming.InitialContext;

import javax.servlet.http.*;

import javax.servlet.ServletContext;

import java.util.ArrayList;

import edu.msu.hit.lib.forms.*;

/** A bean that handles common form tasks.

*

*/

public abstract class FormBean implements edu.msu.hit.lib.util.Message {

private String method="POST";

private String action="";

protected HashMap fieldsMap;

protected HashMap fielderrorsMap;

private String uri="";

private HashMap params;

private boolean newForm=true;

protected boolean formErrors=false;

private String name="form";

private String formPage;

private String formDonePage;

private String message;

private String footer="</form>";

private String pageTitle;

private TreeSet repeatFields=null;

protected HttpServletRequest request=null;

protected HttpServletResponse response=null;

protected ServletContext context=null;

public FormBean() {

super();

fieldsMap = new HashMap();

fielderrorsMap = new HashMap();

FormFieldHiddenBean field = new FormFieldHiddenBean("formID","true");

addField(field);

repeatFields = new TreeSet();

}

public FormBean(String newFormPage,String newFormDonePage) {

this();

setFormPage(newFormPage);

setFormDonePage(newFormDonePage);

}

public void addField(FormFieldBean formField){

fieldsMap.put(formField.getID(),formField);

}

public void addError(String formFieldId, String errormsg){

fielderrorsMap.put(formFieldId,errormsg);

formErrors = true;

}

public String getError(String formFieldId){

return (String)fielderrorsMap.get(formFieldId);

}

public void addRepeatField(FormFieldBean formField){

repeatFields.add(formField);

}

public java.lang.String getAction() {

return action;

}

public Object getField(String fieldID){

Object f = fieldsMap.get(fieldID);

return f;

}

public String getFieldValue(String fieldName) {

FormFieldBean field = (FormFieldBean) getField(fieldName);

if (field != null)

return field.getValue();

else return "";

}

public String getFieldValueEscaped(String fieldName) {

FormFieldBean field = (FormFieldBean) getField(fieldName);

if (field != null)

return field.getValueEscaped();

else return "";

}

public java.lang.String getFooter() {

return footer;

}

public java.lang.String getFormDonePage() {

return formDonePage;

}

public java.lang.String getFormPage() {

return formPage;

}

public java.lang.String getHeader() {

StringBuffer sb = new StringBuffer("<form method=\"");

sb.append(getMethod());

sb.append("\" action=\"");

sb.append(getAction());

sb.append("\">");

return(sb.toString());

}

public java.util.Iterator getIterator() {

if (repeatFields == null) repeatFields = new TreeSet();

return repeatFields.iterator();

}

public java.lang.String getMessage() {

return message;

}

public java.lang.String getMethod() {

return method;

}

public java.lang.String getName() {

return name;

}

public java.lang.String getFormName() {

return name;

}

public java.lang.String getPageTitle() {

return pageTitle;

}

public java.util.TreeSet getRepeatFields() {

return repeatFields;

}

public java.lang.String getUri() {

return uri;

}

public boolean isNewForm() {

return newForm;

}

public boolean areErrors() {

return formErrors;

}

//public abstract void save(Connection conn);

public abstract void save();

public void setAction(java.lang.String newAction) {

action = newAction;

}

public void setFieldValue(String fieldName, String newValue) {

FormFieldBean field = (FormFieldBean)getField(fieldName);

if (field != null)

field.setValue(newValue);

}

public void setFormDonePage(java.lang.String newFormDonePage) {

formDonePage = newFormDonePage;

}

public void setFormPage(java.lang.String newFormPage) {

formPage = newFormPage;

}

public void setMessage(java.lang.String newMessage) {

message = newMessage;

}

public void setMethod(java.lang.String newMethod) {

method = newMethod;

}

public void setName(java.lang.String newName) {

name = newName;

}

public void setFormName(java.lang.String newName) {

name = newName;

}

public void setPageTitle(java.lang.String newTitle) {

pageTitle = newTitle;

}

public void setNewForm(boolean newNewForm) {

newForm = newNewForm;

}

public void setParameters(HashMap requestParams) {

/*

System.out.println("setting form parameters");

String[] paramValues;

FormFieldBean field;

// Look for the FormID hidden field in the form.

// If found, this is a GET or POST of the form.

if (requestParams.containsKey("formID")) {

System.out.println("found the formID hidden field");

paramValues = (String[]) requestParams.get("formID");

if (paramValues[0].equals("true"))

setNewForm(false);

System.out.println("setting NewForm to false");

} else {

System.out.println("did not find the formID hidden field");

}

System.out.println("new form: " + isNewForm());

if (!isNewForm()) {

Iterator iterator = fieldsMap.values().iterator();

while (iterator.hasNext()) {

// get the next form field

field = (FormFieldBean) iterator.next();

// look for a match in the request parameters

if (requestParams.containsKey(field.getID())) {

System.out.println("found a match for form field " + field.getID());

// get the parameter values from the request

paramValues = (String[]) requestParams.get(field.getID());

// only the first element of the array is used at present

field.setValue(paramValues[0]);

} else {

System.out.println("found a match for form field " + field.getID());

field.clear();

}

}

}

*/

}

public void setServletInfo(

javax.servlet.http.HttpServletRequest newRequest,

javax.servlet.http.HttpServletResponse newResponse,

javax.servlet.ServletContext newContext)

{

request = newRequest;

response = newResponse;

context = newContext;

Enumeration e = request.getParameterNames();

java.util.HashMap requestParams = new java.util.HashMap();

System.out.println("FormBean: form: [" + getName() + "]");

System.out.println("FormBean: setting form parameters");

while (e.hasMoreElements()) {

String key = (String) e.nextElement();

String[] values = request.getParameterValues(key);

requestParams.put(key, values);

System.out.println("key: [" + key + "] values: [" + values.toString() + "]");

}

String[] paramValues;

FormFieldBean field;

// Look for the FormID hidden field in the form.

// If found, this is a GET or POST of the form.

//if (requestParams.containsKey("formID")) {

//System.out.println("found the formID hidden field");

//paramValues = (String[]) requestParams.get("formID");

//if (paramValues[0].equals("true"))

//setNewForm(false);

//System.out.println("setting NewForm to false");

//} else {

//System.out.println("did not find the formID hidden field");

//}

System.out.println("FormBean: new form: " + isNewForm());

if (!isNewForm()) {

Iterator iterator = fieldsMap.values().iterator();

while (iterator.hasNext()) {

// get the next form field

field = (FormFieldBean) iterator.next();

// look for a match in the request parameters

if (requestParams.containsKey(field.getID())) {

//System.out.println("found a match for form field " + field.getID());

// get the parameter values from the request

paramValues = (String[]) requestParams.get(field.getID());

// only the first element of the array is used at present

field.setValue(paramValues[0]);

} else {

//System.out.println("found a match for form field " + field.getID());

field.clear();

}

}

}

}

public void setUri(java.lang.String newUri) {

uri = newUri;

}

public boolean validate() {

Iterator iterator = fieldsMap.values().iterator();

FormFieldBean field;

while (iterator.hasNext()) {

// get the next form field

field = (FormFieldBean) iterator.next();

if (!field.validate()) {

//setMessage(field.getMessage());

addError(field.getName(), field.getMessage());

//return false;

}

}

return true;

}

//public boolean validate(Connection conn) {

//return(validate());

//}

}

FormFieldBean.java:

--

/** A generic class for modeling an HTML form field.

*

* This is a form field bean

*

* Revisions

* WhenWho What

* -- -

* 20061101 tjc Started writing it.

* 20061228 tjc Adapt for general use, in particular for use

* in the MOCF Ball app.

*

*/

package edu.msu.hit.lib.forms;

public abstract class FormFieldBean

implements edu.msu.hit.lib.util.Message, Comparable {

private String type=null;

private String name=null;

private String prompt=null;

private String ID="";

private String value="";

private String error="";

private int width=25;

private int height=1;

private String html="";

private boolean required=false;

private String message="";

private boolean greyed=false;

private boolean hidden=false;

private boolean visible=true;

public FormFieldBean() {

super();

}

public void clear() {

value = "";

}

public int compareTo(java.lang.Object o){

FormFieldBean otherField = (FormFieldBean)o;

return(getID().compareTo(otherField.getID()));

}

public int getHeight() {

return height;

}

public abstract java.lang.String getHtml();

public java.lang.String getID() {

return ID;

}

public java.lang.String getMessage() {

return message;

}

public java.lang.String getName() {

return name;

}

public java.lang.String getPrompt() {

if (prompt != null)return prompt;

if (name != null) return name;

if (ID != null) return ID;

return("unknown field");

}

public java.lang.String getType() {

return type;

}

public java.lang.String getValue() {

return value;

}

public java.lang.String getError() {

return error;

}

public java.lang.String getValueEscaped() {

if (value == null) return (null);

StringBuffer result = new StringBuffer();

for (int i = 0; i < value.length(); i++) {

char ch = value.charAt(i);

if (ch == '\'')

result.append("''");

else

result.append(ch);

}

return (result.toString());

}

public int getWidth() {

return width;

}

public boolean isRequired() {

return required;

}

public void setHeight(int newHeight) {

height = newHeight;

}

public void setID(java.lang.String newID) {

ID = newID;

}

public void setMessage(java.lang.String newMessage) {

message = newMessage;

}

public void setName(java.lang.String newName) {

name = newName;

}

public void setPrompt(java.lang.String newPrompt) {

if (newPrompt != null) prompt = newPrompt;

}

public void setRequired(boolean newRequired) {

required = newRequired;

}

public void setType(java.lang.String newType) {

if (newType != null) type = newType;

}

public void setValue(java.lang.String newValue) {

if (newValue != null) {

value = newValue;

}

}

public void setError(java.lang.String newError) {

if (newError != null) error = newError;

}

public void setGreyed(boolean newGreyed) {

greyed = newGreyed;

}

public void setHidden(boolean newHidden) {

hidden = newHidden;

}

public void setVisible(boolean newVisible) {

visible = newVisible;

}

public boolean getGreyed() {

return greyed;

}

public boolean getHidden() {

return hidden;

}

public boolean getVisible() {

return visible;

}

public void setWidth(int newWidth) {

width = newWidth;

}

public boolean validate(){

if ( (isRequired()) && (value.equals("")) ) {

setMessage("The field \"" + getPrompt()

+ "\" is required");

setError("The field \"" + getPrompt()

+ "\" is required");

return false;

}

else return true;

}

}

FormTag.java:

-

/*

* A tag to create an HTML form.

*

* Revisions

* WhenWho What

* -- -

* 20061215 tjc Started writing it.

*

*/

package edu.msu.hit.lib.taglib;

import javax.servlet.jsp.tagext.*;

import javax.servlet.jsp.*;

import javax.servlet.*;

import java.io.IOException;

import edu.msu.hit.lib.forms.*;

public class FormTag extends TagSupport {

private String formName;

private String formClass;

private FormBean form=null;

public int doEndTag() throws JspException {

JspWriter out = pageContext.getOut();

try {

if (form != null)

out.print(form.getFooter());

else out.print("</form>");

} catch (IOException e) {

throw new JspException(e.toString());

}

return EVAL_PAGE;

}

public int doStartTag() throws JspException {

System.out.println("FormTag doStartTag");

ServletRequest request = pageContext.getRequest();

try {

//form = (FormBean)request.getAttribute(getFormName());

//Object o = request.getAttribute("form");

//Object o2 = request.getAttribute("formclass");

//Class c2 = Class.forName("java.lang.String");

//formClass = (String) o2.toString();

//Class c = Class.forName(formClass);

//form = (FormBean)request.getAttribute("form");

//form = (FormBean) c.newInstance();

//formClass = (String) pageContext.getAttribute("formclass");

//form = (FormBean) pageContext.getAttribute("form");

form = (FormBean)request.getAttribute(getFormName());

} catch (ClassCastException e) {

throw new JspException("FormTag class cast exception");

/*

} catch (ClassNotFoundException e) {

throw new JspException("FormTag class NOTFOUND exception");

} catch (InstantiationException e) {

throw new JspException("FormTag class Instantiation exception");

} catch (IllegalAccessException e) {

throw new JspException("FormTag class IllegalAccess exception");

*/

}

if (form == null) {

System.out.println("formbean is null, skipping form");

return SKIP_BODY;

} else {

System.out.println("FormTag form retrieved: [" + form.getName() + "]");

}

JspWriter out = pageContext.getOut();

try {

out.print(form.getHeader());

} catch (IOException e) {

throw new JspException(e.toString());

}

return EVAL_BODY_INCLUDE;

}

public java.lang.String getFormName() {

return formName;

}

public void setFormName(java.lang.String newFormName) {

formName = newFormName;

}

}

FormFieldTag.java:

/*

* A custom tag to display an HTML form field

*

* Revisions

* WhenWho What

* -- -

* 20061215 tjc Started writing it.

*

*

*/

package edu.msu.hit.lib.taglib;

import javax.servlet.jsp.tagext.*;

import javax.servlet.jsp.*;

import javax.servlet.*;

import java.io.IOException;

import edu.msu.hit.lib.forms.*;

public class FormFieldTag extends TagSupport {

private String formName;

private String fieldName;

private String attribute=null;

public int doStartTag() throws JspException {

ServletRequest request = pageContext.getRequest();

System.out.println("FormFieldTag doStartTag");

FormBean fb = null;

try {

fb = (FormBean)request.getAttribute(getFormName());

} catch (ClassCastException e) {

System.out.println("FormFieldTag: FormTag class cast exception on " + getFormName());

return SKIP_BODY;

}

if (fb == null){

System.out.println("FormFieldTag: Unable to create FormBean " + getFormName());

return SKIP_BODY;

}

FormFieldBean field = (FormFieldBean)fb.getField(getFieldName());

if (field == null) {

System.out.println("Unable to get field "

+ getFieldName()

+ " in FormBean " + getFormName());

return SKIP_BODY;

}

System.out.println("FormFieldTag: using formbean " + fb + ", field " + field);

//pageContext.setAttribute(field.getName(),field);

JspWriter out = pageContext.getOut();

try {

if ((attribute != null)

&& (attribute.equalsIgnoreCase("prompt"))){

//System.out.println("prompt text: " + field.getPrompt());

out.print(field.getPrompt());

} else {

//System.out.println("field text: " + field.getHtml());

out.print(field.getHtml());

}

} catch (IOException e) {

throw new JspException(e.toString());

}

return (EVAL_BODY_INCLUDE);

}

public java.lang.String getAttribute() {

return attribute;

}

public java.lang.String getFieldName() {

return fieldName;

}

public java.lang.String getFormName() {

return formName;

}

public void setAttribute(java.lang.String newAttribute) {

attribute = newAttribute;

}

public void setFieldName(java.lang.String newFieldName) {

fieldName = newFieldName;

}

public void setFormName(java.lang.String newFormName) {

formName = newFormName;

}

}

The error trace I'm getting is:

08:06:06,778 INFO [TomcatDeployer] deploy, ctxPath=/testformbean, warUrl=.../tm

p/deploy/tmp15636testformbean-exp.war/

08:06:16,932 INFO [STDOUT] testformbean: bean created: product

08:06:17,150 ERROR [STDERR] java.lang.NumberFormatException: For input string: "

request"

08:06:17,150 ERROR [STDERR]at java.lang.NumberFormatException.forInputStrin

g(NumberFormatException.java:48)

08:06:17,150 ERROR [STDERR]at java.lang.Integer.parseInt(Integer.java:447)

08:06:17,150 ERROR [STDERR]at java.lang.Integer.valueOf(Integer.java:553)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.JspUtil.coerceToIn

t(JspUtil.java:752)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.convertString(Generator.java:2949)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.evaluateAttribute(Generator.java:2752)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.generateSetters(Generator.java:2858)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.generateCustomStart(Generator.java:2176)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.visit(Generator.java:1685)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$CustomTag.acc

ept(Node.java:1441)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Nodes.visit(N

ode.java:2163)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Visitor.visit

Body(Node.java:2213)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator$Generate

Visitor.visit(Generator.java:1705)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$CustomTag.acc

ept(Node.java:1441)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Nodes.visit(N

ode.java:2163)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Visitor.visit

Body(Node.java:2213)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Visitor.visit

(Node.java:2219)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Root.accept(N

ode.java:456)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Node$Nodes.visit(N

ode.java:2163)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Generator.generate

(Generator.java:3305)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Compiler.generateJ

ava(Compiler.java:198)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Compiler.compile(C

ompiler.java:295)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Compiler.compile(C

ompiler.java:276)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.compiler.Compiler.compile(C

ompiler.java:264)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.JspCompilationContext.compi

le(JspCompilationContext.java:563)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.servlet.JspServletWrapper.s

ervice(JspServletWrapper.java:303)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.servlet.JspServlet.serviceJ

spFile(JspServlet.java:314)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.servlet.JspServlet.service(

JspServlet.java:264)

08:06:17,150 ERROR [STDERR]at javax.servlet.http.HttpServlet.service(HttpSe

rvlet.java:810)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationFilterCha

in.internalDoFilter(ApplicationFilterChain.java:252)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationFilterCha

in.doFilter(ApplicationFilterChain.java:173)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationDispatche

r.invoke(ApplicationDispatcher.java:672)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationDispatche

r.processRequest(ApplicationDispatcher.java:463)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationDispatche

r.doForward(ApplicationDispatcher.java:398)

08:06:17,150 ERROR [STDERR]at org.apache.catalina.core.ApplicationDispatche

r.forward(ApplicationDispatcher.java:301)

08:06:17,150 ERROR [STDERR]at org.apache.jsp.index_jsp._jspService(index_js

p.java:101)

08:06:17,150 ERROR [STDERR]at org.apache.jasper.runtime.HttpJspBase.service

(HttpJspBase.java:97)

08:06:17,166 ERROR [STDERR]at javax.servlet.http.HttpServlet.service(HttpSe

rvlet.java:810)

08:06:17,166 ERROR [STDERR]at org.apache.jasper.servlet.JspServletWrapper.s

ervice(JspServletWrapper.java:332)

08:06:17,166 ERROR [STDERR]at org.apache.jasper.servlet.JspServlet.serviceJ

spFile(JspServlet.java:314)

08:06