Action类Struts 2中的复选框值

时间:2013-02-08 08:47:10

标签: java javascript jsp checkbox struts2

我想访问我在javascript中设置的动作类中的复选框值

<s:checkbox key="mstDesignations.isActive" id="isActive"></s:checkbox>


<button type="button" class="submitBtn" onclick="adddesignation()"></button>

的javascript:

function adddesignation() {    
    if(document.designationForm.isActive.checked==true){
      document.designationForm.isActive.fieldValue=1;               
    }
    else if( document.designationForm.isActive.checked==false)
    {
      document.designationForm.isActive.fieldValue=2;
    }
    alert(document.designationForm.isActive.fieldValue);
    document.designationForm.submit();
}

当我尝试在下面的动作类中访问它时,我得到null

public MDesig mstDesignations=new MDesig();

System.out.println("Is Active value:::" +mstDesignations.getIsActive());

1 个答案:

答案 0 :(得分:0)

您需要更改javascript以按名称分配字段的值。假设designationForm是表单名称,mstDesignations.isActive是字段名称。

this.designationForm['mstDesignations.isActive'].value=1;