I work with Spring MVC and jstl 2.0
In a form I have two checkboxes. I want to check only one depends on a variable value.
I have a variable tipoUsuarioTrim that can have two values E and P. If the value is E I want to check a checkbox, if the value is P the another one.
I use the ternary operator.
But in the screen I see the two checkboxes checked.
This is my jsp
<form:form
action="${pageContext.request.contextPath}/correos/salvarPaginaCorreos"
name="frm" id="salvar-pagina-correos" modelAttribute="listaEncuestados" method="post">
<c:forEach items="${listaEncuestados.encuestadosErroneos}" var="filaEncuestado" begin="${listaEncuestados.start}"
end="${listaEncuestados.stop}" varStatus="loop">
<c:set var="indice" value="${loop.index}" />
<c:set var="encuestado" value="${listaEncuestados.encuestadosErroneos[loop.index]}" />
<c:set var="tipoUsuario" value="${encuestado.tipoUsuario}" />
<c:set var="tipoUsuarioTrim"
value="${fn:trim(tipoUsuario)}" />
<div style="display: inline-block;margin-left:45px;">
<form:checkbox path="encuestadosErroneos[${loop.index}].tipoUsuario" class="correo" id="correo" name="correo" value="E" onclick="enableDisableCorreo(${loop.index});"
${(tipoUsuarioTrim == 'P' ? "checked='checked'" : ""}
/>
</div>
<div style="display: inline-block;margin-left:50px;">
<form:checkbox path="encuestadosErroneos[${loop.index}].tipoUsuario" class="postal" id="postal" name="postal" value="P" onclick="enableDisablePostal(${loop.index});"
${(tipoUsuarioTrim == 'E' ? "checked='checked'" : ""}
/>
</div>
</c:forEach>
</form:form>
This is a form screen
tipoUsuarioTrim has the value E but the two checkboxes are checked
How can I check only one checkbox depends on a variable value?
Aucun commentaire:
Enregistrer un commentaire