Skip to Main Content

Java APIs

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!

NumberFormatException: For input string: "request"

843810Jan 11 2007 — edited Jan 11 2007
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>
<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"/>
</p></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
* When Who 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
* When Who 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
* When Who 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
* When Who 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
* When Who 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 !=
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 8 2007
Added on Jan 11 2007
1 comment
330 views