• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help on html: options

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
i am absolutely new to the Struts framework...
see, what i want to do is i have two listboxes on my JSP page. you can move objects from the first listbox to the second one. The first listbox has to be populated with options from a database(i need the IDs and need to show the Display name). On click of continue, whatever (the IDs assoiated with the Display names) has been moved to the Second list box has to be stored to my Data bean.
When i visit this page again, the second listbox has to be shown populated with the choices i had made earlier.
Can anyone pleeeeeeeeease guide me??? Any help will be greatly appreciated.
thanx in advance
Meera
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help narrow down the scope of help you need. What, if anything, have you tried so far? Do you have any specific questions regarding the online HTML taglib documentation? Thanks.
 
meera sood
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx for your reply...
well, i have tried out a few things... cant seem to get to populate by form bean with the data in the second list box. how do i do that...see i have made the form bean, registered everything with the struts-config, but my form bean is not getting populated. how do i go about doing that.
thanx again...
Meera
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you are already trying out your own Struts form, I will assume that you have successfully ran the demo application that comes with the Struts download. I will also assume that you have modelled your Struts application after the sample application, perhaps even just adding your own form and action to it.
If you haven't done these yet, please go and try to run the sample application and understand how the different pieces work together: struts-config.xml, web.xml, your ActionForm, and your Action.
If you have already done the above, then here are a few points to consider regarding the options:
  • In order to select multiple items in a listbox, you should include the multiple attribute in the html:select tag. You can assign this attribute any arbitrary value but you would normally use "true" for it to make sense to someone reading the code
  • When multiple values for a property can be submitted, the corresponding property in the ActionForm should be a String array. E.g. if you have


  • // in JSP:
    <html:select property="states" multiple="true">
    <html:options ... />
    </html:select>
    // in ActionForm:
    private String[] states;
    public void setStates(String[] newStates) {
    states = newStates;
    }
    public String[] getStates() {
    return states;
    }
    Make sure your ActionForm follows the above pattern first. It's getting late for me and I have to go but if you still have a problem, then I'll tell you about using the html:options tomorrow.
    [ March 31, 2003: Message edited by: Junilu Lacar ]
     
    meera sood
    Ranch Hand
    Posts: 50
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    i have already run the sample application...was able to make and run a few simple JSP forms also... it is just this listbox where i am facing a problem and it is really bugging me ... have used a String array in the form bean.... its just not getting populated...i mean the setter method is not getting called...
    will wait for your reply...thanx
    Meera
     
    Junilu Lacar
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    All right then, post some of your code. I'd like to see relevant snippets of code from the following:
  • Your ActionForm: showing the field declaration and the getters and setters; the reset() method if you overrode it.
  • Your struts-config.xml: the form-bean definition and the corresponding action definition
  • Your JSP: the html:select and html:options tag


  • Again, please don't post the full code, just the relevant pieces we're interested in. Thanks.
    BTW, have you tried restarting your machine and doing an Irish Jig during the POST? That might help too, you know.
    [ April 01, 2003: Message edited by: Junilu Lacar ]
     
    meera sood
    Ranch Hand
    Posts: 50
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    well..tried the Cha-Cha-Cha... maybe i SHOULDtry the Irish Jig
    anyways....here are my code snippets:

    Struts Config :

    and finally the select/ options tag....that is precisely where i am facing the problem... dont know how to write that...
    rt now what i have written is :

    doesnt look right to me... ...
    Meera
     
    Junilu Lacar
    Sheriff
    Posts: 17644
    300
    Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    OK, read what I wrote in this thread about how to use html ptions.
    You said that the values for selectedParents came from another list box. Are you populating the selectedParents list box using javascript? If so, you are probably expecting everything you moved over to the listbox to be submitted with the form. This is not the case. The only values from any listbox on your form that will be submitted will be those values that have actually been selected. That is, in order for the values that you moved into the selectedParents listbox to be submitted with the request, they have to be selected using a javascript function that is called during the onclick event of the submit button.
    I'm about 95% sure that this is your problem. If I'm right, you can post a question on how to write the JavaScript function to select all items in a listbox in the JavaScript forum.
     
    meera sood
    Ranch Hand
    Posts: 50
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    yes, i think that must be the problem... i'll work on it and if i get any more problems, i know who to contact ....
    thanx again....
    Meera
     
    reply
      Bookmark Topic Watch Topic
    • New Topic