Thanks for the lengthy example, but there is one part that I am completly
lost on.  I thought that the following occurred:
Click link to open page, formbean is reset aciton poppulates formbean jsp
retrieves values from the formbean.  User sees the screen prepopulated.
User modifies the information and clicks on submit.  The bean is again reset
the action is called to put information in the formbean (this is the part I
have no data) the jsp then pulls the data from the formbean.

What is the purpose of the System.out.println that you have at the end of
your action ?

thanks again,
Adam

On 11/21/06, Raghuveer <[EMAIL PROTECTED]> wrote:

 Hi Adam,

Use the sample code as requested by you.
You can ask me any help with nested Tags and from advanced struts




*JSP*


<nested:notEmpty name="ProdSelectionForm" property="results">
    <nested:iterate name="ProdSelectionForm" property="results"
id="Result" type="com.test.javabeans.TestObject">
      <tr>
        <td>    <nested:text  name="Result" property="description" />
</td>
      </tr>
    </nested:iterate>
</nested:notEmpty>

*ActionForm*
**
public class ProdSelectionForm extends ActionForm
{
Collection arlResults=null; //can be arrayalist

/**
  * @return Returns the arlResults.
  */
 public Collection getResults() {
  return arlResults;
 }
 /**
  * @param arlResultsThe arlResultsto set.
  */
 public void setResults(Collection arlResults) {
  this.arlResults= arlResults;
 }

 /**
     *
     * toString representation of object
     * @return      An instance of StringBuffer with Struts Action Form
properties
     *
     */
  public String toString() {

   StringBuffer sbTemp = new StringBuffer();
   sbTemp.append("{");

   sbTemp.append("arlResults=" );
   sbTemp.append(arlResults);
   sbTemp.append("}");
   return sbTemp.toString();

  }//end of toString
}//end Actionform

*TestObject  Java Bean*

import java.io.Serializable;

public class TestObject implements Serializable

String description =null;
int numProducts =0;
/**
 * @return Returns the description.
 */
public String getDescription() {
 return description;
}
/**
 * @param description The description to set.
 */
public void setDescription(String description) {
 this.description = description;
}
/**
 * @return Returns the numProducts.
 */
public int getNumProducts() {
 return numProducts;
}
/**
 * @param numProducts The numProducts to set.
 */
public void setNumProducts(int numProducts) {
 this.numProducts = numProducts;
}

}//end object
**

*Action Class (loading the page)*
**
**
ProdSelectionForm prodSelectionForm= (ProdSelectionForm) form;
com.test.javabeans.TestObject obj1=new com.test.javabeans.TestObject ();
obj1.setDescription("desc1");
obj1.setNumProducts (1);

 com.test.javabeans.TestObject obj2=new com.test.javabeans.TestObject ();
obj1.setDescription("desc2");
obj1.setNumProducts (2);

ArrayList arlResults=new ArrayList ();
arlResults.add(obj1);
arlResults.add(obj2);

prodSelectionForm.setResults(arlResults);

*Action Class (Submitting the page)*

When you submit the page just print the actionform you wouyld see the
updated results of description ,numproducts in action

ProdSelectionForm prodSelectionForm= (ProdSelectionForm) form;

System.out.println("prodSelectionForm="+prodSelectionForm);



Regards
Raghu

-----Original Message-----
*From:* Adam K [mailto:[EMAIL PROTECTED]
*Sent:* Wednesday, November 22, 2006 3:06 AM
*To:* [EMAIL PROTECTED]
*Cc:* Struts Users Mailing List
*Subject:* Re: Indexed Properties

If you might be able to provide a sample I would be very greatful.
As it stands I have come up with the following :
changing the JSP to :

<logic:notEmpty name="ProdSelectionForm" property="results">
    <logic:iterate name="ProdSelectionForm" property="results"
id="Result">
      <tr>
        <td>    <html:text  name="Result" property="description"
indexed="true" />     </td>
      </tr>
    </logic:iterate>
</logic:notEmpty>

Result seemed more natural as it is a single element of the results.
All I want to be able to do is pull 3 things out of an object, display
them in a scope of request, and allow the user to update the list and submit
the form and have the changes be picked up - who would have thought that
would be so incredibly complex ?
*Note*  The part that leads me to believe it's a misunderstanding of the
tags involved is that I can get a single textfield to work perfectly, with
all the requirements (other than it being an object with multiple
properties).


On 11/21/06, Raghuveer <[EMAIL PROTECTED]> wrote:
>
> hi Adam,
>
> I understand description,numProducts are properties in User defined
> Object/java bean in results(getResults(),setResults(..)) Collection in
> your
> actionForm.
>
> For this kind of requirments there will not be any change in actionform
> even
> though ,complixety increases in nesting..
>
> Solution is to use Nested Tags.
>
> Nested tags are used for nesting a object inside the other.
>
> In your requirment "results" is a nested property in your actionform.
> "results" collection  has a collection of objects.
>
> I have used Nested tags for most complex requirments and succeeded.
>
> Nested Tags is the real power of Struts...
>
>
> Regards
> Raghu
>
>
>
>
>
> -----Original Message-----
> From: Adam K [mailto:[EMAIL PROTECTED]
> Sent: Saturday, November 18, 2006 2:55 AM
> To: Struts Users Mailing List
> Subject: Re: Indexed Properties
>
>
> Thanks for the suggestion I'll keep trying things and see what I can get
> from it.
>
>
> On 11/17/06, Hubert Rabago <[EMAIL PROTECTED]> wrote:
> >
> > Lots of people have done it.  Search the archives [1]. Search for
> > "indexed" and "lazyList".   I've done it with both ActionForm and
> > DynaActionForm.
> >
> > Hubert
> >
> > [1] http://struts.apache.org/mail.html
> >
> > On 11/17/06, Adam K <[EMAIL PROTECTED]> wrote:
> > > I think I have found the problem - or at least a potential
> cause.  Would
> > it
> > > be correct in stating that this will not work using ActionForm (what
> I
> > was
> > > using)  and that I must instead use DynaActionForm ?
> > >
> > > Thanks for the time thus far.
> > >
> > >
> > > On 11/17/06, Hubert Rabago < [EMAIL PROTECTED]> wrote:
> > > >
> > > > Adam,
> > > >
> > > > Try adding a getResultsPage() that doesn't take params and always
> > > > returns a valid collection.  (Throw in the setResultsPage() that
> > > > accepts a collection as well.)
> > > >
> > > > Hubert
> > > >
> > > > On 11/17/06, Adam K <[EMAIL PROTECTED]> wrote:
> > > > > This has been driving me nuts for the past little bit.
> > > > > I have a page that is populated using indexed properties.  The
> > > > prepopulation
> > > > > works  fine, and I get the results as I would expect them, but
> > trying to
> > > > > submit the form I get an index out of bounds exception.  I know
> that
> > it
> > > > is
> > > > > being caused because the page doesn't have the arrayList to use
> in
> > the
> > > > > indexed properties.   I guess my question boils down to using
> > indexed
> > > > > properties properly.  I will start by putting in an explanation
> of
> > what
> > > > I
> > > > > have and what I am trying to do:
> > > > >
> > > > > The following is what I am working with :
> > > > > JSP:
> > > > >
> > > > > <logic:notEmpty name="ProdSelectionForm" property="results">
> > > > >     <logic:iterate name="ProdSelectionForm" property="results"
> > > > > id="ResultsPage">
> > > > >         <tr>
> > > > >             <td>    <bean:write name="ResultsPage"
> > > > property="description"
> > > > > />    </td>
> > > > >             <td >    <html:text  name="ResultsPage"
> > > > property="numProducts"
> > > > > indexed="true" />     </td>
> > > > >         </tr>
> > > > >     </logic:iterate>
> > > > > </logic:notEmpty>
> > > > >
> > > > > What I am trying to achieve is that a user clicks on a link,
> they
> > are
> > > > sent
> > > > > to page, and all of the values are prepopulated.  The page is
> then
> > > > displayed
> > > > > and the user has the option to modify any of the variables that
> they
> > > > want to
> > > > > before resubmitting the page.  (When they resubmit the form has
> a
> > url
> > > > > parameter attached to it).  What is happening (or at least what
> I
> > > > believe is
> > > > > happening is the following:  link is clicked, reset is called
> action
> > > > sets
> > > > > the variables, page is displayed, user can modify the page and
> > resubmit,
> > > > > reset is called on the form, the action is called (this is where
> it
> > dies
> > > > as
> > > > > there is no longer an ArrayList) to modify.  My question is am I
> > going
> > > > about
> > > > > this in a manner that seems sensible or am I way off base ?  I
> have
> > the
> > > > > values being prepopulated, but when trying to use the values
> that
> > the
> > > > user
> > > > > puts in I can't use them in the action, nor can I pull the
> values
> > from
> > > > the
> > > > > form without again setting the values in the form.   I am hoping
> it
> > is
> > > > that
> > > > > I have over looked something, but it's possible that I don't
> > understand
> > > > > something as well.
> > > > >
> > > > > Here is the Action code (This is the entire execute method) :
> > > > >         HttpSession session = request.getSession();
> > > > >         ProdSelectionForm prodSelection = (ProdSelectionForm)
> form;
> > > > >         User user ;
> > > > >         user = (User)session.getAttribute("User");
> > > > >         Order order = new Order();
> > > > >         ArrayList products = new ArrayList();
> > > > >         ArrayList pageRes = new ArrayList();
> > > > >         ArrayList results = new ArrayList();
> > > > >
> > > > >         String action = (request.getParameter("Dest") == null ?
> > > > "populate" :
> > > > > request.getParameter("Dest")   );
> > > > >
> > > > >         order = user.getCurrOrder(user);
> > > > >
> > > > >         if(action.equals("populate"))
> > > > >         {
> > > > >             prodSelection.setResults(order.getProducts());
> > > > >         }
> > > > >
> > > > >         if(action.equals("Delete"))
> > > > >         {
> > > > >             ArrayList p = new ArrayList();
> > > > >             p = prodSelection.getResults();
> > > > >
> > > > >             int count = 0;
> > > > >             while (count < p.size())
> > > > >             {
> > > > >                 Product t  = (Product) p.get(count);
> > > > >                 t.setDescription("" +t.getNumProducts() +">"
> > > > +pageRes.size()
> > > > > +"<");
> > > > >                 p.set(count, t);
> > > > >                 count++;
> > > > >             }
> > > > >
> > > > >             t.setDescription("" +t.getNumProducts() +">"
> +p.size()
> > > > +"<");
> > > > >             p.set(0, t);
> > > > >
> > > > >             user.setOrder(p , user);
> > > > >             prodSelection.setResults(p);
> > > > >             prodSelection.setTest(prodSelection.getTest()+" + "
> +
> > p.size
> > > > ());
> > > > >
> > > > >             return mapping.findForward("success");
> > > > >         }
> > > > >         return mapping.findForward("success");
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Form code: (In the form code is an ArrayList called
> results.  This
> > > > arraylist
> > > > > contains  a bunch of Product )
> > > > >
> > > > >     public Product getResultsPage(int index)
> > > > >     {
> > > > >         if(this.results == null)
> > > > >         {
> > > > >             this.results = new ArrayList();
> > > > >         }
> > > > >
> > > > >         while(index >= this.results.size())
> > > > >         {
> > > > >             this.results.add (new Product());
> > > > >         }
> > > > >         return (Product) results.get(index);
> > > > >     }
> > > > >
> > > > >     public void setResultsPage(int index, Product p)
> > > > >     {
> > > > >         if(this.results == null)
> > > > >         {
> > > > >             this.results = new ArrayList();
> > > > >         }
> > > > >
> > > > >         while(index >= this.results.size())
> > > > >         {
> > > > >             this.results.add(new Product());
> > > > >         }
> > > > >         results.set(index, p);
> > > > >         //return (Product) results.get(index);
> > > > >     }
> > > > >
> > > > >     public void setResults(ArrayList results)
> > > > >     {
> > > > >        this.results=results;
> > > > >     }
> > > > >
> > > > >     public ArrayList getResults()
> > > > >     {
> > > > >        return this.results;
> > > > >     }
> > > > >
> > > > >
> > > > >
> > > > > Products is an object that stores various things about a product
>
> > with
> > > > > numProducts, and description being two of those things.
> > > > > Within Products is both getter and setter methods for the
> > numProducts as
> > > > > well as description.
> > > > >
> > > > >
> > > > >
> > > > > Thanks so much for any help you may be able to provide.
> > > > >
> > > > >
> > > >
> > > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>

Reply via email to