2

I have a three radio button in my JSP page. I am displaying multi select box based on radio button selected. But while submitting form, i am getting null value from two select box. Other select box is working fine.

Can anyone help me?

<script type="text/javascript">
$(document).ready(function(){
$('.show').hide();
$("input[name$='application']").click(function() {
var test = $(this).val();
$("div.show").hide();
$('#showemma').hide();
$('#showdmfota').hide();
$('#showuep').hide();
$("#show" + test).show();
   });
});
</script>
<title>Add Config Changes</title>
</head>
<body>
<%
    Server env = new Server();
    Map<String, List<String>> map = env.getServer();
    Properties property = new Properties();
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    property.load(classLoader.getResourceAsStream("error.properties"));
%>
<h3> Add Configuration Change</h3> <br><br>
<form action="_config" method="post">
<table align="center" id ="login">
    <tr>
        <td>Application</td>
            <td>
            <div class="radio" style="font-size:12px;">
                <label><input type="radio" name="application" id="fota" value="dmfota"> DMFOTA</label>
                <label><input type="radio" name="application" id="uep" value="uep"> UEP</label>
                <label><input type="radio" name="application" id="emma" value="emma"> EMMA</label>
                </div>
            </td>
        <td id="error"><p id ="applicationError"><%=property.getProperty("applicationError") %></p></td>
    </tr>           

    <% for (String serverNamekey : map.keySet()){%>
    <tr id="show<%= serverNamekey %>" class="show" style='display:none'>

        <td>Server</td>
            <td>
            <% List<String> servers = map.get(serverNamekey); %>
                <select name="server" id="server" multiple="multiple" style="width:150px; height: 150px;">
                    <%for (String serverName : servers){  %>
                        <option value="<%=serverName%>"><%=serverName%></option>
                    <%} %>
                </select> 
            </td> 
            <td id="error"><p id ="serverError"><%=property.getProperty("serverError") %></p></td>
    </tr>
            <%} %>
    <tr>
        <td colspan =2><input type="submit" value="Add Change Log"   id="configSubmit" class="submit"></td>
    </tr>
</table>
</form> 
</body>
</html>

</table>
</form> 
</body>
Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
Kalpesh
  • 35
  • 1
  • 7

1 Answers1

1

As stated in the comments, your name attribute must be unique on all inputs, ortherwise, only one value will be take into account by the server. Moreover, id must also be unique.

I recommand to use the serverNameKey as unique name and id :

<select id="select-<%= serverNamekey %>" name="<%= serverNamekey %>" ...

Note that you need the same name attribute for all input type="radio", so that part is okay.


Not related to the problem, I also recommand to not use scriplets, you should read about JSTL. If it is a new project, I recommand usage of JSF which took over on JSP (that is deprecated).

Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72