[英]Passing value from jsp to Action for java.util.Set
I want to set values for Set
elements of login from JSP . 我想为从JSP登录的
Set
元素设置值。
JSP page: JSP页面:
<form action="Registered" method="post">
<div class="form-group">
<label>Company Name</label>
<s:textfield name="name" value="%{name}" id="name"/>
</div>
<div class="form-group">
<label>Address</label>
<s:textarea name="address" value="%{address}" id="address"/>
</div>
<div class="form-group">
<label>User Name</label>
<s:textfield name="logins[0].userName" value="%{logins[0].userName}" id="userName"/>
</div>
<div class="form-group">
<label>User Id</label>
<s:textfield name="logins[0].userId" value="%{logins[0].userId}" id="userId"/>
</div>
<div class="form-group">
<label>Mail Id</label>
<s:textfield name="logins[0].userMailid" value="%{logins[0].userMailid}" id="userMailid"/>
</div>
Pojo Classes Pojo课程
public class Client implements java.io.Serializable {
private Set logins = new HashSet(0);
//getter and setter
}
public class Login implements java.io.Serializable {
private Long id;
private Client client;
private String userId;
private String userName;
private String userMailid;
}
Action Class 动作班
public String register() {
Client cl = new Client();
System.out.println(cl.getName() + " " + cl.getAddress());
}
I want to set values of set in to my Action class for Client and Login. 我想为客户端和登录名的操作类设置set in的值。
How to do this? 这个怎么做?
You can use a submit button like this: 您可以使用以下提交按钮:
<form action="Registered" method="post">
<div class="form-group">
<label>Company Name</label>
<s:textfield name="name" value="%{name}" id="name"/>
</div>
<div class="form-group">
<label>Address</label>
<s:textarea name="address" value="%{address}" id="address"/>
</div>
<div class="form-group">
<label>User Name</label>
<s:textfield name="logins[0].userName" value="%{logins[0].userName}" id="userName"/>
</div>
<div class="form-group">
<label>User Id</label>
<s:textfield name="logins[0].userId" value="%{logins[0].userId}" id="userId"/>
</div>
<div class="form-group">
<label>Mail Id</label>
<s:textfield name="logins[0].userMailid" value="%{logins[0].userMailid}" id="userMailid"/>
</div>
<input type="submit" value="Submit">
</form>
EDIT 编辑
After make properties file like: 之后使属性文件如下:
#Global messages
name= name
submit = Submit
I believe you has made Registered.jsp. 我相信您已经创建了Registered.jsp。
An you can run your project! 您可以运行您的项目!
To bind fildes to Set
you should put annotations on this property 要将fildes绑定到
Set
,应在此属性上添加注释
public class Client implements java.io.Serializable {
@Element(value = Login.class)
@Key(value = Long.class)
@KeyProperty(value = "id")
@CreateIfNull(value = true)
private Set logins = new HashSet(0);
//getter and setter
//now you need a property for login id, it should be initialized before JSP is populated
private Long loginId;
//getter and setter
}
now binding to the fields of the JSP change to 现在绑定到JSP的字段更改为
<s:textfield name="logins(%{loginId}).userName" id="userName"/>
the same for other fields that are bound to a set. 绑定到集合的其他字段也是如此。
If you are using iterator tag to iterate through a set and you have an instance of Login
pushed on top of the value stack then you can get its id
instead of using loginId
. 如果您正在使用iterator标记对集合进行迭代,并且在值堆栈的顶部推送了
Login
实例,则可以获取其id
而不是使用loginId
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.