Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法通过Javascript更新作为Arraylist一部分的表单对象_Javascript_Jsp_Struts 1 - Fatal编程技术网

无法通过Javascript更新作为Arraylist一部分的表单对象

无法通过Javascript更新作为Arraylist一部分的表单对象,javascript,jsp,struts-1,Javascript,Jsp,Struts 1,当用户选中或取消选中复选框时,我需要更新formBean中的属性,该属性是formBean中ArrayList的一部分。 在加载页面之前,formBean中的属性值默认设置为“”。 当用户取消选中时,我尝试将值设置为“关闭” 我可以使用firebug调试器看到值更改为“off”,但在submit中,表单对象的值始终保持“on” 下面是我的JSP代码。如果我以错误的方式设置值,请告知我 Struts应用程序 在JSP中显示逻辑: 在上述逻辑中,当用户取消选中并按预期打印警报时,我们可以进入els

当用户选中或取消选中复选框时,我需要更新
formBean
中的属性,该属性是
formBean
ArrayList
的一部分。
在加载页面之前,
formBean
中的属性值默认设置为“”。
当用户取消选中时,我尝试将值设置为“关闭”
我可以使用firebug调试器看到值更改为
“off”
,但在submit中,表单对象的值始终保持
“on”

下面是我的JSP代码。如果我以错误的方式设置值,请告知我

Struts应用程序

在JSP中显示逻辑:

在上述逻辑中,当用户取消选中并按预期打印
警报时,我们可以进入
else
循环,但表单属性
importEnabled
不会更新,因为它始终保持
“开启”
,就像加载页面之前一样


如果编码逻辑有任何问题,请告诉我,并对其进行修复,因为这将非常有用。

不幸的是,我认为您不能。我使用的解决方案是在表单中保留一个字符串数组(String[]),并使用javascript向HTMLDOM添加(或删除)一些隐藏的输入,所有这些都使用表单字符串数组的名称。这些隐藏的输入有一个值,允许我唯一地标识用户选择的复选框

    <input type="checkbox"
           name="importedFiles[<c:out value='${stts.count - 1}'/>].importEnabled"
           id="importedFiles[<c:out value='${stts.count - 1}'/>].importEnabled"
           onClick="replicateCheckbothis, <c:out value='${stts.count - 1}'/> )"
           <c:if test="${importedFiles.importEnabled != null}">checked</c:if> />
function checkSelectedAndImport()
{
    var anyClicked = "none";

    for(var i = 0; i < <c:out value='${maintainDownloadForm.importedFileLength}' />; i++)
    {
        var element = document.getElementById("importedFiles[" + i + "].importEnabled");

        if(element != null)
        {
            if(element.checked)
            {
                anyClicked = "true";
                element.setAttribute('value', 'on'); alert('Selected--->'+element.getAttribute('value'));
            }
            else
            {
                element.setAttribute('value', 'off');
                alert('Not Selected--->'+document.getElementById("importedFiles[" + i + "].importEnabled").value);

            }
        }
    }

    if(anyClicked != "none")
    {
        submitDGForm(getVMWareForm(),'saveImport');
    }
    else
    {
        alert("No rows have been selected for import. Please select data to import. To cancel the import, click on cancel.");
    }
}