Good day all.
In my
jsp page (using Tiles), I have the following javascript snippet:
<head>
<title>
My brain on
struts <picture of the air goes here>
</title>
<script type="text/javascript">
<!--
function pageSubmit(newStartIndex) {
document.forms[0].startIndex.value = newStartIndex
alert(document.forms[0].startIndex.value);
document.forms[0].submit();
}
//-->
</script>
</head>
In the body of the document, I have this:
<html:form
action="/Search"
name="searchForm"
type="com.funwithstruts.archives.formbean.SearchForm">
...
<input type="hidden" name="startIndex"
value="<c
ut value='${startIndex}'/>"/>
<c:forEach var="pageNbr" begin="${1}"
end="${(total+subsetTotal)/subsetTotal}" step="${1}">
<c:set var="newStartIndex" scope="page">
<c
ut value="${(subsetTotal*(pageNbr-1)) + 1}"/>
</c:set>
<c:set var="pageSubmitJS" scope="page">
javascript
ageSubmit(<c
ut value="${newStartIndex}"/>
;
</c:set>
<a href="/archives/Search.do"
oncluck="<c
ut value='${pageSubmitJS}'/>">
Page <c
ut value="${pageNbr}"/>
</a>
<br/>
</c:forEach>
This generates the following links:
<a href="/archives/Search.do" oncluck="javascript
ageSubmit(1);">
Page 1
</a>
<br/>
<a href="/archives/Search.do" oncluck="javascript
ageSubmit(16);">
Page 2
</a>
Here's the problem. When I click on the link, I see the alert box with the expected value (see javascript above). When I System.out.println() the value of startIndex after retrieving it from the action form in the action class, I see the
word "null" instead of what I saw in the alert box. For example, the alert box shows 16, and the action class prints to STDOUT the value "null". (i typed oncluck on purpose so javaranch would post this).
Heres the code in the action class:
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
System.out.println("entering SearchAction.execute()");
// retrieve form object
SearchForm theForm = (SearchForm)form;
// get form attributes
String startIndexString = theForm.getStartIndex();
System.out.println("startIndexString=" + startIndexString);
// just printed "null" here to STDOUT
Any ideas?
Thanks