public class UIAction extends ActionSupport{
private
String username;
private
String password;
public
String getUsername() {
return username ;
}
public
void setUsername(String username) {
this.username = username;
}
public
String getPassword() {
return password ;
}
public
void setPassword(String password) {
this.password = password;
}
/**
* 1.在表单中回显数据:数据位于对象栈中,直接根据表单元素的name数据就可以回显!
* 用户名:<s:textfield name="username"></s:textfield><br/>
密码:<s:password name="password" showPassword="true"></s:password><br/>
*
@return
*/
public
String showDataFromObjStack(){
User user =
new User();
user.setPassword(
"aaa");
user.setUsername(
"bbb");
ActionContext. getContext().getValueStack().push(user);
return "user_objstack" ;
}
/**
* 从map栈中回显数据,s:textfield的value属性不能直接跟 ognl表达式,所以需要加%{ ognl表达式}
*
* 用户名:<s:textfield name=" username" value="%{#user.username}"></s:textfield><br/>
密码: <s:password name="password" showPassword="true" value="%{#user.password}"></s:password><br/>
*
@return
*
*/
public
String showDataFromMap(){
User user =
new User();
user.setPassword(
"111");
user.setUsername(
"zhangsan");
ActionContext. getContext().put(
"user"
, user);
return "user_map" ;
}
/**
* Action中的属性位于对象栈中,在回显时可以直接使用value来回显:
* 用户名:<s:textfield name="username"></s:textfield><br/>
密码: <s:password name="password" showPassword="true" ></s:password><br/>
*
@return
*/
public
String showDataFromActionProperty(){
this.username = "lisi" ;
this.password = "asfd" ;
return "user_actionproperty" ;
}
/**
* 使用s:select标签来显示下拉选择框,必须有list属性;
* jsp:选择省份:<s:select name=" pid" list="#pList" listKey="pid" listValue="pname" headerKey="" headerValue="请选择省份"></s:select> <br/>
* 翻译后的代码:
* 选择省份:
<select id="uiAction_form_action_pid" name="pid">
<option value="">请选择省份
</option>
<option value="1">北京市
</option>
<option value="2">上海市
</option>
<option value="3">重庆市
</option>
</select>
*
@return
*/
public
String putDataToSelect(){
List<Privice> pList =
new ArrayList<Privice>();
Privice privice1 =
new Privice();
privice1.setPid(1L);
privice1.setPname(
"北京市");
Privice privice2 =
new Privice();
privice2.setPid(2L);
privice2.setPname(
"上海市");
Privice privice3 =
new Privice();
privice3.setPid(3L);
privice3.setPname(
"重庆市");
pList.add(privice1);
pList.add(privice2);
pList.add(privice3);
//放在map栈中;
ActionContext. getContext().put(
"pList"
, pList);
return "select_map" ;
}
}
|