Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Spring java Controller get correct data from button when "apply"button is clicked but not pressing the <Enter> key

Reply
Thread Tools

Spring java Controller get correct data from button when "apply"button is clicked but not pressing the <Enter> key

 
 
albert kao
Guest
Posts: n/a
 
      04-09-2010
The group button in my form is set to "unack".
The Spring ParameterizableViewController (HwController.java) receive
the correct group "unack" when the "apply" button is clicked.
However, the HwController receive the null group when the cursor is
moved to the text box and press the <Enter> key.
Only the data from the button is received incorrectly, the other form
data are received correctly.
Please help so that the HwController will receive the correct group
when the <Enter> key is pressed.
I use Spring 2.5.x to implement JSP.
Eclipse console output:
12:56:52,187 INFO com.mycomp.hw.monitoring.war.HwController:57 -
groupStr unack
12:56:52,187 INFO com.mycomp.hw.monitoring.war.HwController:60 -
group unack
12:56:52,187 INFO com.mycomp.hw.monitoring.war.HwController:71 -
rowsPerPageStr 40
12:56:52,187 INFO com.mycomp.hw.monitoring.war.HwController:80 -
rowsPerPage 40
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:57 -
groupStr null
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:60 -
group all
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:69 -
acked null
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:71 -
rowsPerPageStr 60
12:57:14,156 INFO com.mycomp.hw.monitoring.war.HwController:80 -
rowsPerPage 60

Hw.jsp file:
<script type="text/javascript">
function setgroup() {
var group = 'all';
var elem = document.getElementsByName("radio");
for (var i = 0; i < elem.length; i++) {
if (elem[i].checked) {
group = elem[i].value;
}
}

var rowsPerPageElem = document.getElementById("rowsPerPage");
var rowsPerPage = rowsPerPageElem.value;
var chkelem = document.getElementById("ok");
var ok = chkelem.checked;

window.location = "Hw?rowsPerPage=" + rowsPerPage + "&ok=" + ok +
"&group=" + group;
}
</script>

<form name="form">
<c:set var="allchecked" value=""/>
<c:set var="ackchecked" value=""/>
<c:set var="unackchecked" value=""/>

<c:if test="${group == 'all'}">
<c:set var="allchecked" value="checked"/>
</c:if>
<c:if test="${group == 'ack'}">
<c:set var="ackchecked" value="checked"/>
</c:if>
<c:if test="${group == 'unack'}">
<c:set var="unackchecked" value="checked"/>
</c:if>

<input type="radio" name="radio" value="all" ${allchecked}
onClick="setgroup()"> All
<input type="radio" name="radio" value="ack" ${ackchecked}
onClick="setgroup()"> Acknowledged
<input type="radio" name="radio" value="unack" ${unackchecked}
onClick="setgroup()"> Unacknowledged
</form>

<form name="hwform">
<c:set var="unhwchk" value="" />
<c:if test="${ok}">
<c:set var="unhwchk" value="checked" />
</c:if>
<br><br><input type="checkbox" name="ok" id="ok" ${unhwchk}
onClick="setgroup()">HW
<br>Rows Per Page<input type="text" name="rowsPerPage"
id="rowsPerPage" value="${rowsPerPage}" onsubmit="setgroup()"/>
<input type="button" value="Apply" onClick="setgroup()"><br>
</form>


HwController.java:
public ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String group = "all";
String groupStr = request.getParameter("group");
logger.info("groupStr " + groupStr);
if (groupStr != null)
group = groupStr;
logger.info("group " + group);
}
 
Reply With Quote
 
 
 
 
marisa lee
Guest
Posts: n/a
 
      04-10-2010
On Apr 9, 4:32*pm, albert kao <(E-Mail Removed)> wrote:
> The group button in my form is set to "unack".
> The Spring ParameterizableViewController (HwController.java) receive
> the correct group "unack" when the "apply" button is clicked.
> However, the HwController receive the null group when the cursor is
> moved to the text box and press the <Enter> key.
> Only the data from the button is received incorrectly, the other form
> data are received correctly.
> Please help so that the HwController will receive the correct group
> when the <Enter> key is pressed.
> I use Spring 2.5.x to implement JSP.
> Eclipse console output:
> 12:56:52,187 *INFO com.mycomp.hw.monitoring.war.HwController:57 -
> groupStr unack
> 12:56:52,187 *INFO com.mycomp.hw.monitoring.war.HwController:60 -
> group unack
> 12:56:52,187 *INFO com.mycomp.hw.monitoring.war.HwController:71 -
> rowsPerPageStr 40
> 12:56:52,187 *INFO com.mycomp.hw.monitoring.war.HwController:80 -
> rowsPerPage 40
> 12:57:14,156 *INFO com.mycomp.hw.monitoring.war.HwController:57 -
> groupStr null
> 12:57:14,156 *INFO com.mycomp.hw.monitoring.war.HwController:60 -
> group all
> 12:57:14,156 *INFO com.mycomp.hw.monitoring.war.HwController:69 -
> acked null
> 12:57:14,156 *INFO com.mycomp.hw.monitoring.war.HwController:71 -
> rowsPerPageStr 60
> 12:57:14,156 *INFO com.mycomp.hw.monitoring.war.HwController:80 -
> rowsPerPage 60
>
> Hw.jsp file:
> <script type="text/javascript">
> * function setgroup() {
> * * var group = 'all';
> * * var elem = document.getElementsByName("radio");
> * * for (var i = 0; i < elem.length; i++) {
> * * * *if (elem[i].checked) {
> * * * * * * group = elem[i].value;
> * * * *}
> * * }
>
> * * var rowsPerPageElem = document.getElementById("rowsPerPage");
> * * var rowsPerPage = rowsPerPageElem.value;
> * * var chkelem = document.getElementById("ok");
> * * var ok = chkelem.checked;
>
> * * window.location = "Hw?rowsPerPage=" + rowsPerPage + "&ok=" + ok *+
> "&group=" + group;
> * }
> </script>
>
> <form name="form">
> * * <c:set var="allchecked" value=""/>
> * * <c:set var="ackchecked" value=""/>
> * * <c:set var="unackchecked" value=""/>
>
> * * <c:if test="${group == 'all'}">
> * * * <c:set var="allchecked" value="checked"/>
> * * </c:if>
> * * <c:if test="${group == 'ack'}">
> * * * <c:set var="ackchecked" value="checked"/>
> * * </c:if>
> * * <c:if test="${group == 'unack'}">
> * * * <c:set var="unackchecked" value="checked"/>
> * * </c:if>
>
> * <input type="radio" name="radio" value="all" ${allchecked}
> onClick="setgroup()"> All
> * <input type="radio" name="radio" value="ack" ${ackchecked}
> onClick="setgroup()"> Acknowledged
> * <input type="radio" name="radio" value="unack" ${unackchecked}
> onClick="setgroup()"> Unacknowledged
> </form>
>
> <form name="hwform">
> * <c:set var="unhwchk" value="" />
> * <c:if test="${ok}">
> * * <c:set var="unhwchk" value="checked" />
> * </c:if>
> * <br><br><input type="checkbox" name="ok" id="ok" ${unhwchk}
> onClick="setgroup()">HW
> * <br>Rows Per Page<input type="text" name="rowsPerPage"
> id="rowsPerPage" value="${rowsPerPage}" onsubmit="setgroup()"/>
> * <input type="button" value="Apply" onClick="setgroup()"><br>
> </form>
>
> HwController.java:
> public ModelAndView handleRequestInternal(HttpServletRequest request,
> * * HttpServletResponse response) throws Exception {
> * String group = "all";
> * String groupStr = request.getParameter("group");
> * logger.info("groupStr " + groupStr);
> * if (groupStr != null)
> * * group = groupStr;
> * logger.info("group " + group);
>
>
>
> }

The form is changed to the following.
Now pressing the <Enter> key and clicking the "Apply" button has the
same result - the button value is changed from "ack" to "all".
However, I expect that the button value should not change.
<form name="hwform" onsubmit="setgroup()">
<c:set var="unhwchk" value="" />
<c:if test="${ok}">
<c:set var="unhwchk" value="checked" />
</c:if>
<br><br><input type="checkbox" name="ok" id="ok" ${unhwchk}/>HW
<br>Rows Per Page<input type="text" name="rowsPerPage"
id="rowsPerPage" value="${rowsPerPage}"/>
<input type="submit" value="Apply"/><br>
</form>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple buttons - need to set default button when pressing enter key jyotsna Software 1 12-18-2007 08:51 PM
Form with multiple submits, but pressing enter focuses on the wrong button Matthew Sims Javascript 0 03-04-2004 06:10 PM
Pressing Enter Key from a Textbox (Netscape 4.79) and simulate a button-click GOKU24 Javascript 0 08-26-2003 07:36 PM
Get text in TextBox without pressing Enter key mg ASP .Net 5 07-14-2003 02:09 PM
Python - get key pressing ? Krisztian Kepes Python 2 07-03-2003 02:13 PM



Advertisments