File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes how to set an object to null? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to set an object to null?" Watch "how to set an object to null?" New topic
Author

how to set an object to null?

Darren Alexandria
Ranch Hand

Joined: Aug 17, 2007
Posts: 185
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

Joined: Jan 10, 2002
Posts: 61092
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Darren Alexandria
Ranch Hand

Joined: Aug 17, 2007
Posts: 185
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

Joined: Jan 10, 2002
Posts: 61092
    
  66

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

Joined: Aug 17, 2007
Posts: 185
Is there a way to set optionsCollection element to null?
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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

Joined: Jan 10, 2002
Posts: 61092
    
  66

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

Joined: Feb 08, 2006
Posts: 948
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

So will this.

selectElement.options.length = 0


GenRocket - Experts at Building Test Data
Darren Alexandria
Ranch Hand

Joined: Aug 17, 2007
Posts: 185
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

Joined: Feb 08, 2006
Posts: 948
Maybe you could try posting your code.

- Brent
Darren Alexandria
Ranch Hand

Joined: Aug 17, 2007
Posts: 185
Have tried putting the selected elements on a propery
and it worked!

thanks to all!
Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to set an object to null?