Struts 2 <s:checkbox> checkbox example
来源:互联网 发布:单片机最小系统图 编辑:程序博客网 时间:2024/05/17 08:45
In Struts 2 , you can use the <s:checkbox> tag to create a HTML check box. ThefieldValue=”true” is the actual value that will be submitted by the check box.
<s:checkbox name="checkMe" fieldValue="true" label="Check Me for testing"/>
It will generate the following HTML.
<input type="checkbox" name="checkMe" value="true" id="xx_checkMe"/><input type="hidden" id="__checkbox_xx_checkMe" name="__checkbox_checkMe" value="true"/><label for="resultAction_checkMe" class="checkboxLabel">Check Me for testing</label>
Preselect a checkbox
If you want to preselect a check box, just add a value attribute and set it to true.
<s:checkbox name="checkMe" fieldValue="true" value="true" label="Check Me for testing"/>
It will generate the following HTML.
<input type="checkbox" name="checkMe" value="true" checked="checked" id="xx_checkMe"/><input type="hidden" id="__checkbox_xx_checkMe" name="__checkbox_checkMe" value="true" /><label for="resultAction_checkMe" class="checkboxLabel">Check Me for testing</label>
Struts 2 <s:checkbox> example
A full example to create a check box via Struts 2 <s:checkbox>, and assign submitted check box value to the Action class and display it.
1. Action
Action class with a checkMe boolean property to hold the check box value.
CheckBoxAction.java
package com.mkyong.common.action; import com.opensymphony.xwork2.ActionSupport; public class CheckBoxAction extends ActionSupport{ private boolean checkMe; public boolean isCheckMe() {return checkMe;} public void setCheckMe(boolean checkMe) {this.checkMe = checkMe;} public String execute() { return SUCCESS; } public String display() { return NONE; } }
Result page to use Struts 2 “s:checkbox” tag to create a check box.
checkBox.jsp
<%@ taglib prefix="s" uri="/struts-tags" %><html><head></head> <body><h1>Struts 2 check box example</h1> <s:form action="resultAction" namespace="/"> <h4><s:checkbox name="checkMe" fieldValue="true" label="Check Me for testing"/></h4> <s:submit value="submit" name="submit" /> </s:form> </body></html>
result.jsp
<%@ taglib prefix="s" uri="/struts-tags" %><html> <body><h1>Struts 2 check box example</h1> <h4> CheckBox (CheckMe) value : <s:property value="checkMe"/></h4> </body></html>
3. struts.xml
Link all together ~
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <action name="checkBoxAction" class="com.mkyong.common.action.CheckBoxAction" method="display"><result name="none">pages/checkBox.jsp</result> </action> <action name="resultAction" class="com.mkyong.common.action.CheckBoxAction"><result name="success">pages/result.jsp</result> </action> </package> </struts>
http://localhost:8080/Struts2Example/checkBoxAction.action
http://localhost:8080/Struts2Example/resultAction.action
Reference
- Struts 2 checkbox documentation
转自:http://www.mkyong.com/struts2/struts-2-scheckbox-checkbox-example/
- Struts 2 <s:checkbox> checkbox example
- Struts中的标签s:checkbox用处
- s:checkbox
- Checkbox object example
- Checkbox object example
- Android CheckBox example
- Android Checkbox Example
- struts标签html:checkbox
- Struts Checkbox 动态设置
- struts checkbox 问题
- struts标签html:checkbox
- Struts之checkbox标签
- 关于struts标签checkbox
- checkbox
- checkbox
- CheckBox
- CheckBox
- checkbox
- 转自Lindahua博客《图,谱,马尔可夫过程,聚类结构》
- 博弈论基础知识: 巴什博奕+威佐夫博奕+尼姆博弈(及Staircase);
- H.264资料参考大全
- ubuntu 11.04之后版本安装jdk
- C++编程思想,第十八章《RTTI运行时类型识别》
- Struts 2 <s:checkbox> checkbox example
- #define的作用域
- Android网格布局(GirdView)学习
- error LNK2005: "class CPoint StartPt" (?StartPt@@3VCPoint@@A) already defined in mypicture.obj 解决
- CUDA 矩阵乘法优化
- android获取系统标准时区的时间
- fckeditor编辑器使用
- C语言实现base64编解码
- 高度相同的列Andy-Budd版