2
我在Struts2中使用了ModelDriven
,这样我的模型对象就拥有了另一个具有属性的对象。我正在做一个AJAX调用,并希望我的模型对象被用户填充。在POJO ModelDriven Struts 2中访问属性?
JSP:
<s:select list="#session.circleIdNameMap"
headerKey="-1" headerValue="Select Circle"
name="id.circleId" id="selectCircleDropDown"
onchange="findTspNameIdMap(this.value)">
</s:select>
JS:
$.ajax({
type: 'POST',
url: '/gma/findTspNameIdMap.action',
data:
{
id.circleId: circleId,
minNumberOc: $("[name='minNumberOc']").val(),
minDurationOc: $("[name='minDurationOc']").val(),
},
然而,这里的萤火我得到一个错误
SyntaxError: missing : after property id
id.circleId: circleId,
但其他直接化子性质类似minNumberOc
工作好的但不是id.anything
。我张贴我的模型对象和Action类。
GmaThresholdParameter:
public class GmaThresholdParameter implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private GmaThresholdParameterPK id;
//getter/setters of id
GmaThresholdParameterPK:
public class GmaThresholdParameterPK implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name="CIRCLE_ID")
private int circleId;
@Column(name="TSP_ID")
private int tspId;
private String flag;
//getter/setters
Action类:
public class ConfigureTspThresholdAction extends ActionSupport implements SessionAware, ModelDriven<GmaThresholdParameter>{
private Map<String,String> circleIdNameMap;
// MODEL object
GmaThresholdParameter gmaThresholdParameters = new GmaThresholdParameter();
.....
...
public GmaThresholdParameter getGmaThresholdParameters() {
return gmaThresholdParameters;
}
public void setGmaThresholdParameters(
GmaThresholdParameter gmaThresholdParameters) {
this.gmaThresholdParameters = gmaThresholdParameters;
}
@Override
public GmaThresholdParameter getModel() {
return gmaThresholdParameters;
}
如何设置对应于id
的属性?为什么它在Firebug中发生错误?
我检查了我的代码,我不把“”末,它仍然提供了错误。它确定id.circleId:circleId有效吗?即使在AJAX中,struts是否能够选取getter? –
并且由于错误提示'缺少:id.cricleId:(id)后的circleId'(冒号)'。所以它预计ID后的冒号。 id.anthying:xyz实际上工作吗? –
'id.circleId'应该在引号中,没有它这样的名称是无效的。 –