在dojo sx:div刷新的情况下,所有表单的数据都为null

时间:2014-01-15 10:54:42

标签: java struts2 dojo

在我的struts2 web应用程序中,我有一个包含dojo sx:div的表单。当我刷新此div时,所有表单的数据都为空。当我点击方法搜索范围内的“Refres the Div”按钮,属性 listIdSelected 时,它为null。我看到在某些情况下,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;
    }

}

1 个答案:

答案 0 :(得分:1)

由于formId标记中的<sx:div>错误,您的表单未提交。由于您的表单ID为idForm,因此将div formId更改为<。p>

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