Bookmark Topic Watch 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • paul wheaton
  • Paul Clapham
Saloon Keepers:
  • Piet Souris
Bartenders:
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Question:

Here is a code fragment from a JSP page:



foodTypeList is a collection that has these elements:-

  • 01 Entree
  • 02 Snack
  • 03 Dessert


  • How do I set Snack as the default?

    Answer:

    The html:select tag will show the option as "selected" that matches the current value of the ActionForm bean property that is specified in the "property" attribute of the tag.

    So, if you want to set a default value, you have to set the ActionForm bean property. In your example, let's suppose that that myActionForm is a local variable that refers to your ActionForm bean, the following statement would do the job:

    myActionForm.setFoodType("02");

    Here are your options:


  • If a particular value is always supposed to be the default value, you can set this value in the reset() method of the ActionForm bean.
  • You can set it in an Action class that forwards to the JSP
  • You can set it in the JSP itself with a c:set tag.

  • Example:




    Return to StrutsFaq
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
      Bookmark Topic Watch Topic
    • New Topic