This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Struts and the fly likes logic:iterate and onChange Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:iterate and onChange" Watch "logic:iterate and onChange" New topic
Author

logic:iterate and onChange

milo lak
Greenhorn

Joined: May 28, 2006
Posts: 4
hi all,

i have a problem here,

i`m using logic:iterate to display a list-which new row/element can be added to the list.
i have two listbox for each row.the second listbox will be populated with element based on selection made to the first listbox(onChange). the problem is when i have more than one row/element in the list.if i make selection at the first listbox,the second listbox for all row will change.I just want to make only the row i choose to change.How am i going to do that? Help please...
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In order to do this, you will have to use JavaScript to populate the 2nd listBox. One way to do this would be to populate JavaScript arrays containing all possible values for the 2nd list, and when a selection is made for the first list, replace the 2nd list with the appropriate array of values.

Another option would be to use AJAX to make a call to the server to populate the 2nd listbox once the first has been selected.


Merrill
Consultant, Sima Solutions
milo lak
Greenhorn

Joined: May 28, 2006
Posts: 4
thanks,
already using Javascript to populate the second listbox.
the problem still persist.
when any of the first listbox value changed,all value in the second listbox change.

i haven't tried AJAX before,but from what i heard about it-it lets you change your content without reloading everything.might do the trick.i`ll check on it later.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
When I say to use JavaScript to change the 2nd ListBox, I'm talking about using the Document Object Model (DOM) to change the contents of the box without submitting the form. Is that what you're doing? It's certainly possible to to that for a single listBox without changing the others, even without using AJAX.

The decision as to whether to use AJAX or not is largely dependent on how many possibilities there are: How many items in each possible list? How many possible lists are there? If the answer is a lot, then you'd want to use AJAX. If the answer is not so many, you can do it just by creating JavaScript variables for all possible combinations and using JavaScript to change what's in the 2nd listBox depending on what's entered in the first.
milo lak
Greenhorn

Joined: May 28, 2006
Posts: 4
hi again,

what i`m doing right now is,onChange the javascript will call a lookupdispatchaction to populate the second listbox. it works for the first row in the list.
but when i added a new row, everytime a value were selected from the first listbox ,the second listbox value for both rows changes.
That`s pretty much what i`m doing right now, Using Struts,Jboss and Netbeans,and Oracle10g db.

no,am not using DOM.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Trying to accomplish this with server-side code as you're doing is going to be difficult. As I said before, I believe using JavaScript is the best approach.

Also, just so you're aware, the term usually used for this type of thing is "dependent dropdowns" or "dependent selects". You will find more information on the subject in this thread.
milo lak
Greenhorn

Joined: May 28, 2006
Posts: 4
thanks,

i`ll have a look at the link you gave afterwards.
will be trying Javascript to solve my problem here,as you said it`s difficult the way i do it right now.

again,thanks a bunch. ;P
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: logic:iterate and onChange