我有麻烦弄清楚这个(虽然我知道它并不复杂)。
我在一个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打印得很好,而变量which没有。
在主题处理中,我所做的一切都称为动作。这是代码:
<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);
那我怎么在action文件中访问value呢?
如果没有主题处理代码,就很难区分,但是有两种可能的解决方案:
1)保留会话中每个字段的值,并比较哪些更改了
2)在"wrapper"onchange
函数中设置一个隐藏字段(见下文)
<s:select name="customer" ... onchange="fire('customer')">
...
function fire(s) {
$('#which').val(s);
dojo.event.topic.publish('getLists');
dojo.event.topic.publish('getDayReports');
}