Question

I am doing my struts project now i want to retrieve data as json. But the variable that i want to get the json response does'nt retrieve the json values that i need.

Here is my Action class

import com.myDrDirect.hbmobj.Doctor;
import com.myDrDirect.order.dao.DoctorDashBoardDao;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import java.util.Map;

public class patientOrderDetails extends ActionSupport {
    private int rows;
    private int total;
    private int records;
    private int page;
    private List recentOrders;
    public String jsonRecentOrderDetails() {

         try{
            Map sessionSingleDoctor = ActionContext.getContext().getSession();
            Doctor SessionObj = (Doctor) sessionSingleDoctor.get("Doctor");

          records = DoctorDashBoardDao.getInstance().getCount();
            //records = 10;
             setRows(Integer.parseInt(getText("number.rows.per.page")));
        //rows = 10;
            int to = (getRows() * getPage());
            int from = (getRows() * (getPage()-1));


            total =(int) Math.ceil((double)records / (double)rows);   
            recentOrders= DoctorDashBoardDao.getInstance().getDoctorRecentOrderDetails(rows,from,SessionObj.getId());


     } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getCause());
            //log.error("Error occured " + e.toString());
            return ERROR;
        }
          return SUCCESS;
     }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRecords() {
        return records;
    }

    public void setRecords(int records) {
        this.records = records;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List getRecentOrders() {
        return recentOrders;
    }

    public void setRecentOrders(List recentOrders) {
        this.recentOrders= recentOrders;
    }


}

and my struts.xml have

<package name="json" extends="json-default">

            <action name="DashBoardActivityJson" class="com.myDrDirect.doctor.action.patientOrderDetails" method="jsonRecentOrderDetails">
                <result name="success" type="json">
                    <!-- serialize the result property of the action -->                    
                    <param name="includeProperties">recentOrders</param>

                </result>
            </action>
            <action name="grid" >
                <result name="success" >/WEB-INF/doctor/jsonGrid.jsp</result>
            </action>
        </package>

I need to get the response in RecentOrders1 varable but this variable not retrieve the json data. When i retrieve the variable records i got the response correctly. The recorde only have a totalcount of the list but the recentOrder1 returns a list. I need to get the recentOrder as list in my view page. Can anybody please tell me what is the issue in the above action or xml file. Please help.

One thing i have noticed here is return value in recentOrder is a list. Do i need to convert this list to json string. Is it necessary or struts2 automatically change my list variable into a json string?

Was it helpful?

Solution

Your action doesn't have a property RecentOrders1, only recentOrders.

Note both the capitalization, and lack of a digit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top