views:

31

answers:

2

It may seem strange, but I need to get values of non-selected radio buttons for each radio button's group. I have used the code below to get all the selected buttons values, but I need to get the unselected ones.

        ArrayList <String> userSelection = new ArrayList <String>();
        Enumeration names = request.getParameterNames();
        String selection = "";
        while ( names.hasMoreElements() )
        {
           name = (String) names.nextElement();
           userSelection.add(request.getParameter( selection ));
        } 
+1  A: 

You simply can't get those values form your request.

It's the browser which will create the request and it doesn't send informations that appears useless for the navigation (such as unused values).

The only way to do that would be to guess the values.

Remember this request could be forged by hand so, never trust user input.

Colin Hebert
+3  A: 

The browser will not send you the non-selected buttons. What you'll need to do is either:

  1. Have your code know what all the buttons will be
  2. Create a hidden field with a list of all the possible values.

If you go with #2, take heed of Mr HEBERT'S suggestion to never trust user input.

Dave