• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to set an object to null?

 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day!

How can I set say a list (html:select) to null?

I have tried:



But this doesn't work.

Thanks!
[ March 12, 2008: Message edited by: Darren Alexandria ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A <select> element (it's probably best not to refer to an HTML element by its Struts tag in an HTML forum) always has a value. If none is explicitly specified in the markup, that value is the first option in its list.

What is it that you are actually trying to accomplish? If you merely don't want the element's value to be submitted as part of the form, set the element to disabled.
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Bear.

Here's what I am trying to do:

I have a 2 lists. The list at the left contains elements that can be
transferred to the list at the right. My problem is this, whenever I
try to transfer all the elements from the left list to the right list,
the left list is not emptied even if I have set it into null.

When I transfer the elements from left list to right list, the property
for the left list is retrieved from the Action Form, this property should
contain null value since I have already transferred all elements to the right
list. But this is not happening, the property still contains the elements that it previously has thus the elements that have been previously transferred remains in the left list.

[ March 12, 2008: Message edited by: Darren Alexandria ]
[ March 12, 2008: Message edited by: Darren Alexandria ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value of the list represents what option is selected -- it has nothing to do with what the lsit contains.

For what you are describing you need to add and remove option elements from the select.
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to set optionsCollection element to null?
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is sounding more like a Struts issue. The only values that will get submitted with the form are the selected items in your list. Is your form configured to use session scope? If that is the case then it sounds like you need to implement the reset method on your form to clear the lists.

- Brent
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brent Sterling:
This is sounding more like a Struts issue.
Only if he wants to handle this on the server. If it's a client-side activity, it's a JavaScript issues.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw a mention of an Action Form and I thought we switched to talking about after the page was submitted, but I think I read that wrong.

If you are trying to remove items from the select element you can call the remove method. I tried setting the options array to null or to a new array but that did not seem to work for me. The following code will clear the list:


- Brent
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So will this.

selectElement.options.length = 0
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your replies.
Have already tried this one but still doesn't work.



My plan now is to put all the elements that will be selected in a
property. Hope this will work.

Thanks again.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you could try posting your code.

- Brent
 
Darren Alexandria
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have tried putting the selected elements on a propery
and it worked!

thanks to all!
Cheers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic