Hello All,
I am having a little problem that hopefully someone can help me with. I
have a form that has a hidden field in it, I am not populating this hidden
field on the page load but rather I am populating the value in a JavaScript
function and then using the form.submit() in JavaScript to submit the form.
When I try pulling the value for the hidden field out in my Action class I
get either a null pointer exception or a zero length string depending on
how I try to get the data. I have verified that there is data populating
in the hidden fields value. Here is the code below, if anyone can help me
in finding out how to get the value I would be very grateful.
/////jsp////
<%@ page language ="java"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<html>
<head>
<title>Report Generator</title>
<LINK REL="stylesheet" TYPE="text/css" HREF="style/style.css">
<script LANGUAGE="JavaScript1.2" SRC="style/select.js"></script>
<script LANGUAGE="JavaScript1.2" SRC="style/report_generator.js"></script>
<script LANGUAGE="JavaScript1.2" SRC="style/dyn_select.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<html:form action="Generator" name="generatorForm" type
="com.kcp.csi.reportgen.GeneratorForm">
<html:hidden property="XMLQueryString"/>
<table width = "100%" border = "0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">
<table width="197" border="0" height="103%" align="left"
valign="top" cellpadding="0" cellspacing="0">
<tr>
<td height="90%" width="193" background
="images/bg_home_03.gif" >
<table width="100%" border="0"
cellspacing="0" cellpadding="0">
<tr>
<td align="left">
<br><html:img src="images/load.gif" onmouseover="runtimeStyle.cursor
= 'hand'" onclick="runClick(document.generatorForm)"/> <br><br>
<html:img onmouseover
="runtimeStyle.cursor = 'hand'" src="images/update.gif" onclick
="getHiddenValue(document.generatorForm)"/> <br> <br>
<html:img onmouseover
="runtimeStyle.cursor = 'hand'" src="images/delete.gif"/> <br><br>
<html:img onmouseover
="runtimeStyle.cursor = 'hand'" src="images/save.gif"/> <br><br>
<html:text property
="saveName"/>
</td>
</tr>
</table>
</td>
</tr>
..... and so on.....
////javascript////
function getHiddenValue(form) // added for
testing
{
alert(form.XMLQueryString.value);
}
function runClick(form)
{
var strQueryXML = new String();
if(form.selectedColumns.options.length > 0)
{
strQueryXML = getQueryXML(form);
form.XMLQueryString.value = strQueryXML;
alert(strQueryXML); // added for testing
alert(form.XMLQueryString.value); // added for testing
form.submit();
}
else
{
alert("Please select at least one column.");
objSelCols.focus();
}
}
////Action Class/////
public class GeneratorAction extends Action
{
private ActionErrors errors = new ActionErrors();
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
HttpSession session = request.getSession();
String sXML = new String();
String target = new String("failure");
if(form != null)
{
errors.clear();
GeneratorForm gForm = (GeneratorForm)form;
try
{
//sXML = gForm.getXMLQueryString(); //0 length
string
sXML = request.getAttribute("XMLQueryString").toString();
//null pointer
//sXML = session.getAttribute("XMLQueryString").toString();
//null pointer
System.out.println("XML String ="+sXML.toString());
target = new String("success");
}
catch(Exception e)
{
System.out.println("Error Getting Attributes "+e);
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError
("errors.dbsubmiterror",sXML));
target = new String("failure");
saveErrors(request,errors);
}
}
return(mapping.findForward(target));
}
}
Thanks
Tim Bachta
Information Technology
MC 48
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>