Re: Can a collection property have its changes saved back to the ActionForm?

2010-03-22 Thread Andrew Sharpe
Thanks Adam.  I ended up using your solution.  I'm not thrilled about the user 
seeing the listbox items get auto selected after they submit the form, but the 
code is certainly cleaner than adding and removing hidden controls.  For the 
archives, here's what I went with:

JSP

function setStatus() {
var emailSelect = document.getElementById(emailSelect);
emailSelect.multiple = true;
emailSelect.focus(); // This is needed to force IE to execute the line 
above.
for (var i = 0; i  emailSelect.length; i++) {
emailSelect.options[i].selected = true;
}
}

html:select name=formName property=addresses 
onchange=setEmailButtonStatus(); size=4
html:options name=preferencesForm property=oldAddresses/
/html:select

ACTIONFORM

private String[] addresses;

public String[] getAddresses() {
return addresses;
}

public void setAddresses(String[] value) {
addresses = value;
}

private final ListString oldAddresses = new ArrayListString();

public ListString getOldAddresses() {
return oldAddresses;
}

Thanks again,

Andrew



- Original Message 
From: adam pinder apin...@hotmail.co.uk
To: user@struts.apache.org
Sent: Thu, March 18, 2010 6:11:27 AM
Subject: RE: Can a collection property have its changes saved back to the 
ActionForm?



you want to save the options in the select not a selected option...

if you make the select a multiple select and in javascript you select all 
options are all the option values sent to the server against the same 
parameter name (turn on parameter interceptor logging to check)... 

if so, add a set method in your action with the same name as the select element 
that accepts a string array, like

setNewRole(String[] newRoles)

inside this method you can initialise your proper ArrayList and add the 
elements from the string array into it.

you still need the javascript to select options but at least you're not 
creating new elements.

i haven't checked if multiple selects sends its parameters in this way but it 
works when multiple checkbox elements all have the same name and are sent as 
name/values pair.

ps. if i've misunderstood and you just want to save multiple selected options, 
then you can omit the javascript part which would be better.



 Date: Wed, 17 Mar 2010 17:23:45 -0700
 From: andrewrwsha...@yahoo.com
 Subject: Re: Can a collection property have its changes saved back to the 
 ActionForm?
 To: user@struts.apache.org

 For the archives, the solution I'm going with is to have the javascript add 
 elements to the document corresponding to the new values in the select. The 
 names of the hidden elements will be indexed. Something like this:

 Action Form:

 public List getOldList()

 public String getSelectedValue()

 public void setNewList(int index, String value)

 JSP:

 
 
 

 





 Then the setNewList method gets called on the form with the new values from 
 the select box.

 If anyone has any better ideas I'm open to hearing them, but this seems to do 
 the trick.

 Andrew



 - Original Message 
 From: Andrew Sharpe 
 To: user@struts.apache.org
 Sent: Mon, March 15, 2010 6:03:30 PM
 Subject: Can a collection property have its changes saved back to the 
 ActionForm?

 Hello all,

 I have a List collection that I am displaying in an
 and it is working great. The problem is that my
 jsp page makes changes to that control via
 javascript (adds new options, removes, etc). I would like these
 changes to be saved back to the ActionForm, preferrably to the same
 collection where it got its data from.

 Struts does not seem to do it by default, that is, the
 tag seems to make use of the ActionForm's get
 property, but not its set. If it is supposed to behave this way please
 let me know and I will reexamine my syntax. Otherwise can someone tell
 me the easiest way to do this? I am using Struts 1.3.8 and
 unfortunately cannot upgrade to Struts 2.

 Many thanks in advance,

 Andrew



 __
 The new Internet Explorer® 8 - Faster, safer, easier. Optimized for Yahoo! 
 Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/

 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org


 __
 Looking for the perfect gift? Give the gift of Flickr!

 http://www.flickr.com/gift/

 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
   
_
Got a cool Hotmail story? Tell us now
http://clk.atdmt.com/UKM/go/195013117/direct/01

Re: Can a collection property have its changes saved back to the ActionForm?

2010-03-22 Thread Andrew Sharpe
Apologies all, I am editing my solution below for clarity and accuracy:



- Original Message 
From: Andrew Sharpe andrewrwsha...@yahoo.com
To: Struts Users Mailing List user@struts.apache.org
Sent: Mon, March 22, 2010 8:44:42 AM
Subject: Re: Can a collection property have its changes saved back to the 
ActionForm?

Thanks Adam.  I ended up using your solution.  I'm not thrilled about the user 
seeing the listbox items get auto selected after they submit the form, but the 
code is certainly cleaner than adding and removing hidden controls.  For the 
archives, here's what I went with:

JSP

function setStatus() {
var emailSelect = document.getElementById(emailSelect);
emailSelect.multiple = true;
emailSelect.focus(); // This is needed to force IE to execute the line 
above.
for (var i = 0; i  emailSelect.length; i++) {
emailSelect.options[i].selected = true;
}
}

html:select name=formName property=addresses size=4 
styleId=emailSelect
html:options name=preferencesForm property=oldAddresses/
/html:select

html:submit onclick=setStatus()/

ACTIONFORM

private String[] addresses;

public String[] getAddresses() {
return addresses;
}

public void setAddresses(String[] value) {
addresses = value;
}

private final ListString oldAddresses = new ArrayListString();

public ListString getOldAddresses() {
return oldAddresses;
}

Thanks again,

Andrew



- Original Message 
From: adam pinder apin...@hotmail.co.uk
To: user@struts.apache.org
Sent: Thu, March 18, 2010 6:11:27 AM
Subject: RE: Can a collection property have its changes saved back to the 
ActionForm?



you want to save the options in the select not a selected option...

if you make the select a multiple select and in javascript you select all 
options are all the option values sent to the server against the same 
parameter name (turn on parameter interceptor logging to check)... 

if so, add a set method in your action with the same name as the select element 
that accepts a string array, like

setNewRole(String[] newRoles)

inside this method you can initialise your proper ArrayList and add the 
elements from the string array into it.

you still need the javascript to select options but at least you're not 
creating new elements.

i haven't checked if multiple selects sends its parameters in this way but it 
works when multiple checkbox elements all have the same name and are sent as 
name/values pair.

ps. if i've misunderstood and you just want to save multiple selected options, 
then you can omit the javascript part which would be better.



 Date: Wed, 17 Mar 2010 17:23:45 -0700
 From: andrewrwsha...@yahoo.com
 Subject: Re: Can a collection property have its changes saved back to the 
 ActionForm?
 To: user@struts.apache.org

 For the archives, the solution I'm going with is to have the javascript add 
 elements to the document corresponding to the new values in the select. The 
 names of the hidden elements will be indexed. Something like this:

 Action Form:

 public List getOldList()

 public String getSelectedValue()

 public void setNewList(int index, String value)

 JSP:

 
 
 

 





 Then the setNewList method gets called on the form with the new values from 
 the select box.

 If anyone has any better ideas I'm open to hearing them, but this seems to do 
 the trick.

 Andrew



 - Original Message 
 From: Andrew Sharpe 
 To: user@struts.apache.org
 Sent: Mon, March 15, 2010 6:03:30 PM
 Subject: Can a collection property have its changes saved back to the 
 ActionForm?

 Hello all,

 I have a List collection that I am displaying in an
 and it is working great. The problem is that my
 jsp page makes changes to that control via
 javascript (adds new options, removes, etc). I would like these
 changes to be saved back to the ActionForm, preferrably to the same
 collection where it got its data from.

 Struts does not seem to do it by default, that is, the
 tag seems to make use of the ActionForm's get
 property, but not its set. If it is supposed to behave this way please
 let me know and I will reexamine my syntax. Otherwise can someone tell
 me the easiest way to do this? I am using Struts 1.3.8 and
 unfortunately cannot upgrade to Struts 2.

 Many thanks in advance,

 Andrew



 __
 The new Internet Explorer® 8 - Faster, safer, easier. Optimized for Yahoo! 
 Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/

 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org


 __
 Looking for the perfect gift? Give the gift of Flickr!

 http://www.flickr.com/gift

Re: Cannot find bean: sendJsp in any scope

2010-03-17 Thread Andrew Sharpe
Along with the change I suggested, you also need to add a public getName() 
method to your Book object.  Try that, and also make sure you can get a simple 
String property to display to ensure you have Struts configured properly.

If you still have trouble let me know and I ll come up with a working example 
for you tonight.

On Wed Mar 17th, 2010 6:51 AM ADT tesla wrote:


thanks for reply but it still doesn't work.I am looking the tutorials on the
google and it  must be like this but its not working .I cant understand why
it is?if you have an example with arrays and logic iterate i will be
thankful if you share it with me

Andrew Sharpe-2 wrote:
 
 I think you want:
 
 logic:iterate id=book name=BookForm property=bookList
  bean:write name=book property=name/
 /logic:iterate
 
 See the docs on logic:iterate for more info:
 http://struts.apache.org/1.0.2/struts-logic.html#iterate
 
 If this still doesn't work I would recommend trying to first output a
 String property to verify you have everything setup properly.
 
 
 
 - Original Message 
 From: tesla fatihdu...@hotmail.com
 To: user@struts.apache.org
 Sent: Tue, March 16, 2010 10:24:13 AM
 Subject: Re: Cannot find bean: sendJsp in any scope
 
 
 When i add logic present tag to data.jsp i am not getting an error but my
 page is still empty i think my arraylist is null but why? i'm waiting your
 advices
 
 tesla wrote:
 
 Hi
 I wanna show my arrayList on the screen by using logic:iterate tag but
 when i run my application i am gettig this error.I'm working on this
 application for two days and still i cant see my arraylist elements on
 the
 browser.
 Thanks in advice.
 
  data.jsp
 
 logic:iterate id=book name=sendJsp   property=bookList
 bean:write name=book property=name/
   /logic:iterate
 
 Book.java
 
 public class Book {

 private String name;
 private String description;
 private int price;
 private int id;
 
 public Book()
{

}
 public Book(String name)
 {
 this.name=name;
 }
 
  public ArrayListBook loadData()
  {
  ArrayListBook kitapListesi = new ArrayListBook();
  kitapListesi.add(new Book(calculus1));
   kitapListesi.add(new Book(calculus2));
  return kitapListesi;
  }
 
 BookAction.java
 
   public ActionForward execute(ActionMapping mapping, ActionForm form,
 HttpServletRequest request, HttpServletResponse response)
 throws Exception {
 

 BookForm bookForm = (BookForm) form;
 Book book = new Book();
 bookForm.setBookList(book.loadData());
request.setAttribute(sendJsp, bookForm.getBookList());
 return mapping.findForward(SUCCESS);
 }
 
 BookForm.Java
 
 public class BookForm extends org.apache.struts.action.ActionForm {

  private ArrayListBook bookList = new ArrayListBook();
 
 public BookForm() {
 super();
 // TODO Auto-generated constructor stub
 }
 public ArrayListBook getBookList() {  return bookList; }
   public void setBookList(ArrayListBook bookList) {  this.bookList =
 bookList; }
 
 struts_config.xml
 
 form-bean name=BookForm type=paket.BookForm/form-bean
 
  action input=/data.jsp name=BookForm path=/data scope=request
 type=paket.BookAction 
   /action
  
 
 
 -- 
 View this message in context:
 http://old.nabble.com/Cannot-find-bean%3A-%22sendJsp%22-in-any-scope-tp27915481p27918564.html
 Sent from the Struts - User mailing list archive at Nabble.com.
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 
 
   __
 Connect with friends from any web browser - no download required. Try the
 new Yahoo! Canada Messenger for the Web BETA at
 http://ca.messenger.yahoo.com/webmessengerpromo.php
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 
 
 

-- 
View this message in context: 
http://old.nabble.com/Cannot-find-bean%3A-%22sendJsp%22-in-any-scope-tp27915481p27929687.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org




  __
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Cannot find bean: sendJsp in any scope

2010-03-17 Thread Andrew Sharpe
I found a full example for you here: 
http://www.java2s.com/Code/Java/J2EE/StrutsFrameworkASampleStrutsApplication.htm


You'll notice that the name property of the logic:iterate tag is set to the 
form name as used in struts-config (in your case, BookForm).

Assuming data.jsp forwards to BookAction, you should not need to put the book 
list on the request as you are doing in the execute method of the BookAction.

Again I suggest you try to get a simple String property on the action form to 
display in your browser and then work your way up to the collection.

Good luck!

Andrew


- Original Message 
From: tesla fatihdu...@hotmail.com
To: user@struts.apache.org
Sent: Wed, March 17, 2010 11:10:15 AM
Subject: Re: Cannot find bean: sendJsp in any scope


I already had public getName() method.i wrote all getters and setters to my
application just didn't post them to the forum.i created a new arraylist and
added String property but cant show them always the same error.I'm losing my
mind i have a problem with listing array elements.I really be thankful to
you really send me a working example.i'm waiting for your reply thanks again


Andrew Sharpe-2 wrote:
 
 Along with the change I suggested, you also need to add a public getName()
 method to your Book object.  Try that, and also make sure you can get a
 simple String property to display to ensure you have Struts configured
 properly.
 
 If you still have trouble let me know and I ll come up with a working
 example for you tonight.
 
 On Wed Mar 17th, 2010 6:51 AM ADT tesla wrote:
 

thanks for reply but it still doesn't work.I am looking the tutorials on
the
google and it  must be like this but its not working .I cant understand
why
it is?if you have an example with arrays and logic iterate i will be
thankful if you share it with me

Andrew Sharpe-2 wrote:
 
 I think you want:
 
 logic:iterate id=book name=BookForm property=bookList
  bean:write name=book property=name/
 /logic:iterate
 
 See the docs on logic:iterate for more info:
 http://struts.apache.org/1.0.2/struts-logic.html#iterate
 
 If this still doesn't work I would recommend trying to first output a
 String property to verify you have everything setup properly.
 
 
 
 - Original Message 
 From: tesla fatihdu...@hotmail.com
 To: user@struts.apache.org
 Sent: Tue, March 16, 2010 10:24:13 AM
 Subject: Re: Cannot find bean: sendJsp in any scope
 
 
 When i add logic present tag to data.jsp i am not getting an error but
 my
 page is still empty i think my arraylist is null but why? i'm waiting
 your
 advices
 
 tesla wrote:
 
 Hi
 I wanna show my arrayList on the screen by using logic:iterate tag but
 when i run my application i am gettig this error.I'm working on this
 application for two days and still i cant see my arraylist elements on
 the
 browser.
 Thanks in advice.
 
  data.jsp
 
 logic:iterate id=book name=sendJsp   property=bookList
 bean:write name=book property=name/
   /logic:iterate
 
 Book.java
 
 public class Book {

 private String name;
 private String description;
 private int price;
 private int id;
 
 public Book()
{

}
 public Book(String name)
 {
 this.name=name;
 }
 
  public ArrayListBook loadData()
  {
  ArrayListBook kitapListesi = new ArrayListBook();
  kitapListesi.add(new Book(calculus1));
   kitapListesi.add(new Book(calculus2));
  return kitapListesi;
  }
 
 BookAction.java
 
   public ActionForward execute(ActionMapping mapping, ActionForm form,
 HttpServletRequest request, HttpServletResponse response)
 throws Exception {
 

 BookForm bookForm = (BookForm) form;
 Book book = new Book();
 bookForm.setBookList(book.loadData());
request.setAttribute(sendJsp, bookForm.getBookList());
 return mapping.findForward(SUCCESS);
 }
 
 BookForm.Java
 
 public class BookForm extends org.apache.struts.action.ActionForm {

  private ArrayListBook bookList = new ArrayListBook();
 
 public BookForm() {
 super();
 // TODO Auto-generated constructor stub
 }
 public ArrayListBook getBookList() {  return bookList; }
   public void setBookList(ArrayListBook bookList) {  this.bookList =
 bookList; }
 
 struts_config.xml
 
 form-bean name=BookForm type=paket.BookForm/form-bean
 
  action input=/data.jsp name=BookForm path=/data scope=request
 type=paket.BookAction 
   /action
  
 
 
 -- 
 View this message in context:
 http://old.nabble.com/Cannot-find-bean%3A-%22sendJsp%22-in-any-scope-tp27915481p27918564.html
 Sent from the Struts - User mailing list archive at Nabble.com.
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 
 
   __
 Connect with friends

Re: Can a collection property have its changes saved back to the ActionForm?

2010-03-17 Thread Andrew Sharpe
For the archives, the solution I'm going with is to have the javascript add 
html:hidden elements to the document corresponding to the new values in the 
select.  The names of the hidden elements will be indexed.  Something like this:

Action Form:

public ListString getOldList()

public String getSelectedValue()

public void setNewList(int index, String value)

JSP:

html:select name=formName property=selectedValue styleId=myId
 html:options name=formName property=oldList/
/html:select

html:submit onclick=saveSelect()/

script type=text/javascript
function saveSelect() {
 var selectControl = document.getElementById('myId);
for (var i = 0; i  select.length; i++) {
var hid = document.createElement(input);
hid.type = hidden;
hid.name = newList[ + i + ];
hid.value = selectControl.options[i].value;
document.forms[0].appendChild(hid);
}
}
/script

Then the setNewList method gets called on the form with the new values from the 
select box.

If anyone has any better ideas I'm open to hearing them, but this seems to do 
the trick.

Andrew



- Original Message 
From: Andrew Sharpe andrewrwsha...@yahoo.com
To: user@struts.apache.org
Sent: Mon, March 15, 2010 6:03:30 PM
Subject: Can a collection property have its changes saved back to the 
ActionForm?

Hello all,

I have a ListString collection that I am displaying in an
html:select and it is working great.  The problem is that my
jsp page makes changes to that html:select control via
javascript (adds new options, removes, etc).  I would like these
changes to be saved back to the ActionForm, preferrably to the same
collection where it got its data from.  

Struts does not seem to do it by default, that is, the
html:options tag seems to make use of the ActionForm's get
property, but not its set.  If it is supposed to behave this way please
let me know and I will reexamine my syntax.  Otherwise can someone tell
me the easiest way to do this?  I am using Struts 1.3.8 and
unfortunately cannot upgrade to Struts 2.

Many thanks in advance,

Andrew



  __
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  
Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


  __
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Cannot find bean: sendJsp in any scope

2010-03-16 Thread Andrew Sharpe
I think you want:

logic:iterate id=book name=BookForm property=bookList
 bean:write name=book property=name/
/logic:iterate

See the docs on logic:iterate for more info: 
http://struts.apache.org/1.0.2/struts-logic.html#iterate

If this still doesn't work I would recommend trying to first output a String 
property to verify you have everything setup properly.



- Original Message 
From: tesla fatihdu...@hotmail.com
To: user@struts.apache.org
Sent: Tue, March 16, 2010 10:24:13 AM
Subject: Re: Cannot find bean: sendJsp in any scope


When i add logic present tag to data.jsp i am not getting an error but my
page is still empty i think my arraylist is null but why? i'm waiting your
advices

tesla wrote:
 
 Hi
 I wanna show my arrayList on the screen by using logic:iterate tag but
 when i run my application i am gettig this error.I'm working on this
 application for two days and still i cant see my arraylist elements on the
 browser.
 Thanks in advice.
 
  data.jsp
 
 logic:iterate id=book name=sendJsp   property=bookList
 bean:write name=book property=name/
   /logic:iterate
 
 Book.java
 
 public class Book {

 private String name;
 private String description;
 private int price;
 private int id;
 
 public Book()
{

}
 public Book(String name)
 {
 this.name=name;
 }
 
  public ArrayListBook loadData()
  {
  ArrayListBook kitapListesi = new ArrayListBook();
  kitapListesi.add(new Book(calculus1));
   kitapListesi.add(new Book(calculus2));
  return kitapListesi;
  }
 
 BookAction.java
 
   public ActionForward execute(ActionMapping mapping, ActionForm form,
 HttpServletRequest request, HttpServletResponse response)
 throws Exception {
 

 BookForm bookForm = (BookForm) form;
 Book book = new Book();
 bookForm.setBookList(book.loadData());
request.setAttribute(sendJsp, bookForm.getBookList());
 return mapping.findForward(SUCCESS);
 }
 
 BookForm.Java
 
 public class BookForm extends org.apache.struts.action.ActionForm {

  private ArrayListBook bookList = new ArrayListBook();
 
 public BookForm() {
 super();
 // TODO Auto-generated constructor stub
 }
 public ArrayListBook getBookList() {  return bookList; }
   public void setBookList(ArrayListBook bookList) {  this.bookList =
 bookList; }
 
 struts_config.xml
 
 form-bean name=BookForm type=paket.BookForm/form-bean
 
  action input=/data.jsp name=BookForm path=/data scope=request
 type=paket.BookAction 
   /action
  
 

-- 
View this message in context: 
http://old.nabble.com/Cannot-find-bean%3A-%22sendJsp%22-in-any-scope-tp27915481p27918564.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org


  __
Connect with friends from any web browser - no download required. Try the new 
Yahoo! Canada Messenger for the Web BETA at 
http://ca.messenger.yahoo.com/webmessengerpromo.php

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Can a collection property have its changes saved back to the ActionForm?

2010-03-15 Thread Andrew Sharpe
Hello all,

I have a ListString collection that I am displaying in an
html:select and it is working great.  The problem is that my
jsp page makes changes to that html:select control via
javascript (adds new options, removes, etc).  I would like these
changes to be saved back to the ActionForm, preferrably to the same
collection where it got its data from.  

Struts does not seem to do it by default, that is, the
html:options tag seems to make use of the ActionForm's get
property, but not its set.  If it is supposed to behave this way please
let me know and I will reexamine my syntax.  Otherwise can someone tell
me the easiest way to do this?  I am using Struts 1.3.8 and
unfortunately cannot upgrade to Struts 2.

Many thanks in advance,

Andrew



  __
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  
Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org