0
我有一个textfield
这样的:如何在Struts 2 action的<s:textfield />中获取id属性的值?
<s:textfield id="123456" name="abc" value="cateory name" />
有可能获得Struts2的Action类(这是123456
)id
属性的价值?
我有一个textfield
这样的:如何在Struts 2 action的<s:textfield />中获取id属性的值?
<s:textfield id="123456" name="abc" value="cateory name" />
有可能获得Struts2的Action类(这是123456
)id
属性的价值?
随着OO(面向对象)编程,你应该定义一个类别类,通过ID和姓名字段,以及相关的存取方法,就像这样:
public class Category{
private long id;
private String name;
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
public long getId(){
return this.id;
}
public void setId(Long id){
this.id = id;
}
}
然后点根据你的需要给他们带隐藏或可见的领域。
在你的情况,ID应该是一个隐藏字段:
<s:hidden name="category.id" value="123456" />
<s:textfield name="category.name" value="blabla" />
你甚至可以重复的类别列表,像这样:
<s:iterator name="categories" var="cat" status="ctr">
<s:hidden name="#cat[#ctr.index].id" value="123456" />
<s:textfield name="#cat[#ctr.index].name" value="blabla" />
</s:iterator>
,并张贴他们回的ArrayList中目标操作自动。
尝试
jQuery("input[name='abc']").attr("id");
你能解释一下为什么? –
因为我需要该id值来执行数据库查询。否则,我不得不使用另一个隐藏的字段。 – ipkiss
只需使用隐藏字段。 –