struts2的一个小问题,问题虽小,可几天解决不了
我做的是尚学堂的OA中的定义表单,定义表单中下拉框表单会有“添加条目”,点击“条目”进入添加条目主界面,我的添加条目主界面核心代码如下:
<table class="tableEdit" style="width:580px;" cellspacing="0" border="0" cellpadding="0">
<c:forEach begin="0" end="20" var="i">
<tr>
<td class="tdEditLabel" >文本</td>
<td class="tdEditContent"><input type="text" name="items[${i}].label" value="${field.items[i].label }">
</td>
<td class="tdEditLabel" >值</td>
<td class="tdEditContent"><input type="text" name="items[${i}].value" value="${field.items[i].value }"></td>
</tr>
</c:forEach>
</table>
把上边的表单提交到Action,调用的方法代码如下:
//添加条目
public String addItem()throws Exception{
List items = getItems();
log.debug("items size is "+items.size()+" id is "+getId());
for (Iterator iter = items.iterator(); iter.hasNext();) {
FieldItem item = (FieldItem) iter.next();
if(item!=null)
{
log.debug("items is "+item.getValue());
}
//如果没有输入任何值,则忽略不处理
if(item == null || item.getValue() == null || item.getValue().trim().equals("")){
iter.remove();
}
}
formManager.updateFieldItems(getId(), getItems());
return SUCCESS;
}
在Action中,调用到updateFieldItems()方法,它的代码如下:
public void updateFieldItems(int fieldId, List items) {
FormField field = findFormField(fieldId);
field.setItems(items);
getHibernateTemplate().update(field);
}
其中有个FormFile类,它的代码如下,映射文件和数据库用Ant生成:
package org.myy.model;
import java.util.List;
/**
* 表单域
* @author Administrator
* @hibernate.class table="T_FormField"
*/
public class FormField {
/**
* @hibernate.id
* generator-class="native"
*/
private int id;
/**
* 表单域标签
* @hibernate.property
*/
private String fieldLabel;
/**
* 表单域的名称
* @hibernate.property
*/
private String fieldName;
/**
* 表单域的输入形式
* @hibernate.many-to-one
*/
private FieldInput fieldInput;
/**
* 表单域的类型
* @hibernate.many-to-one
*/
private FieldType fieldType;
/**
* 额外参数,条目
* 比如:如果是下拉框,都有哪些值可供选择
* @hibernate.list table="T_FieldItem"
* @hibernate.key column="fieldId"
* @hibernate.list-index column="itemIndex"
* @hibernate.composite-element class="org.myy.model.FieldItem"
*/
private List items;
/**
* 对应的表单
* @hibernate.many-to-one column="flowFormId"
*/
private FlowForm flowForm;
public FieldInput getFieldInput() {
return fieldInput;
}
public void setFieldInput(FieldInput fieldInput) {
this.fieldInput = fieldInput;
}
public String getFieldLabel() {
return fieldLabel;
}
public void setFieldLabel(String fieldLabel) {
this.fieldLabel = fieldLabel;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
public FieldType getFieldType() {
return fieldType;
}
public void setFieldType(FieldType fieldType) {
this.fieldType = fieldType;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
}
public FlowForm getFlowForm() {
return flowForm;
}
public void setFlowForm(FlowForm flowForm) {
this.flowForm = flowForm;
}
}
这就是整个业务逻辑的代码了,可是当我提交上边的表单到Action时,日志文件输出为:
17:02:10,055 DEBUG FolwFormManagerAction:164 - items size is 20 id is 2
Hibernate: select formfield0_.id as id14_0_, formfield0_.fieldLabel as fieldLabel14_0_, formfield0_.fieldName as fieldName14_0_, formfield0_.fieldInput as fieldInput14_0_, formfield0_.fieldType as fieldType14_0_, formfield0_.flowFormId as flowFormId14_0_ from T_FormField formfield0_ where formfield0_.id=?
Hibernate: delete from T_FieldItem where fieldId=?
打开数据库看时,却没有值,这个问题还请各大哥大姐帮帮看看。。^_^
[解决办法]