我这个例子主要是得到从后台返回的结果反映在前台的checkbox上。
在后台action中首先应该有一个List,用于前天checkbox的迭代:
private List<PropertyBean> propertyList;
PropertyBean有propertyId和propertyName两个属性。另外一点需要注意的是在action中需要记得给propertyList set和get方法。要不然在前天就取不到值了。
private RoomBean room = new RoomBean();//记得set,get方法
room.setPropertyId("1,2");
因为property可能是多个值,所以保存在后台的就可能是1,2这种形式的。
PropertyBean p1 = new PropertyBean();
p1.setPropertyId("1");
p1.setPropertyName("pname1");
PropertyBean p2 = new PropertyBean();
p2.setPropertyId("2");
p2.setPropertyName("pname2");
propertyList.add(p1);
propertyList.add(p2);
我在这里是给propertyList设定了两个值,好让前台有数据可以迭代。
String pro[];
pro=room.getPropertyId().split("[,]+");
List list = new ArrayList();
for (int i = 0; i < pro.length; i++) {
list.add(pro[i]);
}
request.setAttribute("propertyId", list);
这一段代码有点关键,这个主要是在<s:checkboxList>中的value属性。
<s:checkboxlist list="propertyList" label="设施" listKey="propertyId" listValue="propertyName" name="room.propertyId" value="#request.propertyId"></s:checkboxlist>
我来解释下这些属性的含义,list就是我们在后天定义的list的名字,lable是一个标签,这行代码相当于一个tr里面放了两个td,一个td放lable,一个td放checkbox,然后listkey和listvale分别代表list中bean的属性。listvalue是显示在页面上的值。而name值则是为了绑定后台的属性值room,而propertyId是room的一个属性值。value值则是为了使后台返回的数据,如1,2这样的数据与前台进行匹配,如果符合则选中。这个是在request范围中把propertyId取出来。
最后在说一下关于<s:checkboxList>验证是否选中的问题,只需要直接这样子写即可:
var value = document.getElementsByName('room.propertyId');
var length = value.length;
var aa = "";
alert(length);
for(var i = 0 ;i<length;i++){
if(value[i].checked == true){
aa = "哈哈";
}
}
if(aa==""){
alert("请选择");
}
但是有点奇怪的是用这种方式不能获得checkboxlist的焦点,如果有知道的兄弟交流下...
分享到:
相关推荐
<%@ taglib uri="/struts-tags" prefix="s" %> 结合例子,重点掌握以下标签的用法 (1) <s:property> (2) <s:set> (3) <s:if> 、<s:elseif>、<s:else> ...(8) <s:select>、<s:radio>、<s:checkboxlist>
<%@ taglib uri="/struts-tags" prefix="s" %> 结合例子,重点掌握以下标签的用法 (1) <s:property> (2) <s:set> (3) <s:if> 、<s:elseif>、<s:else> ...(8) <s:select>、<s:radio>、<s:checkboxlist>
<s:checkboxlist list=""></s:checkboxlist>-----多选框 <s:combobox list=""></s:combobox>-----下拉框 <s:component></s:component>-----图像符号 D: <s:date/>-----获取日期格式 <s:datetimepicker></s:...
2. <s:checkboxlist list=""></s:checkboxlist>-----多选框 3. <s:combobox list=""></s:combobox>-----下拉框 4. <s:component></s:component>-----图像符号 D: 1. <s:date/>-----获取日期格式 2. <s:...
____ , it's rather durable.</span></strong> <asp:Image ID="Image3" Visible ="false" runat="server" ImageUrl="~/images/错误.gif" /> <asp:RadioButtonList ID="RadioButtonList3" runat="server"> ...
解决struts2里checkboxlist 换行 在struts核心jar包下的template里创建custom文件夹。把该文件放到custom下。替换工程里的jar文件。... value="checkPermission"></s:checkboxlist> </table> </td>
<asp:CheckBoxList ID="CheckBoxList1" runat="server"> <asp:ListItem Value="国家"></asp:ListItem> <asp:ListItem Value="民族"></asp:ListItem> <asp:ListItem Value="文化"></asp:ListItem> </asp:...
asp.net项目开发学校毕业作业 <tr> <td> 用户名</td> <td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> </tr> <tr> <td> 密码</td> <td> <asp:TextBox ID="TextBox2" runat="server...
private void Datagrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) ... <asp:CheckBox ID="id" runat="server"></asp:CheckBox> </ItemTemplate> </asp:TemplateColumn>
<spanstyle="font-size: 16pt"><strong><br/> </strong></span> <tableborder="1"style="text-align: left"> <tr> <tdstyle="width: 125px"> <asp:TextBoxID="txtName"runat="server"Width="77px"></asp:TextBox></...
label="<input type='checkbox' onclick='CheckAll((this.checked))' > 是否提交" > <h:switchCheckbox value="0" checkedValue="1" uncheckedValue="0" /> </r:field> <r:field fieldName="fileName" label=...
<asp:Repeater ID="rptUser" runat="server" onitemcommand="rptUser_... <asp:CheckBox ID="chk" runat="server" /></td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater>
<mx:CheckBox change=" {outerDocument.doSelect(data as Object)} " /> </mx:Component> </mx:itemRenderer> </mx:DataGridColumn> <mx:DataGridColumn headerText="names" dataField="names" width="200" />...
eclipse-testng 离线包<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:math="http://exslt.org/math" xmlns:testng=...
NULL 博文链接:https://xueyue.iteye.com/blog/1158510
C#编程经验技巧宝典源代码,目录如下:<br>第1章 开发环境 1<br><br>1.1 Visual Studio开发环境安装与配置 2<br><br>0001 安装Visual Studio 2005开发环境须知 2<br><br>0002 配置合适的Visual Studio 2005...
<mx:CheckBox id="cbVisible" label="IFrame Visible" selected="true" click="iFrame.visible=cbVisible.selected"/> </mx:ControlBar> </mx:Panel> </mx:HBox> <mx:Script> <![CDATA[ import mx....
、FunctionValidator (允许用户利用外部函数进行校验)<br>InputValidator:<br>值的大小(数值型和字符型)范围、值的长度、选择个数(针对checkbox、radio、select)<br>以上都是个区间范围,大于、小于设定值...
在 开发工作中,因为要做用到CheckBoxList在客户端用js操作,无论js怎样调试,就是无法获取value的值,很是郁闷,后来Google了下,去了趟CodeProject,算是幸运的。我们在网页上放置一下代码: 代码如下: <asp ...
asp.net Dropdownlist结合CheckBoxList多选下拉框