Web tier: servlets, JSP, Web frameworks: dynamic drop down with Struts

  1. dynamic drop down with Struts (3 messages)

    Hi, I'm having a problem with some basic struts. I'm trying populate a html drop down menu with where the collection, types, is added to the request object via an Action, which then forwards onto the jsp including the above tags. The collection is generated from a method in a model, which requires a parameter held in the session variable. My problem is that I can't figure out how to populate the drop down, such that when the form is submitted and an error is return from the ActionFrom validate method, the form in the jsp keeps it values and the selection from the drop down is kept. I have tried a couple of things. 1. to use an action that populates the request object with the collection, but when the form is submitted and an error is return the collection no longer exist in the request. 2. to add a method to my ActionForm such that it returns the collection, however, I rely on a session veriable to create collection, I can't seem to get at the from a method within the ActionForm object. Is there an easy solution that I'm complety overlooking? Thanks Thomas O.
  2. I think you would better keep your types collection in your ActionForm and use instead of . In Action's execute method (or whatever name is used for the method which renders the page) just populate your ActionForm's types field with proper collection.
  3. i disagree with adding the collection to the Form, which is suppose to be the "Model" with only setters/getters and a validate method, that validates syntax only!
  4. I am under impression that forms are claimed to perform a function of transfer objects between model and view as well. let me check some struts docs...
    Note: While ActionForm beans often have properties that correspond to properties in your Model beans, the form beans themselves should be considered a Controller component. As such, they are able to transfer data between the Model and View layers.