Re: Help: and form input fields

2001-01-05 Thread Chandan Kulkarni



My orderform bean has
 
   public OrderItem getItems(int 
index )   // this is used during the 
setProperty...   public ArrayList 
getItems() 
// This is used by the iterate tag    
public void setItems(int index,OrderItem str)
    public void setItems(ArrayList arr) 

My OrderItem bean has
 
    public String 
getItemName()    public String 
getQuantity()    public void setItemName(String 
str)    public void setQuantity(String str)
 
 
Hope that helps...
 
    -Chandan.
 

  -Original Message-From: 
  Mishkin Berteig <[EMAIL PROTECTED]>To: [EMAIL PROTECTED] 
  <[EMAIL PROTECTED]>Date: 
  Friday, January 05, 2001 12:05 PMSubject: Re: Help: 
   and form input fieldsHow does your 
  orderform bean look? What are the method signatures for the items property? 
  Thanks, Mishkin. 


Re: Help: and form input fields

2001-01-05 Thread Chandan Kulkarni



 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  does not work 
as expected...I had to use the input tag...)
 

   Item Name  
  Quantity       

   
  <% int count=0; %>  
        
      " value="<%= 
  ((OrderItem)orderlist).getItemName() %>"  />     
     
      " value="<%= 
  ((OrderItem)orderlist).getQuantity() %>"  />   
      
  
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: 
   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: 
  
       
  ITEM:Quantity   
         
  Pencil      
       
  Pencil      
       
  Pencil    
   ...  
  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:  and form input fields 
   Are you trying 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/

/*
 * $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 provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in
 *the documentation and/or other materials provided with the
 *distribution.
 *

Re: PropertyUtils handling multiple getter methods

2000-12-28 Thread Chandan Kulkarni



Thanks for the explanation...
 
I mistyped in my mail before - I did have 2 getters for the 
getItems(), one simple and one indexed.
 
After writing the mail I did write a test and I did 
figure out I had misunderstood the code getPropertyDescriptors gets one 
descriptor for each property -  not 2 if there are 2 
getters...
 
It turns out the only changes I need to make are to  
BeanUtils.java to handle setting of  indexed  and 
nested properties within a 
 
Thanks again,
 
    -Chandan.

  -Original Message-From: 
  Craig R. McClanahan <[EMAIL PROTECTED]>To: 
  [EMAIL PROTECTED] 
  <[EMAIL PROTECTED]>Cc: 
  [EMAIL PROTECTED] 
  <[EMAIL PROTECTED]>; 
  Chandan Kulkarni <[EMAIL PROTECTED]>Date: 
  Thursday, December 28, 2000 5:04 PMSubject: Re: PropertyUtils 
  handling multiple getter methodsSee below. 
  Chandan Kulkarni wrote: 
    I had a question about this 
part of PropertyUtils.java.     public 
static PropertyDescriptor getPropertyDescriptor(Object bean, 
  
String name)   PropertyDescriptor descriptors[] = 
getPropertyDescriptors(bean);  if (descriptors == null)     return (null); 
 for (int i = 0; i < 
descriptors.length; i++) {  if 
(name.equals(descriptors[i].getName()))   
return (descriptors[i]);  
}The method 
getPropertyDescriptorcalls    
getPropertyDescriptors(bean)and iterates through them to get a match on the 
name. Incase the Bean class 
contains  ArrayList items; It requires to have 2 getItems methods 1)   ArrayList 
getItems() - to be used when you use 
the    
2)  It also 
requires an indexed getter    Item 
getItem(int index)    to handle the form input fields within 
the iterate tag. If you find the wrong descriptor 
first, you get a NoSuchMethodExceptionI propose getPropertyDescriptor take 
another parameter (which says whether its an Indexedproperty we are looking 
for) or create anothergetIndexedPropertyDescriptor. I'll probably do that to handle nested, indexed properties to get 
 to work...   -Chandan.
  PropertyUtils is using the standard JavaBeans introspection under the 
  covers, in order to identify the actual method names of the getters and 
  setters.  In particular, you are required to use the property naming 
  conventions outlined in the JavaBeans specification, version 1.0.1. 
  In your example above, you are using two different property names ("items" 
  versus "item"), so the introspection code will consider those to be two 
  different properties.  It is legal to provide both array-based and 
  index-based getters and setters for the same property, but you must use the 
  same name -- for example: 
      Item[] getItems();     Item 
  getItems(int index);     void setItems(Item items[]); 
      void setItems(int index, Item item); 
  If you do this, PropertyUtils uses the following algorithm to retrieve an 
  indexed property value at a particular subscript: * If there is an indexed 
  getter (Item getItems(int index)),   call it directly * 
  Otherwise, call the array getter (Item[] getItems()) and   access the 
  requested element out of the array. 
  Craig McClanahan   


PropertyUtils handling multiple getter methods

2000-12-27 Thread Chandan Kulkarni



 
I had a question about this part of 
PropertyUtils.java.
 

 
        
public static PropertyDescriptor getPropertyDescriptor(Object 
bean,    
          String name)
 

 
     PropertyDescriptor descriptors[] = 
getPropertyDescriptors(bean);     if (descriptors == 
null)     return 
(null);     for (int i = 0; i < descriptors.length; 
i++) {     if 
(name.equals(descriptors[i].getName())) 
     return 
(descriptors[i]);     }

The method getPropertyDescriptor  

calls 
        
getPropertyDescriptors(bean)
and iterates through them to get a match on the 
name.
 
Incase the Bean class contains
      ArrayList items;
 
It requires to have 2 getItems methods
 1)   ArrayList getItems() - to be used when 
you use the 
            
 
2)  It also requires an indexed getter
        Item getItem(int 
index)
    to handle the form input fields within the 
iterate tag.
 
If you find the wrong descriptor first, you get a 
NoSuchMethodException
I propose getPropertyDescriptor take another parameter 
(which says whether its an  Indexed
property we are looking for) or create another
getIndexedPropertyDescriptor.
 
I'll probably do that to handle nested, indexed properties to 
get  to work...
 
  -Chandan.
 


Re: Help: and form input fields

2000-12-27 Thread Chandan Kulkarni



Yes...same idea...

  -Original Message-From: 
  Ted Husted <[EMAIL PROTECTED]>To: 
  Struts List <[EMAIL PROTECTED]>Date: 
  Wednesday, December 27, 2000 10:36 AMSubject: Re: Help: 
   and form input fields
  Are you trying 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/



Re: Help: and form input fields

2000-12-27 Thread Chandan Kulkarni



 
I'm trying to use  within a form that 
contains a Collection of OrderItems to create the appropriate input 
fields.
 
Example Screen:
 
Order Number: 
List of Items:
Item Number Name    
Quantity
--    
   -
--    
   -
--    
   -
--    
   -
--    
   -
 
(where --- are form input fields)
The bean the form uses is the OrderForm. It contains an 
ArrayList of OrderItems. An OrderItem is an object with 3 fields 
ItemNumber, Name, Quantity. 
 
Using  to iterate over the ArrayList of 
OrderItems,  and the struts form tags I am trying to generate the correct 
input lines for each OrderItem.
 
Using 


 
... does not work as required. It generate several lines 
with the same name for itemNumber for each item in the OrderItems ArrayList. 
When the form is submitted the struts framework cannot get the right values 
to set the OrderItems ArrayList with the correct values.
 
Setting the OrderItems collection within the OrderForm 
bean is where the problem is... Getting values can be worked around by using 

    
value="<%= ((OrderItem)orderlist).getItemNumber() %>" />
 
(which I had showed below)
 
Hope that helps
 
   -Chandan.    
 
 

  -Original Message-From: 
  Ted Husted <[EMAIL PROTECTED]>To: 
  Struts List <[EMAIL PROTECTED]>Date: 
  Wednesday, December 27, 2000 9:50 AMSubject: Re: Help: 
   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...
   
  " 
      
  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  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: 
 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.
 
        
     

 
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  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 parts of my 
orderform.jsp==
 

 
 Order Number 
:    
   
...<% int count=0; %>  
          
value="<%= ((OrderItem)orderlist).getItemNumber() %>" />  
    <% count++; 
%>
 
==
 
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  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:
 
    " value="<%= 
((Orde

Re: Help: and form input fields

2000-12-27 Thread Chandan Kulkarni



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...
 
" 
    
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  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: 
   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.
   
          
       
  
   
  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  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 parts of my 
  orderform.jsp==
   
  
   
   Order Number : 
     
     
  ...<% int count=0; %>  
            
  value="<%= ((OrderItem)orderlist).getItemNumber() %>" />  
      <% count++; 
  %>
   
  ==
   
  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  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:
   
      " 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


Help: and form input fields

2000-12-26 Thread Chandan Kulkarni



I am trying to use  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 parts of my 
orderform.jsp==
 

 
 Order Number : 
      
...<% int count=0; %>  
          
value="<%= ((OrderItem)orderlist).getItemNumber() %>" />  
    <% count++; 
%>
 
==
 
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  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:
 
    " 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