我想在这个帮助下进行部分页面刷新。举一个场景,我们根据它的选择选项有一个下拉列表,我想刷新页面的 div 部分,其中数据根据下拉选择填充。
这个怎么做?
更新 :
我试过这个:
JSP 代码:
在此下拉选择中,我想填充(刷新)div。
<s:form id="RoleListForm">
<s:label value="Roles"/>
// JSON Action populating roleNameList on page Load
<s:url id="fetchJsonRoleListUrl" action="fetchJsonRoleList"/>
<sj:select
name="idRoleInfo"
id="idRoleInfoList"
href="%{fetchJsonRoleListUrl}"
list="roleNameList"
onChangeTopics="reloadRolePrivilegesDiv"
listKey="idRoleInfo"
listValue="roleName"
emptyOption="true"/>
</s:form>
这是我想根据 DD 选择填充的 div 代码,但我没有填充文本字段值:
// 页面加载的 JSON 动作
<s:url id="roleDetailsUrl" action="roleDetailsAction" />
<sj:div href="%{roleDetailsUrl}" formIds="RoleListForm" reloadTopics="reloadRolePrivilegesDiv">
<s:textfield id="idRoleName" name="roleName" />
<s:textfield id="idRolePrivileges" name="privileges"/>
</sj:div>
我在浏览器上的 div 部分得到这个:
{"roleName":"IT User","privileges":"IT User"}
更新部分:
动作类:
public class GraphsAction extends ActionSupport {
private String startDate;
private String endDate;
private String bodyStats;
HomeService homeService = new HomeService();
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
public String reloadDatePicker() {
Date date1 = new Date();
Date date2 = new Date();
Map session = ActionContext.getContext().getSession();
Integer loginId = (Integer) session.get("loginId");
if (loginId != null) {
List list = homeService.getAllGraphData(loginId);
List chestList = homeService.getChestGraphData(loginId);
List waistList = homeService.getWaistGraphData(loginId);
List hipsList = homeService.getHipsGraphData(loginId);
List bicepsList = homeService.getBicepsGraphData(loginId);
if (bodyStats.equals("")) {
UserStats usetsts = (UserStats) list.get(0);
date1 = usetsts.getUpadtedDate();
this.startDate = formatter.format(date1);
UserStats usetsts1 = (UserStats) list.get(list.size() - 1);
date2 = usetsts1.getUpadtedDate();
this.endDate = formatter.format(date2);
}
if (bodyStats.equals("0")) {
UserStats usetsts = (UserStats) list.get(0);
date1 = usetsts.getUpadtedDate();
this.startDate = formatter.format(date1);
UserStats usetsts1 = (UserStats) list.get(list.size() - 1);
date2 = usetsts1.getUpadtedDate();
this.endDate = formatter.format(date2);
}
if (bodyStats.equals("1")) {
UserStats usetsts = (UserStats) list.get(0);
date1 = usetsts.getUpadtedDate();
this.startDate = formatter.format(date1);
UserStats usetsts1 = (UserStats) list.get(list.size() - 1);
date2 = usetsts1.getUpadtedDate();
this.endDate = formatter.format(date2);
}
if (bodyStats.equals("2")) {
UserStats usetsts = (UserStats) list.get(0);
date1 = usetsts.getUpadtedDate();
this.startDate = formatter.format(date1);
UserStats usetsts1 = (UserStats) list.get(list.size() - 1);
date2 = usetsts1.getUpadtedDate();
this.endDate = formatter.format(date2);
}
return SUCCESS;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getBodyStats() {
return bodyStats;
}
public void setBodyStats(String bodyStats) {
this.bodyStats = bodyStats;
}
}
Struts.xml:
<action name="jsonReloadDatePickerAction" class="com.ebhasin.fitnessbliss.actions.GraphsAction" method="reloadDatePicker">
<result name="success">/jsps/datePicker.jsp</result>
</action>