Struts checkbox with ActionForm in request scope

Discussion in 'Java' started by sameergn@gmail.com, Jan 12, 2007.

  1. Guest

    Hi,

    I am trying to render check boxes using an indexed property say
    selectedRole[0..n]. Since the Form is request scope, how one should
    code the setter method setSelectedRole(int idx), when the form is
    submitted. The number of submitted checkboxes are not known and
    setSelectedRole(n) can be called in any order.

    Is there any better option than keeping the ActionForm in session? With
    session scope also, we will end up in same scenario when session
    timeout occurs before user submits the page.

    We can count #of request parameters starting with "selectedRole[" in
    reset() method and then allocate the array, but this looks ugly.

    Thanks,
    Sameer
     
    , Jan 12, 2007
    #1
    1. Advertising

  2. wrote:
    > Hi,
    >
    > I am trying to render check boxes using an indexed property say
    > selectedRole[0..n]. Since the Form is request scope, how one should
    > code the setter method setSelectedRole(int idx), when the form is
    > submitted. The number of submitted checkboxes are not known and
    > setSelectedRole(n) can be called in any order.
    >
    > Is there any better option than keeping the ActionForm in session? With
    > session scope also, we will end up in same scenario when session
    > timeout occurs before user submits the page.
    >
    > We can count #of request parameters starting with "selectedRole[" in
    > reset() method and then allocate the array, but this looks ugly.
    >
    > Thanks,
    > Sameer



    One option is to not use an action form for this, and have the action
    (the one to which this form is submitted) do a request.getParameter( ).
    Note that this will not work if it is a multipart request. You can name
    the checkboxes consistently (like cb0 through cb10) and then in a for
    loop, check for "presence" of this parameter. If the checkbox is
    checked, it'd be present in the request. This way you can know which
    ones were checked, and which ones were unchecked (by looking into the
    previous state, maybe in the database).

    I hope I understood your question correctly, and this helps.

    -cheers,
    Manish
     
    Manish Pandit, Jan 12, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tom
    Replies:
    2
    Views:
    978
    code learner
    Dec 24, 2010
  2. Rode
    Replies:
    0
    Views:
    871
  3. Pratap Das
    Replies:
    2
    Views:
    2,075
    Pratap Das
    Apr 5, 2004
  4. runescience
    Replies:
    0
    Views:
    4,312
    runescience
    Feb 23, 2006
  5. michel777
    Replies:
    0
    Views:
    2,150
    michel777
    Nov 14, 2006
Loading...

Share This Page