确定一组 5 个下拉菜单中的哪一个已更改(在操作类中)

发布于 2024-12-05 01:01:41 字数 3845 浏览 0 评论 0原文

我很难弄清楚这个问题(尽管我知道它并不复杂)。

我在 jsp 页面上有 5 个下拉菜单。每个下拉菜单的 onChange 事件都调用相同的操作。 在操作文件中,我想知道 5 个下拉列表中的哪一个发生了更改(这导致了 onChange 事件)。

我知道这可能非常简单,但我无法做到。请指教。

这是包含下拉菜单的 jsp:

<s:form action="viewDayReport" id="dayReport">
        <s:select label="Customer " name="customer" headerKey="0" headerValue="Select" list="customerList" onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <s:select label="Contact "  name="contact"  headerKey="0" headerValue="Select" list="contactList"  onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <s:select label="Employee " name="employee" headerKey="0" headerValue="Select" list="employeeList" onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <s:select label="Stage "    name="stage"    headerKey="0" headerValue="Select" list="stageList"    onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <s:select label="Type "     name="type"     headerKey="0" headerValue="Select" list="typeList"     onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <sd:datetimepicker label="Date" name="date" displayFormat="dd/MM/yyyy"/>
        <%--<s:reset value="Reset"/>--%>
        <%--<s:submit value="View Report(s)"/>--%>
    </s:form>

如果我错过了任何信息,请告诉我。

谢谢

Kanishk

编辑:

这是当前的表单,包含操作文件中的 5 个下拉菜单

<s:form action="viewDayReport" id="dayReport">
        <s:select label="Customer " name="customer" headerKey="0" headerValue="Select" list="customerList" onchange="dojo.event.topic.publish('getLists');dojo.query('which').attr('value','customer');"/>
        <s:select label="Contact "  name="contact"  headerKey="0" headerValue="Select" list="contactList"  onchange="dojo.event.topic.publish('getLists');"/>
        <s:select label="Employee " name="employee" headerKey="0" headerValue="Select" list="employeeList" onchange="dojo.event.topic.publish('getLists');"/>
        <s:select label="Stage "    name="stage"    headerKey="0" headerValue="Select" list="stageList"    onchange="dojo.event.topic.publish('getLists');"/>
        <s:select label="Type "     name="type"     headerKey="0" headerValue="Select" list="typeList"     onchange="dojo.event.topic.publish('getLists');"/>
        <sd:datetimepicker label="Date" name="date" displayFormat="dd/MM/yyyy"/>
        <s:hidden id="which"/>
        <%--<s:reset value="Reset"/>--%>
        <%--<s:submit value="View Report(s)"/>--%>
    </s:form>

(我将长代码剪短并显示相关内容):

public class getLists extends ActionSupport {


private String which;
public String getWhich() {
    return which;
}

public void setWhich(String which) {
    this.which = which;
}

private String customer;
public String getCustomer() {
    return customer;
}

public void setCustomer(String customer) {
    this.customer = customer;
}
//other variables and functions
@Override
public String execute(){

    System.out.println("getlists:"+which);
    System.out.println("getlists:"+customer);

    //other function calls

    return "success";
}

}

变量 customer 打印得很好,但变量则不然。


在主题处理中,我所做的就是称为动作。这是代码:

<s:url id="scriptURL" action="getLists" />
<sd:div href="%{scriptURL}" listenTopics="getLists" formId="dayReport" showLoadingText="false" preload="false"></sd:div>

第二个主题类似。

在您所说的内容中,您能否解释一下以下代码的作用:

dojo.query('#which').attr('value', s);

以及我如何访问操作文件中的“值”?

I am having trouble figuring out this one (although I know its not complex).

I have 5 drop downs on a jsp page.The onChange event of every drop down calls the same action.
In the action file I want to know which of the 5 drop downs was changed (which caused the onChange event).

I know it may be darn simple, but am not able to do it. Please advice.

This is the jsp containing drop downs:

<s:form action="viewDayReport" id="dayReport">
        <s:select label="Customer " name="customer" headerKey="0" headerValue="Select" list="customerList" onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <s:select label="Contact "  name="contact"  headerKey="0" headerValue="Select" list="contactList"  onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <s:select label="Employee " name="employee" headerKey="0" headerValue="Select" list="employeeList" onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <s:select label="Stage "    name="stage"    headerKey="0" headerValue="Select" list="stageList"    onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <s:select label="Type "     name="type"     headerKey="0" headerValue="Select" list="typeList"     onchange="dojo.event.topic.publish('getLists');dojo.event.topic.publish('getDayReports');"/>
        <sd:datetimepicker label="Date" name="date" displayFormat="dd/MM/yyyy"/>
        <%--<s:reset value="Reset"/>--%>
        <%--<s:submit value="View Report(s)"/>--%>
    </s:form>

In case I have missed out on any info please tell.

Thanks

Kanishk

Edit:

This is the current form containing the 5 drop downs

<s:form action="viewDayReport" id="dayReport">
        <s:select label="Customer " name="customer" headerKey="0" headerValue="Select" list="customerList" onchange="dojo.event.topic.publish('getLists');dojo.query('which').attr('value','customer');"/>
        <s:select label="Contact "  name="contact"  headerKey="0" headerValue="Select" list="contactList"  onchange="dojo.event.topic.publish('getLists');"/>
        <s:select label="Employee " name="employee" headerKey="0" headerValue="Select" list="employeeList" onchange="dojo.event.topic.publish('getLists');"/>
        <s:select label="Stage "    name="stage"    headerKey="0" headerValue="Select" list="stageList"    onchange="dojo.event.topic.publish('getLists');"/>
        <s:select label="Type "     name="type"     headerKey="0" headerValue="Select" list="typeList"     onchange="dojo.event.topic.publish('getLists');"/>
        <sd:datetimepicker label="Date" name="date" displayFormat="dd/MM/yyyy"/>
        <s:hidden id="which"/>
        <%--<s:reset value="Reset"/>--%>
        <%--<s:submit value="View Report(s)"/>--%>
    </s:form>

In the action file (I am cutting a long code short and showing what is relevant):

public class getLists extends ActionSupport {


private String which;
public String getWhich() {
    return which;
}

public void setWhich(String which) {
    this.which = which;
}

private String customer;
public String getCustomer() {
    return customer;
}

public void setCustomer(String customer) {
    this.customer = customer;
}
//other variables and functions
@Override
public String execute(){

    System.out.println("getlists:"+which);
    System.out.println("getlists:"+customer);

    //other function calls

    return "success";
}

}

The variable customer gets printed fine but the variable which does not.


In topic handling, all I have done is, called an action. This is the code:

<s:url id="scriptURL" action="getLists" />
<sd:div href="%{scriptURL}" listenTopics="getLists" formId="dayReport" showLoadingText="false" preload="false"></sd:div>

Similarly for the 2nd topic.

In what you have told, can you please explain what does the following code do:

dojo.query('#which').attr('value', s);

And how am I gonna access "value" in action file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静待花开 2024-12-12 01:01:41

如果没有主题处理代码,就很难判断,但有两种可能的解决方案:

1)保留会话中每个字段的值并比较以查看哪些更改了

2)在“包装器”onchange 功能(见下文)

<s:select name="customer" ... onchange="fire('customer')">
...
function fire(s) {
    $('#which').val(s);
    dojo.event.topic.publish('getLists');
    dojo.event.topic.publish('getDayReports');
}

Without the topic-handling code it's harder to tell, but two possible solutions:

1) Keep the values of each field in session and compare to see which changed

2) Set a hidden field in a "wrapper" onchange function (see below)

<s:select name="customer" ... onchange="fire('customer')">
...
function fire(s) {
    $('#which').val(s);
    dojo.event.topic.publish('getLists');
    dojo.event.topic.publish('getDayReports');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文