【发布时间】:2014-01-21 01:34:21
【问题描述】:
在我的 Action 类中,我有一个 POJO 类的对象。
public class ConfigureTspThresholdAction extends
ActionSupport implements SessionAware, ModelDriven<GmaThresholdParameter>{
private Map<String,Object> session;
private String circleId;
private String tspId;
private String thresholdTypeFlag;
GmaThresholdParameter gmaThresholdParameters = new GmaThresholdParameter();
GmaThresholdParameter 也是这里的 POJO(我的 Entity 类),它有各种成员,我想从用户那里获取其值。
我在我的 JSP 中的文本字段中获取用户填写的值:
JSP:
<s:div id="thresholdParametersDiv" cssStyle="display: none">
<table>
<tr>
<td>Minimum Number of OG Calls</td>
<td><s:textfield id="thresholdParameter_1"
name="minNumberOc"
onkeypress="return isNumber(event,'thresholdParameter_1')"></s:textfield></td>
</tr>
<tr>
<td>Minimum Duration of OG Calls (in secs)</td>
<td><s:textfield id="thresholdParameter_2"
name="minDurationOc"
onkeypress="return isNumber(event,'thresholdParameter_2')"></s:textfield></td>
</tr>
<tr>
<td>Maximum Number of IC Calls</td>
<td><s:textfield id="thresholdParameter_3"
name="maxNumberIc"
onkeypress="return isNumber(event,'thresholdParameter_3')"></s:textfield></td>
</tr>
..........similarly other textfileds
</table>
文本字段中有name 属性,其值是我想要填充的GmaThresholdParameter 的成员变量。
现在,我想从这些文本字段中提取值并将我的 GmaThresholdParameter gmaThresholdParameters = new GmaThresholdParameter(); 填充到我的 Action 类中。
对于其他原始变量,我通过 getter/setter 填充它们,并以与 Action 类中相同的名称发送我的 AJAX 调用,例如:
JS:
$.ajax({
type: 'POST',
traditional: true,
url: '/gma/updateThresholdParameters.action',
data:
{
circleId: circleId,
tspId: tspId,
thresholdTypeFlag: thresholdTypeFlag,
// HERE I want to send my GmaThreshholdParameter object. How to send it so that it fills my object in action class ?
}
我想将我的 GmaThreshholdParameter 对象从 JavaScript 发送到 Action 类。如何发送它以填充我在动作类中的对象?
我应该从数组中的 textfileds 收集值并发送它还是创建一个 JavaScript Object 以从映射 Java POJO 对象的 JavaScript 发送对象?
有什么解决办法吗?
【问题讨论】:
-
我不明白您为什么需要从 javascript 发送对象?如果要发送所有值,请使用
data : $("#form_id").serialize(),。
标签: java javascript ajax jsp struts2