سؤال

I want to do partial page refresh with the help of this. Take a scenario, we have a dropdown list according to select option of it, I want to refresh a div section of a page with data populated according to dropdown selection .

How to do this?

Updated :

i have tried this:

JSP Code:
On this Dropdown selection i want to populate (refresh) 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>

Here is the div code that i want to populate according to DD selection, But i am not getting textfields value filled:

// JSON Action on page Load

 <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>

I am getting this in div section On Browser:

{"roleName":"IT User","privileges":"IT User"}

Updated Part:

Action Class:

 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>
هل كانت مفيدة؟

المحلول

One of the options is to put content which is currently inside your <sj:div> to separate JSP page and configure your roleDetailsAction action to return that page instead of json result.

نصائح أخرى

I have to do this in almost all of my software solutions...!! These is what I do

a) Load the page with all the necessary data from server and in HTML source code link the onchange event for the dropdown button with a function in JS.

b) populate/initlize the page with the data obtained from the server.

c) As we have linked the drop down button's onchange event with our implementation in JS, all we have to do is make AJAX call from these function (in JS) and get the required data from the server. Again in the response of completion of current AJAX request we get the relevant data from server and then we use DOM manipulations to update the page with required data.

We have to stick to the id's of all the elements/div of page and fiddle with them with jQuery.

All the best.

PS: ping me if you need reference code for the same...!!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top