开发者

Determining which drop down out of a set of 5 was changed (in action class)

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 la开发者_如何学JAVAbel="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?


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');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜