java - Struts2: repopulating textboxes with List<Integer> after validation -
i have jsp page has code this::
<div id="textboxesgroup"> <div class="control-group"> <label class="control-label" for="inputauto">room type</label> <div class="controls"> <!-- <input type="text" id="inputauto" class="grd-white" /> --> <s:select id="inputauto" data-form="select2" cssstyle="width:200px" data-placeholder="select room type" name="resortroomtype" headerkey="-1" list="roomtypelist"/> </div> </div> <div class="control-group"> <label class="control-label" for="inputauto">room numbers</label> <div class="controls"> <!-- <input type="text" id="inputauto" class="grd-white" /> --> <s:textfield id="inputauto" cssclass="grd-white" name="roomnumbers" onkeypress="return isnumber(event)"/> <s:label name="roomnumbererror" cssclass="help-inline" cssstyle=" color: red;"></s:label> </div> </div> </div> <div > <input type='button' value='+' id='addbutton' class="btn " /> <input type='button' value='-' id='removebutton' class="btn" /> </div>
my js add , remove button is::
<script type="text/javascript"> $(document).ready(function () { $("#addbutton").click(function () { if( ($('#textboxesgroup').children().size()+1) > 12) { alert("resort don't have more rooms" ); return false; } var id = ($('#textboxesgroup').children().size()+1).tostring(); $('#textboxesgroup').append('<div class="control-group" id="control-group"> <label class="control-label" for="inputselectgroup">room type</label> <div class="controls"><select style="width:200px" id="inputselectgroup" name="resortroomtype" data-form="select2"> <option value="single room">single room</option> <option value="double room">double room</option> <option value="twin room">twin room</option> <option value="interconnecting room">interconnecting room</option> <option value="suite">suite</option> <option value="pent house suite">pent house suite</option> </select> </div> </div> <div class="control-group" id="control-group"> <label class="control-label" for="inputauto">number of rooms</label> <div class="controls"> <input type="text" class="grd-white" id="inputauto" name="roomnumbers" onkeypress="return isnumber(event)" > </div> </div>'); }); $("#removebutton").click(function () { if ($('#textboxesgroup').children().size() == 2) { alert("no more textbox remove"); return false; } $('#textboxesgroup').children().last().remove(); $('#textboxesgroup').children().last().remove(); }); }); </script>
and in action class i've ::
private list<integer> roomnumbers; getter/setters;
and i've validate method validate there field empty or not. if empty return input , i'll form page (e.g. add_resort.jsp). ex have input roomtype :: single room roomnumber ::2 , roomtype :: doubleroom roomnumber is:: empty (i forgot enter number) , click button save changes , validation happenes.. when return page in roomnumber text field got value this:::[2,null]
test case::::::
before validation roomnumber =2
after validation roomnumber=[2]
test case::::::
before validation roomnumber =2 roomnumber= null
after validation roomnumber=[2,null]
in validate method
if(roomnumbers != null){ roomnumbers.add(new integer(55)); setroomnumbers(roomnumbers); addfielderror("roomnumbers", "please enter valid room number."); }
Comments
Post a Comment