Re: adding / creating new collection elements in a form

2003-06-08 Thread Rob
Hi Dan,

This seems to be the most promising solution as of yet.  I am
however a little unclear as to how this avoids the need for
a request for each row added.
If I understand what your describing the LookupDispatchAction
extension is for handling forms with multiple buttons.  As you
describe one of the operations of this action is to add a new
element to the collection from which I am populating the form
fields.
My confusion is that I don't see how a request is avoided for
every new row added.  I would like to add multiple rows to my
html form on the client side w/ javascript (making no request
to the server) and then allow the user to populate and when
submitted all new rows result in new instances of whatever
kind of object being added to the collection.
I can provide a more detailed explanation if it helps, I'm not
entirely sure I can do what I want to do with struts at this
point.
Rob

Dan Tran wrote:
I just implemented myself, so let me throw a shot at this.

In my case, I make my action derived from LookupDispatchAction
which can handle multiple button submission handlers.
One of the button is called something like addRow. When you hit this
addRow button, struts will repopolate what ever on your screen and dispatch
it
to your addRow handler where you can add new empty row to your collection
and forward back to your screen.
regarding your out of index problem, I would suggest to use common
Collection
ListUtils.lazyList.  Here is an example a lazy collection in a my form
private List gradeViews =  ListUtils.lazyList(new ArrayList(), new
GenericFactory(org.glvnsjc.view.StudentGradeView));
//there is no direct setXXX, call getXXX first and populate the object
// lazy list takes care all dynamic allocation
public StudentGradeView getGradeView(int index) {return
(StudentGradeView) gradeViews.get(index); }
public void removeAllGradeView() { this.gradeViews.clear(); }
public List getGradeViews() { return this.gradeViews;}
Please look up GenericFactory in the maling list, I dont want to repost it

If you dont know LookupDispatchAction yet, learn it.  It has the magic that
I cant live without
Good luck!!!

-Dan

- Original Message - 
From: Rob [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Saturday, June 07, 2003 8:55 AM
Subject: Re: adding / creating new collection elements in a form



Perhaps I was not making myself clear when I first posted this.

I know how to write the javascript, I know how to use struts
nested/logic tags.  What I was looking for when I posted was
a solution whereby I could add new elements to a collection
in a form.  Not update existing elements, thus increasing the
size of a collection based on properties from fields that
were added by client side scripting.



I've not been able to find a solution to this within the mailing
list.  But I would like to the following.
I have a page with a collection of fields which are populated by
a form (via it's collection).  I also have a button which would
allow the addition of a new row. (hopefully)
Name  Descrip
[ xy ][ foo   ]
[ ab ][ bar   ]
Add

(1) I would like to have the add button add a new pair of text
input fields each time it is clicked. (2) I would like it if
clicking add did not make a request to the server this being the
case it suggests some kind of client side javascript adding the
new fields.
The problems of course with this are the following.

(1) client side code won't be able to utilise the struts tags
   and as such I won't know what values to set the appropriate
   input text element attributes to.
(2) It is highly likely that even if I solved problem (1) that
   it would result in a IndexOutOfBounds exception, or just not
   bother with the properties from the new fields.
Has anyone else solved this?  Does struts have a mechanism for
dealing with this?  I'm fully aware of nested/logic tags but
if they are the way I can't see how.
Suggestions would be appreciated, Thanks!

Rob



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


Re: adding / creating new collection elements in a form

2003-06-07 Thread Rob
Perhaps I was not making myself clear when I first posted this.

I know how to write the javascript, I know how to use struts
nested/logic tags.  What I was looking for when I posted was
a solution whereby I could add new elements to a collection
in a form.  Not update existing elements, thus increasing the
size of a collection based on properties from fields that
were added by client side scripting.


I've not been able to find a solution to this within the mailing
list.  But I would like to the following.
I have a page with a collection of fields which are populated by
a form (via it's collection).  I also have a button which would
allow the addition of a new row. (hopefully)
 Name  Descrip
[ xy ][ foo   ]
[ ab ][ bar   ]
Add

(1) I would like to have the add button add a new pair of text
input fields each time it is clicked. (2) I would like it if
clicking add did not make a request to the server this being the
case it suggests some kind of client side javascript adding the
new fields.
The problems of course with this are the following.

(1) client side code won't be able to utilise the struts tags
and as such I won't know what values to set the appropriate
input text element attributes to.
(2) It is highly likely that even if I solved problem (1) that
it would result in a IndexOutOfBounds exception, or just not
bother with the properties from the new fields.
Has anyone else solved this?  Does struts have a mechanism for
dealing with this?  I'm fully aware of nested/logic tags but
if they are the way I can't see how.
Suggestions would be appreciated, Thanks!

Rob

-
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: adding / creating new collection elements in a form

2003-06-07 Thread Dan Tran
I just implemented myself, so let me throw a shot at this.

In my case, I make my action derived from LookupDispatchAction
which can handle multiple button submission handlers.
One of the button is called something like addRow. When you hit this
addRow button, struts will repopolate what ever on your screen and dispatch
it
to your addRow handler where you can add new empty row to your collection
and forward back to your screen.

regarding your out of index problem, I would suggest to use common
Collection
ListUtils.lazyList.  Here is an example a lazy collection in a my form

private List gradeViews =  ListUtils.lazyList(new ArrayList(), new
GenericFactory(org.glvnsjc.view.StudentGradeView));

//there is no direct setXXX, call getXXX first and populate the object
// lazy list takes care all dynamic allocation
public StudentGradeView getGradeView(int index) {return
(StudentGradeView) gradeViews.get(index); }
public void removeAllGradeView() { this.gradeViews.clear(); }
public List getGradeViews() { return this.gradeViews;}

Please look up GenericFactory in the maling list, I dont want to repost it

If you dont know LookupDispatchAction yet, learn it.  It has the magic that
I cant live without

Good luck!!!

-Dan


- Original Message - 
From: Rob [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Sent: Saturday, June 07, 2003 8:55 AM
Subject: Re: adding / creating new collection elements in a form


 Perhaps I was not making myself clear when I first posted this.

 I know how to write the javascript, I know how to use struts
 nested/logic tags.  What I was looking for when I posted was
 a solution whereby I could add new elements to a collection
 in a form.  Not update existing elements, thus increasing the
 size of a collection based on properties from fields that
 were added by client side scripting.



  I've not been able to find a solution to this within the mailing
  list.  But I would like to the following.
 
  I have a page with a collection of fields which are populated by
  a form (via it's collection).  I also have a button which would
  allow the addition of a new row. (hopefully)
 
   Name  Descrip
  [ xy ][ foo   ]
  [ ab ][ bar   ]
 
  Add
 
  (1) I would like to have the add button add a new pair of text
  input fields each time it is clicked. (2) I would like it if
  clicking add did not make a request to the server this being the
  case it suggests some kind of client side javascript adding the
  new fields.
 
  The problems of course with this are the following.
 
  (1) client side code won't be able to utilise the struts tags
  and as such I won't know what values to set the appropriate
  input text element attributes to.
  (2) It is highly likely that even if I solved problem (1) that
  it would result in a IndexOutOfBounds exception, or just not
  bother with the properties from the new fields.
 
  Has anyone else solved this?  Does struts have a mechanism for
  dealing with this?  I'm fully aware of nested/logic tags but
  if they are the way I can't see how.
 
  Suggestions would be appreciated, Thanks!
 
  Rob
 
 
  -
  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]



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



adding / creating new collection elements in a form

2003-06-06 Thread Rob
I've not been able to find a solution to this within the mailing
list.  But I would like to the following.
I have a page with a collection of fields which are populated by
a form (via it's collection).  I also have a button which would
allow the addition of a new row. (hopefully)
 Name  Descrip
[ xy ][ foo   ]
[ ab ][ bar   ]
Add

(1) I would like to have the add button add a new pair of text
input fields each time it is clicked. (2) I would like it if
clicking add did not make a request to the server this being the
case it suggests some kind of client side javascript adding the
new fields.
The problems of course with this are the following.

(1) client side code won't be able to utilise the struts tags
and as such I won't know what values to set the appropriate
input text element attributes to.
(2) It is highly likely that even if I solved problem (1) that
it would result in a IndexOutOfBounds exception, or just not
bother with the properties from the new fields.
Has anyone else solved this?  Does struts have a mechanism for
dealing with this?  I'm fully aware of nested/logic tags but
if they are the way I can't see how.
Suggestions would be appreciated, Thanks!

Rob

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


Re: adding / creating new collection elements in a form

2003-06-06 Thread Sashi Ravipati
I have a javascript wich woks, u can give it a try, replace the html
tags with Struts Html tags, it should work

html
head
titleadding table rows with input elements
/title
script type=text/javascript

var TDCount = 0;

function insertTableRow(id)
{
var table = document.getElementById(id);

// get number of current rows
var rowItems = table.getElementsByTagName(tr);
var rowCount = rowItems.length;

// insert the new row
var newRow = table.insertRow(rowCount);

// get count of cells for the last row (so we know how many to insert)
var cellItems = rowItems[rowCount-1].getElementsByTagName(td);
var cellCount = cellItems.length;

// loop over the children of the last set of cells
for (i=0; icellCount; i++)
{
  // insert an analagous cell
  var cell = newRow.insertCell(i);
  
  // get the children of each cell
  var kids = cellItems[i].childNodes;

  for (j=0; jkids.length; j++)
  {
var newChild = kids[j].cloneNode(true);

// copy data into this cell
cell.appendChild(newChild);
  }
}
}
/script

/head
body
form name=form1 method=GET action=
table width=75% border=1 id=mytable
  tr
tdinput name=BEGINDATE type=text id=CPUtype/td
tdSELECT
NAME=SPLCODEOPTIONONE/OPTIONOPTIONTWO/OPTIONOPTIONTHREE/OPTION/SELECT/td
tdinput name=ENDDATE type=text id=CPUSerial1/td
  /tr
 
/table
br
input type=button name=addRow value=Add Row
onClick=insertTableRow('mytable')
INPUT TYPE=SUBMIT VALUE=SUBMIT
a href=javascript:insertTableRow('mytable')Add Row/a/
/form

/body
/html

 [EMAIL PROTECTED] 06/06/03 06:38PM 
I've not been able to find a solution to this within the mailing
list.  But I would like to the following.

I have a page with a collection of fields which are populated by
a form (via it's collection).  I also have a button which would
allow the addition of a new row. (hopefully)

  Name  Descrip
[ xy ][ foo   ]
[ ab ][ bar   ]

Add

(1) I would like to have the add button add a new pair of text
input fields each time it is clicked. (2) I would like it if
clicking add did not make a request to the server this being the
case it suggests some kind of client side javascript adding the
new fields.

The problems of course with this are the following.

(1) client side code won't be able to utilise the struts tags
 and as such I won't know what values to set the appropriate
 input text element attributes to.
(2) It is highly likely that even if I solved problem (1) that
 it would result in a IndexOutOfBounds exception, or just not
 bother with the properties from the new fields.

Has anyone else solved this?  Does struts have a mechanism for
dealing with this?  I'm fully aware of nested/logic tags but
if they are the way I can't see how.

Suggestions would be appreciated, Thanks!

Rob


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


Re: adding / creating new collection elements in a form

2003-06-06 Thread Vic Cekvenich
Get a multi row to work by itslef first. (without JavaScript add) and 
unit test.

Once you get this working, saving, you can just view HTML (in the 
working browser )  and realize that struts just emits standard form HTML.
You can examine this HTML and get your .js to emit same via add button.

hth,

Rob wrote:

I've not been able to find a solution to this within the mailing
list.  But I would like to the following.
I have a page with a collection of fields which are populated by
a form (via it's collection).  I also have a button which would
allow the addition of a new row. (hopefully)
 Name  Descrip
[ xy ][ foo   ]
[ ab ][ bar   ]
Add

(1) I would like to have the add button add a new pair of text
input fields each time it is clicked. (2) I would like it if
clicking add did not make a request to the server this being the
case it suggests some kind of client side javascript adding the
new fields.
The problems of course with this are the following.

(1) client side code won't be able to utilise the struts tags
and as such I won't know what values to set the appropriate
input text element attributes to.
(2) It is highly likely that even if I solved problem (1) that
it would result in a IndexOutOfBounds exception, or just not
bother with the properties from the new fields.
Has anyone else solved this?  Does struts have a mechanism for
dealing with this?  I'm fully aware of nested/logic tags but
if they are the way I can't see how.
Suggestions would be appreciated, Thanks!

Rob


--
Vic Cekvenich,
Struts Instructor,
1-800-917-JAVA
Advanced a href =baseBeans.comStruts Training/a and project recovery in North 
East.
Open Source a href =baseBeans.comContent Management/a  basicPortal sofware
Best practicea href =baseBeans.comStruts Support/a v.1.1 helper ScafflodingXPress


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