Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7643063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:21:10+00:00 2026-05-31T09:21:10+00:00

I am back with one more complex thing. This time i don’t know whether

  • 0

I am back with one more complex thing. This time i don’t know whether i am logically correct.

I have to return the data from database as json object. In this json object i have return some values which is foreign key with other tables in the database. I got the values correctly from database and now i want to iterate the forien key values from my ajax success using the struts iterate tag. It is possible to iterate if we can iterate the json values an object, Anybody please share the idea if i am correct.

<s:iterator value="listdoctorProducts" status="st" >
            <div class="productListing">
                <h3><span><s:property value="inventory.name" /></span> - <s:property value="inventory.description" /> </h3>
                    <div class="productDtlLeft">
                        <s:iterator value="inventory.pronovaInventories" >
                            <img src="images/pronova/products/<s:property value="image" />" width="31" height="94" alt="" />
                        </s:iterator>                        
                    </div>     
                    <s:iterator value="inventory.productRatings" status="st">
                        <s:if test="(#st.index+1)==1">
                            <s:set var="no2" value="rating" /> 
                        </s:if>
                        <s:else>
                            <s:set var="no2" value="#no2+rating" /> 
                        </s:else>
                        <s:set var="count" value="#st.index+1" /> 
                    </s:iterator>
                     <s:set var="aver" value="%{#no2*10/#count}"/>
                     <s:set var="result" value="#aver*1.0/10"/>
                    <div class="productDtlRight">
                        <div class="ratting">
                            <div class="rattingStar">bg</div>
                            <div class="rattingOrange" style="width:<s:property value="(#result/5)*100"/>%;">bg</div>
                        </div>

                        <span>(<s:property value="#aver*1.0/10"/>)</span>
                        <div class="clear"></div>
                        <s:set var="no2" value="0" /> 
                        <s:bean name="com.zoondia.common.calculationBean" var="decCalBeansuggestedPrice">
                            <s:param name="valueOne" value="retailPrice"/>                                                             
                            <s:param name="decimalPlace">#.##</s:param>
                        </s:bean>
                        <h4>$<s:property value="#decCalBeansuggestedPrice.decimalPointConversionResult" /></h4>
                        <a class="addtoCart" href="javaScript:void(0)">View All</a>
                   </div>
                   <div class="clear"></div>
                </div>
        </s:iterator> 

In this jsp page you can see that i have a database object list in listdoctorProducts and i can get the values of productRating table by accessing this like this

<s:iterator value="inventory.productRatings" status="st">
                            <s:if test="(#st.index+1)==1">
                                <s:set var="no2" value="rating" /> 
                            </s:if>

and this code i have list here is for first page and if user click for second page i have to list the second page for the user and we need to do this in ajax by populating json values. My problem is how could i write an iterator like this if i retrieve the response as ajax?

Here is my Action class

public String getEcommerceWidgetFourJson(){
        try{            
            Doctor DtObj = null;
            Map sessionSingleDoctor = ActionContext.getContext().getSession();
            Object Obj = null;
            Obj = sessionSingleDoctor.get("Doctor");
            DtObj = (Doctor) Obj;
            int totalCount = DoctorDao.getInstance().totalNumberOfdoctorToProductsForJson(DtObj.getId());
            numberOfRowsPerPage = Integer.parseInt(getText("ecommerce.widget.product.list.four"));
            totalNumberOfRows = (int)Math.ceil((float)totalCount/numberOfRowsPerPage);
            if(pageNum < 1){
                pageNum = 1;
            }else if(pageNum > lastRows){
                pageNum = lastRows;
            }
            listdoctorProducts = DoctorDao.getInstance().getDoctorProductsAsJson(DtObj.getId(),numberOfRowsPerPage,pageNum);



        }catch(Exception e){
            e.printStackTrace();
        }
        return SUCCESS;
    }

I have not added the variable declaration and setter and getter here. And here is my Dao function from where i access the data from database

public List<DoctorToProducts> getDoctorProductsAsJson(int DocId,int numberOfRowsPerPage, int pageNum){
        List<DoctorToProducts> dp = null;
        DoctorToProducts ldp = null;
        SessionFactory sessionFactory =
                    (SessionFactory) ServletActionContext.getServletContext().getAttribute(HibernateListener.KEY_NAME);
        Session Hibernatesession = sessionFactory.openSession();
        Hibernatesession.beginTransaction(); 
        Query  q = (Query) Hibernatesession.createQuery("select id,inventory.id,doctor.id,inventory.pronovaInventories,retailPrice,unitCreditValue from DoctorToProducts where doctor.id="+DocId);
        q.setFirstResult((pageNum-1)*numberOfRowsPerPage);
        q.setMaxResults(numberOfRowsPerPage);
        dp = q.list();
        Hibernatesession.getTransaction().commit();
        Hibernatesession.flush();
        return dp;
    }

and my struts.xml is

<action name="frPdtListPagination" class="com.zoondia.action.DoctorPdtsPagination" method="getEcommerceWidgetFourJson">
            <result  type="json">                

            </result>
        </action>

Just add the action for this json call only.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:21:11+00:00Added an answer on May 31, 2026 at 9:21 am

    This is going to be guess work on my part…

    The short answer to your question is: no. That is you can’t both return json and iterate over the objects in your action producing meaningful results because of the way it has been set up.

    Lets change the set up so the answer becomes a yes. This is the quick version not tested:

    //Not tested, this is just an example of what you can do
    package com.quaternion.action;
    
    import com.opensymphony.xwork2.ActionSupport;
    import com.opensymphony.xwork2.Preparable;
    import java.util.List;
    import org.apache.struts2.convention.annotation.Action;
    import org.apache.struts2.convention.annotation.Result;
    import org.springframework.beans.factory.annotation.Autowired;
    
    public class DoctorActions extends ActionSupport implements Preparable {
        @Autowired DoctorService doctorService; //injected from spring
        List<String> doctorProducts;
    
        @Override
        public void prepare() {
            doctorProducts = doctorService.getProducts();
        }
    
        @Action(results = {
            @Result(type = "json", params = {
                "includeProperties",
                "doctorProducts"})
        })
        public String DoctorJsonProducts() {
            return SUCCESS;
        }
    
        @Action
        public String DoctorProducts(){
            return SUCCESS;
        }
    }
    

    Explanation of the above:

    By having our Action implement Preparable struts2 will call the prepare method which uses the doctorService set doctorProducts. Note how clean the intention of the Action becomes when everything to do with Doctor management has been moved into its own service class, including transaction management.

    Next note that our class creates two actions, one of which uses the json result type. The json result will serialise our list into JSON for us.

    Some sort of dependency injection magic was used here, but you could have just as easily used the prepare method and a factory.

    Further, the annotations cover what is required there is no need for any xml, however there is need for struts2-conventions-plugin jar and struts2-json-plugin jar.

    So… you’ll need to backtrack and rebuild your action to get the functionality you want because currently you have a list of json strings which is not what you want to write into your jsps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One thing I have noticed a lot of back and forth on is where
Looking back at my past projects I often encounter this one: A client or
Some time back, I created two separate SharePoint projects in VS 2008; one using
One of the problems I have come across having complex tasks on the browser
I like the plyr syntax. Any time I have to use one of the
One of the biggest issues currently holding me back from diving full steam into
One of my hobby applications uses a SQLite back end to store the application
Is there a quick one-liner to call datepart in Sql Server and get back
Is it quicker to make one trip to the database and bring back 3000+
I'm trying to change the back button to a custom one. If I create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.