在Struts 2 Action类中发送属性

时间:2014-03-31 16:21:28

标签: java struts2 dojo

我有一个包含dojo sx:div的屏幕。管理div加载的动作类与主体不同。但是当我点击我的链接时,我想用主窗体中的参数输入刷新sx:div。我怎么能这样做?

JSP文件:

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

<script language="javascript">
    function refreshDiv() {
        var td = element.parentNode;
        document.getElementById('idSubFamily').value = td.getAttribute('id');
        dojo.event.topic.publish("/listQuestionTopic", "0", "1");
    }
</script>

<table class="board" width="100%">
    <tr class="titre">
        <td class="titleFamily" width="30%" height="32"><s:property
                value="getText('resultat.sous_famille.question.label')" /></td>

        <s:if test="%{displayWeight}">
            <td class="titleFamily" width="30%" height="32"><s:property
                    value="getText('question.weight.label')" /></td>
        </s:if>
    </tr>
    <s:if test="%{subFamilyItem.size != 0}">
        <s:iterator value="subFamilyItem" status="rowstatus">
            <s:if test="#rowstatus.odd == true">
                <s:set name="trClass" value="%{'even'}"></s:set>
            </s:if>
            <s:else>
                <s:set name="trClass" value="%{'odd'}"></s:set>
            </s:else>
            <tr class="<s:property value="#trClass"/>">
                <td class="family_<s:property value="#trClass"/>"><s:a 
                        cssClass="board" onclick="refreshDiv()">
                        <s:property value="%{getText(traductionCode)}" />


                    </s:a></td>

                <s:if test="%{displayWeight}">
                    <td class="family_<s:property value="#trClass"/>"><s:property
                            value="%{weight}" /></td>
                </s:if>
            </tr>
        </s:iterator>
    </s:if>
</table>

<sx:div id="listQuestions" href="Question.do" formId="idFormQuestion"
    listenTopics="/listQuestionTopic" theme="ajax" preload="false">
    <s:hidden id="idFamily" name="idFamilySelected"></s:hidden>
</sx:div>

PrinciaplAction类:

package com.omb.controller;

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

import com.omb.ui.SubFamilyItem;
import com.opensymphony.xwork2.ActionSupport;

public class PrincipalAction extends ActionSupport {

    private List<SubFamilyItem> subFamilyItem = new ArrayList<SubFamilyItem>();

    @Override
    public String execute() throws Exception {
        subFamilyItem.add(new Item("1", "Family 1"));
        subFamilyItem.add(new Item("2", "Family 2"));
        return SUCCESS;
    }

    public List<Item> getSubFamilyItem() {
        return this.subFamilyItem;
    }

    public void setSubFamilyItem(List<Item> subFamilyItem) {
        this.subFamilyItem = subFamilyItem;
    }

}

DivAction类:

package com.omb.controller;

import com.opensymphony.xwork2.ActionSupport;

public class DivAction extends ActionSupport {

    Service myService;

    // From the principal screen
    Long idFamilySelected;


    /**
     * 
     * @see com.opensymphony.xwork2.ActionSupport#execute()
     */
    public String execute() {
        MyObject object = myService.findObject(idFamilySelected);
        return SUCCESS;
    }

    public String getMyService() {
        return this.subFamilySelected;
    }

    public void setMyService(Service myService) {
        this.myService = myService;
    }

    public String getidFamilySelected() {
        return this.idFamilySelected;
    }

    public void setidFamilySelected(Service idFamilySelected) {
        this.idFamilySelected = idFamilySelected;
    }

}

0 个答案:

没有答案