我有一个JSP页面,其代码如下::
<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>
我的js for add and remove按钮是::
<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 to remove");
return false;
}
$('#TextBoxesGroup').children().last().remove();
$('#TextBoxesGroup').children().last().remove();
});
});
</script>
在我的动作课中我是::
private List<Integer> roomnumbers;
getter/setters;
我有一个验证方法,它将验证是否有任何字段为空。如果为空,那么它将返回INPUT,我将返回到我的表单页面(例如add_resort.jsp)。因此,对于ex我输入像房间类型::单人房间数量是:: 2和房间类型::双人房间数字是::空(我忘了输入数字)然后我点击按钮保存更改和验证发生.. 但当我回到我的房间文本字段中的那个页面时,我得到了类似这样的价值::: [2,null]
测试用例::::::
验证前 roomnumber = 2
验证后roomnumber = [2]
测试用例::::::
验证前 roomnumber = 2 roomnumber = null
验证后roomnumber = [2,空]
验证方法中的
if(roomnumbers != null){
roomnumbers.add(new Integer(55));
setRoomnumbers(roomnumbers);
addFieldError("roomnumbers", "Please Enter valid room number.");
}