[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Help me regarding Struts Problem....

hi,

I am developing web application using Struts1.1. Now following is my ViewCartForm.java (formbean)file.
=========================
public class ViewcartForm extends ActionForm {
      /** cartsessiondata property */
      private CartSessionData[] cartdata=new CartSessionData[0];

      public CartSessionData[] getCartdata() {
            return cartdata;
      }
      public void setCartdata(CartSessionData[] cartdata) {
            this.cartdata = cartdata;
      }

}
========================

& this is content of my Viewcart.jsp file:-
==================
      <logic:empty name="viewcartForm" property="cartdata">
            <tr>
                  <td colspan="5">Your Shopping Cart is Empty!!!</td>
            </tr>
      </logic:empty>
      <logic:notEmpty name="viewcartForm" property="cartdata">
            <tr>
                  <td colspan='25' class=header width="100%" height=30>
                  <center><blink>Parts in your Shopping Cart </blink></center>
                  </td>
            </tr>
            <tr>
                  <td>

                  <table border="1" cellpadding="0" width="100%" bgcolor="#71B8FF"
                        bordercolor="#000000" cellspacing="1">
                        <tbody>
                              <logic:iterate name="viewcartForm" property="cartdata"
                                    id="partsincart">
                                    <tr>
                                          <td colspan="2" class=darkodd>&nbsp;&nbsp;&nbsp;&nbsp;Part ID:</td>
                                          <td colspan="2" class=darkodd>&nbsp;<bean:write
                                                name="partsincart" property="partid" /></td>
                                                                 <td colspan="2" class=darkodd>&nbsp;<bean:write
                                                name="partsincart" property="partdesc" /></td>
                                    </tr>
                              </logic:iterate>
                  </table>
                  </td>
            </tr>
      </logic:notEmpty>
=================

In The above jsp file I am not able to get any of the parts from my "cartsdata" collection inside my form bean.
What is problem here?
When I am executing viewcart.jsp file i am just getting the header inside <logic:notempty......> tag , i.e, I am just getting output "Parts in your Shopping Cart" on my jsp file. Rest I can't see. Whare I am wrong? PLease tell me.
Thanx in Advance.
Prash.
0
Econify
Asked:
Econify
  • 3
  • 2
  • 2
  • +2
1 Solution
 
radarshCommented:
Hi Econify,

Strange... indeed. Well, do you have valid/non-empty data within your cartdata ArrayList?
Remove <tbody> tag. Are you not getting the table with border 1 also?

________
radarsh
0
 
olgavillamizarCommented:
Hi Econify

Are you sure that you have the action class??

Something like

public abstract class Viewcart extends Action {

public ViewCart() {
 

}


public abstract ActionForward Execute(Action Mapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

ActionForward forward = null;
 forward = this.doExecute(mapping, form, request, response);

}



public abstract ActionForward doExecute(Action Mapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
ViewcartForm fform = (ViewcartForm) form;
//here the code that you want to do

}
0
 
fargoCommented:
private CartSessionData[] cartdata=new CartSessionData[0];
in the form bean u are initialising it with a length of 0..correct? And later on, are u setting the cartdata? If yes, u can just make some debugging to check how much is the length of cardata (to cross check)...if it is not set or the length is 0, simply means there is no data to iterate over.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
EconifyAuthor Commented:
Hi,
There is action class for my formbean in which I ahve written method ActionForward execute successfully. Inside this method I am able to view the all contents of CartSesionData objects array successfully. But only problem here is pulling that data into formbean & on JSP Page.
How to solve this?

Thanx.
0
 
fargoCommented:
sorry with my last comment. It was not correct. First of all, are u keeping this list in request or session as an attribute in the action class like

request.setAttribute("cartdata",yourcartdataarray);
OR
request.getSession().setAttribute("cartdata",yourcartdataarray);

If possible, show us your action class.
0
 
geetha_ramaCommented:
Have a ViewCartVO class which will have partid & partdesc . Provide getter & setter methods for this in the VO class itself. In the ViewCartForm class , instead of declaring cartdata as a array of type CartSessionData , declare cartdata as a List. Provide getter & setter methord for cartdata in the form class.
Try out this & I guess this will work..
0
 
olgavillamizarCommented:
The problem is put the collection into the jsp?

If the problem is it you have to put into jsp I suggest that you create an objet that contains the values and put this:
The object has two attibutes partid and partdesc

<logic:iterate name="viewcartForm" property="cartdata" id="partsincart" type="the object that you created">
                              <tr>
                                   <td colspan="2" class=darkodd>&nbsp;&nbsp;&nbsp;&nbsp;Part ID:</td>
                                   <td colspan="2" class=darkodd>&nbsp;<bean:write name="partsincart" property="partid" /></td>
                                                                 <td colspan="2" class=darkodd>&nbsp;<bean:write
                                        name="partsincart" property="partdesc" /></td>
                              </tr>
                         </logic:iterate>
0
 
EconifyAuthor Commented:
Hi,
I solved my pronlem. Actually I forgot to declare my formbean inside my actionclass as follows:-
==========
ViewCartForm cartform = (ViewCartForm) form;
//coding for accessing data into collection
................

cartform.setcartdata(name_of_collection_object);
.........
=========

Thats all,

Anyways thanx for your efforts.

Prash
0
 
fargoCommented:
good that the problem is solved. But could you clarify for giving B grade? Every expert in Experts-Exchange is to help and for asker giving grades like a school boy doesn't suit the forum.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now