Re: Help: logic:iterate and form input fields
I have this working now... Here's how I got this working I'm including my BeanUtils.java. Here's how my jsp looks (the form:text does not work as expected...I had to usethe input tag...) TABLE WIDTH=100% border=1TRTH Item Name /thTH Quantity /TH/TR % int count=0; %logic:iterate id="orderlist" name="orderform" property="items" length="2"tr TD input TYPE="TEXT" name="%= "items[" + count + "].itemName" %" value="%= ((OrderItem)orderlist).getItemName() %" / /tdTD input TYPE="TEXT" name="%= "items[" + count++ + "].quantity" %" value="%= ((OrderItem)orderlist).getQuantity() %" / /td /TR/logic:iterate/TABLE The name is the nested and indexed name. The value field needs to be explicitly set to get the value from the bean. The changes I made to BeanUtils.java is I commented out this code in public static void populate(Object bean, String prefix, String suffix, HttpServletRequest request) /* CK: int subscript = stripped.lastIndexOf("["); if (subscript = 0) // Remove subscript expression stripped = stripped.substring(0, subscript); CK: */ This keeps the indexed part of the name And then in public static void populate(Object bean, Hashtable properties) Added this code // Check to see if the name is nested or indexed - then use PropertyUtils.setProperty int indexed = name.lastIndexOf("["); int nested = name.lastIndexOf("."); if ((indexed = 0) || (nested = 0)) {try { PropertyUtils.setProperty( bean, name, Array.get(value, 0));}catch( java.lang.NoSuchMethodException e ) {} continue; } To handle the nested and indexed names by calling PropertyUtils.setProperty... Good luck, -Chandan Kulkarni. -Original Message-From: Mishkin Berteig [EMAIL PROTECTED]To: [EMAIL PROTECTED] [EMAIL PROTECTED]Cc: Chandan Kulkarni [EMAIL PROTECTED]Date: Thursday, January 04, 2001 10:43 PMSubject: Re: Help: logic:iterate and form input fieldsActually, I think I can add some clarification to this issue as I am encountering what I see as a similar problem. The basic goal is to create a form where there are a variable number of entries, all of which are the same type. The number of entries is determined at run-time, for example from rows in a database table. An example scenario would look something like this. Your Shopping Cart: ITEM: QUANTITY: Pencil 1___ Eraser 1___ Cheese 1___ (The quantities are text fields.) The list of items is generated at run-time from the things a person has clicked into their shopping cart, and the quantities are set at check-out time (by the user). The problem is that the iterate and form tags dont seem to work together for indexed properties. This is partially a problem with the underlying html. Each text field in a form needs a different name. In order to have these fields correspond to a specific index value in an indexed property, the names of the fields need to be parsed. The html might look something like this: form ... table tr tdITEM:/tdtdQuantity/td /tr tr tdPencil/tdtdinput type="text" name="item000" value="1"/td /tr tr tdPencil/tdtdinput type="text" name="item001" value="1"/td /tr tr tdPencil/tdtdinput type="text" name="item002" value="1"/td /tr /table ... /form When the submit button was hit, the request parameters would be parsed. I have just started working on this problem. Mishkin. Chandan Kulkarni wrote: Yes...same idea... -Original Message- From: Ted Husted [EMAIL PROTECTED] To: Struts List [EMAIL PROTECTED] Date: Wednesday, December 27, 2000 10:36 AM Subject: Re: Help: logic:iterate and form input fields Are you trying to do something like this order form (Javascript)https://public.wxxi.org/schedules/fm/voice-order.htmThis only shows one item, but the idea is that there would be one line for each item in a small inventory. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 425-0252; Fax 716 223-2506. -- http://www.husted.com/ /* * $Header: /home/cvspublic/jakarta-struts/src/share/org/apache/struts/util/BeanUtils.java,v 1.15 2000/11/13 17:31:05 mschachter Exp $ * $Revision: 1.15 $ * $Date: 2000/11/13 17:31:05 $ * * * * The Apache Software License, Version 1.1 * * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provi
Re: Help: logic:iterate and form input fields
How does your orderform bean look? What are the method signatures for the items property? Thanks, Mishkin. Chandan Kulkarni wrote: I have this working now...Here's how I got this workingI'm including my BeanUtils.java.Here's how my jsp looks (the form:text> does not work as expected...I had to use the input tag...) TABLE WIDTH=100% border=1> TR> TH> Item Name /th> TH> Quantity /TH> /TR>% int count=0; %> logic:iterate id="orderlist" name="orderform" property="items" length="2"> tr> TD> input TYPE="TEXT" name="%= "items[" + count + "].itemName" %>" value="%= ((OrderItem)orderlist).getItemName() %>" /> /td> TD> input TYPE="TEXT" name="%= "items[" + count++ + "].quantity" %>" value="%= ((OrderItem)orderlist).getQuantity() %>" /> /td> /TR> /logic:iterate> /TABLE> The name is the nested and indexed name. The value field needs to be explicitly set to get the value from the bean.The changes I made to BeanUtils.java isI commented out this code inpublic static void populate(Object bean, String prefix, String suffix, HttpServletRequest request) /* CK: int subscript = stripped.lastIndexOf("["); if (subscript >= 0) // Remove subscript expression stripped = stripped.substring(0, subscript); CK: */ This keeps the indexed part of the nameAnd then in public static void populate(Object bean, Hashtable properties)Added this code // Check to see if the name is nested or indexed - then use PropertyUtils.setProperty int indexed = name.lastIndexOf("["); int nested = name.lastIndexOf("."); if ((indexed >= 0) || (nested >= 0)) { try { PropertyUtils.setProperty( bean, name, Array.get(value, 0)); } catch( java.lang.NoSuchMethodException e ) { } continue; } To handle the nested and indexed names by calling PropertyUtils.setProperty...Good luck, -Chandan Kulkarni. S/MIME Cryptographic Signature
Re: Help: logic:iterate and form input fields
Actually, I think I can add some clarification to this issue as I am encountering what I see as a similar problem. The basic goal is to create a form where there are a variable number of entries, all of which are the same type. The number of entries is determined at run-time, for example from rows in a database table. An example scenario would look something like this. Your Shopping Cart: ITEM: QUANTITY: Pencil 1___ Eraser 1___ Cheese 1___ (The quantities are text fields.) The list of items is generated at run-time from the things a person has clicked into their shopping cart, and the quantities are set at check-out time (by the user). The problem is that the iterate and form tags dont seem to work together for indexed properties. This is partially a problem with the underlying html. Each text field in a form needs a different name. In order to have these fields correspond to a specific index value in an indexed property, the names of the fields need to be parsed. The html might look something like this: form ... > table> tr> td>ITEM:/td>td>Quantity/td> /tr> tr> td>Pencil/td>td>input type="text" name="item000" value="1">/td> /tr> tr> td>Pencil/td>td>input type="text" name="item001" value="1">/td> /tr> tr> td>Pencil/td>td>input type="text" name="item002" value="1">/td> /tr> /table> ... /form> When the submit button was hit, the request parameters would be parsed. I have just started working on this problem. Mishkin. Chandan Kulkarni wrote: Yes...same idea... -----Original Message- From: Ted Husted [EMAIL PROTECTED]> To: Struts List [EMAIL PROTECTED]> Date: Wednesday, December 27, 2000 10:36 AM Subject: Re: Help: logic:iterate> and form input fields Are you trying to do something like this order form (Javascript)https://public.wxxi.org/schedules/fm/voice-order.htmThis only shows one item, but the idea is that there would be one line for each item in a small inventory. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 425-0252; Fax 716 223-2506. -- http://www.husted.com/ S/MIME Cryptographic Signature
Re: Help: logic:iterate and form input fields
A clear statement of what you need to accomplish, without posing a particular implementation, might be helpful. I'm not exactly sure what it is you need to do. My first guess is that the part about "count" should be encapsulated in a bean, and not exposed to the JSP. But I'm not sure if I understand the business or application logic behind your question well enough. *** REPLY SEPARATOR ***On 12/27/2000 at 8:51 AM Chandan Kulkarni wrote: Actually OrderItem is an object with several fields. I trimmed it down to just one field to simplify the problem. So "items" is an ArrayList of OrderItems. I couldn't find the right combination of nested/indexed property names for the form:text tag to generate the correct input tag. Here's what I tried... form:text name="orderItems" property="%= "orderitems[" + count + "]" %" value="%= ((OrderItem)orderlist).getItemNumber() %" / When it can't find the correct property name in the bean it gives a compilation error.I used a run-time expression to create items[0].itemName. In this case the form:text tag is just ignored and is left in the html generated just as is... It seems the only way to use an indexed/nested property name is to use the input tag itself. I am using the struts 12/15 build Thanks, -Chandan -Original Message-From: Ted Husted [EMAIL PROTECTED]To: Struts List [EMAIL PROTECTED]Date: Tuesday, December 26, 2000 4:32 PMSubject: Re: Help: logic:iterate and form input fields If I understand the situation, you might be able to do this with an array of orderItem beans (orderItems), with getName and getValue methods. logic:iterate name="orderItems" id="orderItem" tr TD form:text name="orderItem" / /td /TR/logic:iterate form:text should then call getName and getValue for the name and value of each text field. getName might use and internal counter to give the text fields different names. *** REPLY SEPARATOR ***On 12/26/2000 at 3:50 PM Chandan Kulkarni wrote: I am trying to use logic:iterate to iterate through a list of order items.I cannot get it to work. I have seen several emails about patches for handling nested and indexed properties... OrderForm consists of an ArrayList of items. I have added indexed getters ArrayList getItems()and OrderItem getItems(int index) I can't see how an indexed setter would help for setting the properties of OrderItems. Here are partsof my orderform.jsp== form:form action="orderform.do" name="orderform" type="OrderForm" TABLETRTD Order Number : /TDTD form:text name="orderform" property="orderNumber" / /TD/TR ...% int count=0; %logic:iterate id="orderlist" name="orderform" property="items" length="2"tr TD form:text name="orderlist" property="itemNumber" value="%= ((OrderItem)orderlist).getItemNumber() %" / /td /TR% count++; %/logic:iterate form:submit//form:form== Unfortunately this generates input tags with identical names for each iteration. This is a problem when you try to set the properties in the items.The value= part of the form:text tag is a hack to get the values from the Bean. Since the name generated needs to be unique I replaced the form:text lines with input tags like this: input TYPE="TEXT" name="%= "items.itemName[" + count++ + "]" %" value="%= ((OrderItem)orderlist).getItemName() %" / the run-time expression used above cannot be used in the form:text property value, so you have to use the input tag. This still does not allow for setting the values in the OrderItem... Also what do you think of the name used above...should it be items[0].itemName (more semantically correct - I think) or should it be items.itemName[0]... I have tried both but that doesn't work... Does anyone have any pointers/suggestions to get this to work...? Thanks in advance -Chandan
Re: Help: logic:iterate and form input fields
Are youtrying to do something like this order form (Javascript) https://public.wxxi.org/schedules/fm/voice-order.htm This only shows one item, but the idea is that there would be one line for each item in a small inventory. -- Ted Husted, Husted dot Com, Fairport NY USA. -- Custom Software ~ Technical Services. -- Tel 716 425-0252; Fax 716 223-2506. -- http://www.husted.com/
Help: logic:iterate and form input fields
I am trying to use logic:iterate to iterate through a list of order items.I cannot get it to work. I have seen several emails about patches for handling nested and indexed properties... OrderForm consists of an ArrayList of items. I have added indexed getters ArrayList getItems()and OrderItem getItems(int index) I can't see how an indexed setter would help for setting the properties of OrderItems. Here are partsof my orderform.jsp== form:form action="orderform.do" name="orderform" type="OrderForm" TABLETRTD Order Number : /TDTD form:text name="orderform" property="orderNumber" / /TD/TR ...% int count=0; %logic:iterate id="orderlist" name="orderform" property="items" length="2"tr TD form:text name="orderlist" property="itemNumber" value="%= ((OrderItem)orderlist).getItemNumber() %" / /td /TR% count++; %/logic:iterate form:submit//form:form== Unfortunately this generates input tags with identical names for each iteration. This is a problem when you try to set the properties in the items.The value= part of the form:text tag is a hack to get the values from the Bean. Since the name generated needs to be unique I replaced the form:text lines with input tags like this: input TYPE="TEXT" name="%= "items.itemName[" + count++ + "]" %" value="%= ((OrderItem)orderlist).getItemName() %" / the run-time expression used above cannot be used in the form:text property value, so you have to use the input tag. This still does not allow for setting the values in the OrderItem... Also what do you think of the name used above...should it be items[0].itemName (more semantically correct - I think) or should it be items.itemName[0]... I have tried both but that doesn't work... Does anyone have any pointers/suggestions to get this to work...? Thanks in advance -Chandan