Re: shopping cart, dynamic field names

2005-11-23 Thread Danny Lee

Here's a snippet from my checkout.jsp:

 c:forEach var=item items=${checkOutForm.cartEntries} 
varStatus=status


 c:if test=${status.index%2==1}
  TR  bgcolor=#ECECFF
  /c:if
   c:if test=${status.index%2==0}
  TR bgcolor=#FFECFA
  /c:if 
  TDA href=../showProduct.do?id=${item.productID}
	IMG src=images/product_pix/${item.productID}_mini.jpg border=0 
align=left height=40/a/TD
TDfont face=Verdana size=2	c:out 
value=${item.productName}//TD
TDfont face=Verdana size=2	fmt:formatNumber 
value=${item.productPrice} type=currency currencySymbol=euro;//TD

TDfont face=Verdana size=2bx/b html:text
   property=cartEntries[${status.index}].productCount
   value=${item.productCount}
   size=1//TDTD align=lefthtml-el:link

href=../CheckOut.do?DIALOG-EVENT-DELETEproductID=${item.productID}
html:img src=../jsp/images/trash.gif border=0 
align=left/

/html-el:link/TD
/TR
/c:forEach

Well, you see, it's quite easy :) The only thing I have to do after user 
submitting the data, is to persist the given cartEntries[].productCount, 
becouse my shoppingcart is in the database (which is more safe and easer 
to analye with some stastic apps later).


Chhers,

Danny

P.S. And yes, I use Struts Dialogs :)


David Evans schrieb:

Sorry, I've search for hours but can't seem to find the answer to this
basic problem.

I'm building a shopping cart for the first time in struts. I have a
display cart jsp that will show each item, and as expected, i have a qty
textbox for each item and an update cart button. so each qty field will
have to have, as part of its name, an id to tie it to the particular
item in the cart. there is another field in each row, a remove
checkbox, so i can't just name it the id. the cart hangs out in the
session scope, and has a List of CartItem objects called items.  the
action, when called to show the cart, will call cart.getItems() and
stick the List in the request, so that it can easily be referenced by
the c:foreach tag that i will be using to create the html. So the only
way i can figure to get those qty fields in the request to be set in the
ActionForm, upon form submission, is to use a map in the ActionForm,
since i won't know how many items there will be. So the ActionForm ends
up with all of the qty fields in the map, with the key being the name
attribute from the textbox, and the value being the quantity typed in by
the user. So in the action upon form submission i can iterate through
the keys, filter out all keys that start with qty and update the qty
for those items.

So this seems a little hackish, i was wondering if there's a better way,
and secondly, what exactly do i have to name those textboxes to get
struts to recognize that they are pointing to a Map. I'm guessing that
it will be mapname.key, is that correct?

Dave



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



Re: shopping cart, dynamic field names

2005-11-23 Thread Bednarz, id-on GmbH
printx.org


*** REPLY SEPARATOR  ***

On 23.11.2005 at 15:06 Danny Lee wrote:

Here's a snippet from my checkout.jsp:

  c:forEach var=item items=${checkOutForm.cartEntries}
varStatus=status

  c:if test=${status.index%2==1}
   TR  bgcolor=#ECECFF
   /c:if
c:if test=${status.index%2==0}
   TR bgcolor=#FFECFA
   /c:if
   TDA href=../showProduct.do?id=${item.productID}
   IMG src=images/product_pix/${item.productID}_mini.jpg border=0
align=left height=40/a/TD
 TDfont face=Verdana size=2c:out
value=${item.productName}//TD
 TDfont face=Verdana size=2fmt:formatNumber
value=${item.productPrice} type=currency currencySymbol=euro;//TD
 TDfont face=Verdana size=2bx/b html:text
property=cartEntries[${status.index}].productCount
value=${item.productCount}
size=1//TDTD align=lefthtml-el:link

href=../CheckOut.do?DIALOG-EVENT-DELETEproductID=${item.productID}
 html:img src=../jsp/images/trash.gif border=0
align=left/
 /html-el:link/TD
 /TR
 /c:forEach

Well, you see, it's quite easy :) The only thing I have to do after user
submitting the data, is to persist the given cartEntries[].productCount,
becouse my shoppingcart is in the database (which is more safe and easer
to analye with some stastic apps later).

Chhers,

Danny

P.S. And yes, I use Struts Dialogs :)


David Evans schrieb:
 Sorry, I've search for hours but can't seem to find the answer to this
 basic problem.

 I'm building a shopping cart for the first time in struts. I have a
 display cart jsp that will show each item, and as expected, i have a qty
 textbox for each item and an update cart button. so each qty field will
 have to have, as part of its name, an id to tie it to the particular
 item in the cart. there is another field in each row, a remove
 checkbox, so i can't just name it the id. the cart hangs out in the
 session scope, and has a List of CartItem objects called items.  the
 action, when called to show the cart, will call cart.getItems() and
 stick the List in the request, so that it can easily be referenced by
 the c:foreach tag that i will be using to create the html. So the only
 way i can figure to get those qty fields in the request to be set in the
 ActionForm, upon form submission, is to use a map in the ActionForm,
 since i won't know how many items there will be. So the ActionForm ends
 up with all of the qty fields in the map, with the key being the name
 attribute from the textbox, and the value being the quantity typed in by
 the user. So in the action upon form submission i can iterate through
 the keys, filter out all keys that start with qty and update the qty
 for those items.

 So this seems a little hackish, i was wondering if there's a better way,
 and secondly, what exactly do i have to name those textboxes to get
 struts to recognize that they are pointing to a Map. I'm guessing that
 it will be mapname.key, is that correct?

 Dave


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


Mit freundlichen Grüßen

Andreas Bednarz
...
ID.on GmbH
DESIGN and BUSINESS INTELLIGENCE
...
Wagenerstraße 3 | 30169 Hannover
Fon +49(0) 511.93 62 28 - 22
Fax +49 (0)511.93 62 28 - 28
E-Mail [EMAIL PROTECTED]
...
http://www.id-on.de
http://www.e-konfigurator.de





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



Re: shopping cart, dynamic field names

2005-11-23 Thread David Evans
Thank you for your reply.  So in your ActionForm you have a List
property called cartEntries? And the struts populating mechanism is
aware of this because you have the [] characters in the textbox name,
right? And the cartEntries list contains a CartEntry object which has a
productCount property, and the struts populating mechanism puts the
value submitted by the textbox in the productCount property? What
advantage is gained, if any, by using the html:text tag, instead of just
using an html input type=text tag? I have so far preferred using jstl
only in my view layer.

For your delete from cart functionality, you have a link to delete the
object. The view layer specification i am working with requires a
checkbox, so that multiple records can be deleted at once, by clicking
the update cart button. Since the checkbox only submits a value if it is
checked, do you know what will happen if the struts populate mechanism
receives set of request parameters that point to a list backed property,
when the request parameters' indexes are not consecutive?

Thanks for you help

Dave 



On Wed, 2005-11-23 at 15:06 +0100, Danny Lee wrote:
 Here's a snippet from my checkout.jsp:
 
   c:forEach var=item items=${checkOutForm.cartEntries} 
 varStatus=status
 
   c:if test=${status.index%2==1}
TR  bgcolor=#ECECFF
/c:if
 c:if test=${status.index%2==0}
TR bgcolor=#FFECFA
/c:if
TDA href=../showProduct.do?id=${item.productID}
   IMG src=images/product_pix/${item.productID}_mini.jpg border=0 
 align=left height=40/a/TD
  TDfont face=Verdana size=2   c:out 
 value=${item.productName}//TD
  TDfont face=Verdana size=2   fmt:formatNumber 
 value=${item.productPrice} type=currency currencySymbol=euro;//TD
  TDfont face=Verdana size=2bx/b html:text
 property=cartEntries[${status.index}].productCount
 value=${item.productCount}
 size=1//TDTD align=lefthtml-el:link
  
 href=../CheckOut.do?DIALOG-EVENT-DELETEproductID=${item.productID}
  html:img src=../jsp/images/trash.gif border=0 
 align=left/
  /html-el:link/TD
  /TR
  /c:forEach
 
 Well, you see, it's quite easy :) The only thing I have to do after user 
 submitting the data, is to persist the given cartEntries[].productCount, 
 becouse my shoppingcart is in the database (which is more safe and easer 
 to analye with some stastic apps later).
 
 Chhers,
 
 Danny
 
 P.S. And yes, I use Struts Dialogs :)
 
 
 David Evans schrieb:
  Sorry, I've search for hours but can't seem to find the answer to this
  basic problem.
  
  I'm building a shopping cart for the first time in struts. I have a
  display cart jsp that will show each item, and as expected, i have a qty
  textbox for each item and an update cart button. so each qty field will
  have to have, as part of its name, an id to tie it to the particular
  item in the cart. there is another field in each row, a remove
  checkbox, so i can't just name it the id. the cart hangs out in the
  session scope, and has a List of CartItem objects called items.  the
  action, when called to show the cart, will call cart.getItems() and
  stick the List in the request, so that it can easily be referenced by
  the c:foreach tag that i will be using to create the html. So the only
  way i can figure to get those qty fields in the request to be set in the
  ActionForm, upon form submission, is to use a map in the ActionForm,
  since i won't know how many items there will be. So the ActionForm ends
  up with all of the qty fields in the map, with the key being the name
  attribute from the textbox, and the value being the quantity typed in by
  the user. So in the action upon form submission i can iterate through
  the keys, filter out all keys that start with qty and update the qty
  for those items.
  
  So this seems a little hackish, i was wondering if there's a better way,
  and secondly, what exactly do i have to name those textboxes to get
  struts to recognize that they are pointing to a Map. I'm guessing that
  it will be mapname.key, is that correct?
  
  Dave
 
 
 -
 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: shopping cart, dynamic field names

2005-11-23 Thread Danny Lee

Cool site, thanks pal :)
I'm actually lived in Hannover 1999-2000, studied economics there...

Cheers,

Danny

Bednarz, id-on GmbH schrieb:

printx.org



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



Re: shopping cart, dynamic field names

2005-11-23 Thread Danny Lee
Hi David, yeap you got the stuff right. The only thing I forgot to tell 
you is: if you not using Struts dialogs you have to prepopulate the 
form. So you actually need two actions 1st for prepopulating of 
properties and 2nd for correlation with the user input. Or you just use 
Struts Dialogs, it's really simple and cool :)





David Evans schrieb:


What
advantage is gained, if any, by using the html:text tag, instead of just
using an html input type=text tag? I have so far preferred using jstl
only in my view layer.


Well, I'm don't know about advanteges of using html:text. But I just 
supose, that if the guys did that, it have certain meaning. BTW, I 
prefer JSTL in JSP too at the moment, becouse ppl say it's faster than 
pure Struts :)



For your delete from cart functionality, you have a link to delete the
object. The view layer specification i am working with requires a
skipped  receives set of request parameters that point to a list backed 
property,
when the request parameters' indexes are not consecutive?


Well, I'm not sure about the checkboxes, becouse I've never used them 
till now. There were lot of posts about checkboxes, so as far I know 
this is not so simple but can be done. My idea of delete was: don't 
make  delete too comfortable ;)))



Cheers,

Danny





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



shopping cart, dynamic field names

2005-11-22 Thread David Evans
Sorry, I've search for hours but can't seem to find the answer to this
basic problem.

I'm building a shopping cart for the first time in struts. I have a
display cart jsp that will show each item, and as expected, i have a qty
textbox for each item and an update cart button. so each qty field will
have to have, as part of its name, an id to tie it to the particular
item in the cart. there is another field in each row, a remove
checkbox, so i can't just name it the id. the cart hangs out in the
session scope, and has a List of CartItem objects called items.  the
action, when called to show the cart, will call cart.getItems() and
stick the List in the request, so that it can easily be referenced by
the c:foreach tag that i will be using to create the html. So the only
way i can figure to get those qty fields in the request to be set in the
ActionForm, upon form submission, is to use a map in the ActionForm,
since i won't know how many items there will be. So the ActionForm ends
up with all of the qty fields in the map, with the key being the name
attribute from the textbox, and the value being the quantity typed in by
the user. So in the action upon form submission i can iterate through
the keys, filter out all keys that start with qty and update the qty
for those items.

So this seems a little hackish, i was wondering if there's a better way,
and secondly, what exactly do i have to name those textboxes to get
struts to recognize that they are pointing to a Map. I'm guessing that
it will be mapname.key, is that correct?

Dave




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