gpt4 book ai didi

java - 所有表单的数据均为空,其中 dojo sx :div is refresh

转载 作者:行者123 更新时间:2023-12-01 13:37:45 24 4
gpt4 key购买 nike

在我的 struts2 Web 应用程序中,我有一个包含 dojo sx:div 的表单。当我刷新这个 div 时,所有表单的数据都是空的。当我单击按钮“Refres the Div”时,方法search范围内的属性listIdSelected为空。我发现在某些情况下一个JSP页面中可能有多个表单。是最好的解决方案吗?我不喜欢这种做法,使用 JSF 这种情况更容易管理。

JSP 文件:

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>

<link rel="stylesheet"
href="<s:url value="/css/jquery.multiselect.css"/>" type="text/css" />
<link rel="stylesheet"
href="<s:url value="/css/jquery.multiselect.filter.css"/>"
type="text/css" />
<link rel="stylesheet"
href="<s:url value="/css/themes/base/jquery.ui.theme.css"/>"
type="text/css" />
<script type="text/javascript"
src="<s:url value="/js/jquery-1.9.1.min.js" />"></script>
<script type="text/javascript"
src="<s:url value="/js/jquery-ui.min.js" />"></script>
<script type="text/javascript"
src="<s:url value="/js/jquery.multiselect.min.js" />"></script>
<script type="text/javascript"
src="<s:url value="/js/jquery.multiselect.filter.js" />"></script>


<script language="javascript">
$(function() {

$("select").multiselect({
multiple : true,
selectedList : 4,
height : 180
});

$("select").multiselect().multiselectfilter();

});

function refreshDiv() {
dojo.event.topic.publish("/listTopic", "0", "1");
}
</script>

<s:form id="idForm" action="validationAction.do" name="MyForm"
theme="simple">

<div class="contentTable">
<div class="tbl">

<table width="100%">
<tr>
<td><s:select id="idCombo" multiple="true" list="listItems"
name="listIdSelected" value="listIdSelected" listKey="id"
listValue="label" emptyOption="true" /></td>
</tr>
</table>
</div>
</div>

<div class="contentTable">
<div class="tbl">

<div class="bloc_action">
<input class="btn_action" type="button" onclick="refreshDiv();"
value="Refresh the div" />
</div>

<sx:div id="listDiv" href="searchAction.do" formId="listForm"
listenTopics="/listTopic" theme="ajax">
</sx:div>

</div>
</div>

<div class="bloc_action">
<s:submit cssClass="btn_action" value="Submit form"></s:submit>
</div>

</s:form>

Java 文件:

package com.omb.controller.report;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.omb.ui.item.Item;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

@SuppressWarnings("serial")
public class MyAction extends ActionSupport implements Preparable {

Log log = LogFactory.getLog(MyAction.class);

private List<Item> listItems = new ArrayList<String>();
private List<String> listIdSelected;

public void prepare() throws Exception {
listItems.add(new Item("1", "Item 1"));
listItems.add(new Item("2", "Item 2"));
listItems.add(new Item("3", "Item 3"));
listItems.add(new Item("4", "Item 4"));
}

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = true)
public String validation() throws Exception {
// do validation
return SUCCES;
}

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = true)
public String search() throws Exception {
log.debug("listIdSelected.size() = " + listIdSelected.size());
return "displayResultList";
}

public List<Item> getListItems() {
return this.listItems;
}

public void setListItems(List<Item> listItems) {
this.listItems = listItems;
}

public List<Integer> getListIdSelected() {
return this.listIdSelected;
}

public void setListIdSelected(List<Integer> listIdSelected) {
this.listIdSelected = listIdSelected;
}

}

最佳答案

您的表单未提交,因为您输入了错误 formId<sx:div>标签。由于您的表单 ID 是 idForm更改div formId到它。

<sx:div id="listDiv" href="searchAction.do" formId="idForm"
listenTopics="/listTopic" theme="ajax">
</sx:div>

关于java - 所有表单的数据均为空,其中 dojo sx :div is refresh,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21135481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com