Re: Getting index value of iteration

2004-06-25 Thread Ron Grabowski
> <%-- Nested tag way Notice how much less to write out--%>
> 
> 
>  Division: 
>  
>  --- Department: 
>  
> 

Thanks for the code snippet Rick. It helped trim down a lot of code.

Whenever I would try and submit the form I was getting
BeanUtil.populate errors. I tracked down this email from November 2002:

http://tinyurl.com/26w69
"
> 
> if I set the action scope="request" I get:
> javax.servlet.ServletException: BeanUtils.populate
> ...
> Caused by: java.lang.IndexOutOfBoundsException: Index: 2, Size: 0
> or
> Caused by: java.lang.NullPointerException
> 
> make sure you don't have scope="request" in your 
> 
"

Do you _have_ to put forms that use nested beans in session scope?
Using your example, my getters/setters would look something like:

public void setDivisions(Divisions[] divisions) {
this.divisions = divisions;
}

public Divisionsa[] getDivisions() {
return this.divisions;
}

On my action, having scope="request" would cause problems. Changing
that to scope="session" solved the problem.

Do you know of a way I can avoid storing the ActionForm in the session?
I've caught a few references to Common's LazyList (page was formatted
correctly in Google cache under Mozilla 1.7 but not when the original
url was clicked on):

 http://tinyurl.com/yqot7

Should I declare this.divisions to be some sort of List or LazyList
instead of Divisions[]?

Is any of this making sense?

Thanks,
Ron

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Getting index value of iteration

2004-06-25 Thread Mark Lowe
I'm using spring too, albeit not for the web stuff.
Haven't looked into spring web tier wise, not sure it has anything for 
forms.

On 25 Jun 2004, at 17:23, Rick Reumann wrote:
Mark Lowe wrote:
Thanks Rick.
You've shown me exactly how to do what i need do and I didn't even 
ask  the question :o)
Glad I could help. Someone actually showed me how to do that using 
JSTL. He's now moved on to using Spring now that loser:)

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


Re: Getting index value of iteration

2004-06-25 Thread Rick Reumann
Mark Lowe wrote:
Thanks Rick.
You've shown me exactly how to do what i need do and I didn't even ask  
the question :o)
Glad I could help. Someone actually showed me how to do that using JSTL. 
He's now moved on to using Spring now that loser:)

--
Rick
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Getting index value of iteration

2004-06-25 Thread Mark Lowe
Thanks Rick.
You've shown me exactly how to do what i need do and I didn't even ask  
the question :o)

2 deep indexed properties and no nested tag llib.

On 25 Jun 2004, at 16:03, Rick Reumann wrote:
Wendy Smoak wrote:
From: Tom McCobb [mailto:[EMAIL PROTECTED] In another section  
of the page I display an iterated list of items in a collection. I  
am stuck on how to get the value of "i", the index of the row
wherein the button was clicked.
Are you willing to use JSTL?  The  tag has 'varStatus'  
which
will give you the integer position as you loop through the collection.
This won't be exactly right, I haven't worked with it for a while,
but...

 

Are these links, or do you need to submit the form with the index as  
one
of the form properties?  Do you have any objection to JavaScript?
With Struts-EL and JSTL, I haven't needed to venture into the Nested
taglib, although I understand there are things it can do that
Struts-EL/JSTL cannot.  This may be one of them...
Actually you can do everything with JSTL/EL that the nested tag does,  
but I must admit the nested tag makes things cleaner. In the above it  
doesn't matter much because you don't have Lists nested within each  
other.

Imagine a case, though, where you had a Company object that a  
Collection of divisions and then each division had a collection of  
departments and you want to display a form that lest you edit the  
departments in each division. You'll see the benefit of nested below  
(sorry for the ugly wrapping you'll get. If you want I can send the  
example to you offlist).

<%-- JSTL way --%>


Division: 

	
		--- Department: 



<%-- Nested tag way Notice how much less to write out--%>

Division: 

--- Department: 



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


Re: Getting index value of iteration

2004-06-25 Thread Rick Reumann
Wendy Smoak wrote:
From: Tom McCobb [mailto:[EMAIL PROTECTED] 
In another section of the page I display an iterated list of 
items in a collection. 
I am stuck on how to get the value of "i", the index of the row
wherein the button was clicked.
Are you willing to use JSTL?  The  tag has 'varStatus' which
will give you the integer position as you loop through the collection.
This won't be exactly right, I haven't worked with it for a while,
but...

 



Are these links, or do you need to submit the form with the index as one
of the form properties?  Do you have any objection to JavaScript?
With Struts-EL and JSTL, I haven't needed to venture into the Nested
taglib, although I understand there are things it can do that
Struts-EL/JSTL cannot.  This may be one of them...
Actually you can do everything with JSTL/EL that the nested tag does, 
but I must admit the nested tag makes things cleaner. In the above it 
doesn't matter much because you don't have Lists nested within each other.

Imagine a case, though, where you had a Company object that a Collection 
of divisions and then each division had a collection of departments and 
you want to display a form that lest you edit the departments in each 
division. You'll see the benefit of nested below (sorry for the ugly 
wrapping you'll get. If you want I can send the example to you offlist).

<%-- JSTL way --%>


Division: 

	
		--- Department: 



<%-- Nested tag way Notice how much less to write out--%>

Division: 

--- Department: 



--
Rick
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Getting index value of iteration

2004-06-24 Thread Tom McCobb
Thanks for these replies and the generous code samples.  I got frustrated
with the nested tag and re-wrote the iteration with jstl as Wendy suggested.
I had a few additional problems because I was using jstl 1.1 in a 2.3
container, but resolved that too.

-Original Message-
From: Wendy Smoak [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 23, 2004 5:46 PM
To: Struts Users Mailing List
Subject: RE: Getting index value of iteration


> From: Tom McCobb [mailto:[EMAIL PROTECTED]
> In another section of the page I display an iterated list of
> items in a collection.
> I am stuck on how to get the value of "i", the index of the row
wherein the button was clicked.

Are you willing to use JSTL?  The  tag has 'varStatus' which
will give you the integer position as you loop through the collection.
This won't be exactly right, I haven't worked with it for a while,
but...






Are these links, or do you need to submit the form with the index as one
of the form properties?  Do you have any objection to JavaScript?

With Struts-EL and JSTL, I haven't needed to venture into the Nested
taglib, although I understand there are things it can do that
Struts-EL/JSTL cannot.  This may be one of them...

--
Wendy Smoak
Application Systems Analyst, Sr.
ASU IA Information Resources Management

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



RE: Getting index value of iteration

2004-06-23 Thread Wendy Smoak
> From: Tom McCobb [mailto:[EMAIL PROTECTED] 
> In another section of the page I display an iterated list of 
> items in a collection. 
> I am stuck on how to get the value of "i", the index of the row
wherein the button was clicked.

Are you willing to use JSTL?  The  tag has 'varStatus' which
will give you the integer position as you loop through the collection.
This won't be exactly right, I haven't worked with it for a while,
but...


 



Are these links, or do you need to submit the form with the index as one
of the form properties?  Do you have any objection to JavaScript?

With Struts-EL and JSTL, I haven't needed to venture into the Nested
taglib, although I understand there are things it can do that
Struts-EL/JSTL cannot.  This may be one of them...

-- 
Wendy Smoak
Application Systems Analyst, Sr.
ASU IA Information Resources Management 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Getting index value of iteration

2004-06-23 Thread miguel angel rojas aquino
well, didn't know if this is what you're looking for, but recently i've 
discovered how to use indexed properties:

first, the jsp (sorry for the spanish comments):
<%@ taglib prefix="logic" uri="/WEB-INF/struts-logic.tld" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

Example of a Bean Based Purchase Order

Example of a Bean Based Purchase Order


Part Number
Quantity
Price


  
  
  






now in the ActionForm
package org.hospital;

import org.apache.struts.action.*;
import java.util.ArrayList;

public class PurchaseOrderBeanForm extends ActionForm {
/**
 * Propiedad Lines.
 * Almacena todo el conjunto de lineas
 */
private ArrayList lines = null;
/**
 * Devuelve el valor de la propiedad lines .
 *
 [EMAIL PROTECTED]  El valor actual de Lines
 */
public ArrayList getLines() {
return this.lines;
}
/**
 * Establece el nuevo valor para la propiedad lines .
 *
 [EMAIL PROTECTED] lines El nuevo valor para lines .
 */
public void setLines(ArrayList lines) {
this.lines = lines;
}
/**
 * Returns an linea object from the lines ArrayList.
 * It is related to the linea property in the jsp
 * 
 *
 [EMAIL PROTECTED]  El valor actual de Linea
 */
public POLine getLinea(int index) {
return (POLine)this.lines.get(index);
}
/**
 * Establece el nuevo valor para la propiedad linea.
 *
 [EMAIL PROTECTED] lines El nuevo valor para linea.
 */
public void setLinea(int index, POLine valor) {
   this.lines.add(index, valor);
}
/**
 * Propiedad Accion.
 */
private String accion = null;
/**
 * Devuelve el valor de la propiedad accion .
 *
 [EMAIL PROTECTED]  El valor actual de Accion
 */
public String getAccion() {
return this.accion;
}
/**
 * Establece el nuevo valor para la propiedad accion .
 *
 [EMAIL PROTECTED] accion El nuevo valor para accion .
 */
public void setAccion(String accion) {
this.accion = accion;
}
}
the POLine object:
package org.hospital;
public class POLine {
private String partNumber;
private String quantity;
private String price;
private double total;
public String getPartNumber() {
return partNumber;
}
public void setPartNumber(String partNumber) {
this.partNumber = partNumber;
}
public String getQuantity() {
return quantity;
}
public void setQuantity(String quantity) {
this.quantity = quantity;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public double getTotal() {
return total;
}
public void setTotal(double total) {
   this.total = total;
}
}
The Action:
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
public class GenerateBeanPO extends Action {
  String mapeo = "inicializa";
  public ActionForward execute(ActionMapping mapping,
   ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response)
  throws ServletException, IOException {
PurchaseOrderBeanForm poForm = (PurchaseOrderBeanForm) form;
ArrayList lines = new ArrayList();
System.out.println(" Estoy en GenerateBeanPO **");
//llenamos el ArrayList
if(poForm.getAccion() == null) {
  for(int i = 0; i < 10; i++) {
POLine linea = new POLine();
linea.setPartNumber(String.valueOf(i));
lines.add(linea);
  }
  poForm.setLines(lines);
  mapeo = "inicializa";
} else {
  try {
//recover ArrayList
ArrayList lineas = poForm.getLines();
//and show it
for (int i = 0; i < lineas.size(); i++) {
  POLine linea = (POLine)lineas.get(i);
  System.out.println("***");
  System.out.println("Articulo: " + linea.getPartNumber());
  System.out.println("Cantidad: " + linea.getQuantity());
  System.out.println("Precio:   " + linea.getPrice());
  System.out.println("***\n");
}
  }catch (Exception e) {
System.out.println("* Error ");
e.printStackTrace();

Getting index value of iteration

2004-06-23 Thread Tom McCobb
I have been pouring over all the posts and how-tos I can find on indexed
properties and indexed values in general, and I am just not getting it.
Here is what I am trying to do:

I have a search page in a section of my main jsp.  It returns results into a
SELECT, and the chosen item in the SELECT populates it's corresponding
property in the related Form.

In another section of the page I display an iterated list of items in a
collection.  In each row that is rendered, I have a text input control, and
a button next to it.  When the user clicks on the button, the idea is to
have the selected result from the search populate the text input control.

I call a method in the related Action class to retrieve the selected search
result, and then I need to put it into the correct detail item. THere is a
property in the detail item corresponding to the text input control.  So I
would like to do somthing like
collection[i].setDestIndex(srchForm.getSelText);  but I am stuck on how to
get the value of "i", the index of the row wherein the button was clicked.

I have tried setting up the iterate tag as:


.


There is an "index" property in the Form, and in the item class that is a
member of the collection being iterated over.

I cannot seem to catch the index property anywhere, either as a property in
struts or as request.getParameter("index").

I am sure this is easy  THanks for any ideas you can float my way, and
please use small words to match my minimal intellect 

T. McCobb


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]