mardi 15 octobre 2019

Multiple checkboxes in different rows with struts

I'm using struts2 to develop some web application and, at some point, I need to get some data from the user: preselect options (with combobox) and some checkboxes.

Both the options (combobox) and the checkboxes are fulfilled with values from MySQL (and working fine)... but when showing the checkboxes I want to show each checkbox in a different line (or row) and this is only happening if I use s:checkbox and s:iterator ... but after that I'm not able to retrieve the values. However, if I use s:checkboxlist (without s:iterator) all the checkboxes are in the same line and I'm able to retrieve the values in the landing page.

This is my action class where I get the values from DB to show checkboxes:

private List<String> listaAsignaturasHabilitadas = new ArrayList();
private List<String> listaAsignaturasHabilitadasSeleccionadas = new ArrayList();

//getters & setters

This is showing the checkboxes one per line (but I cannot retrieve it in the landing page):

<s:iterator value="listaHabilitaciones" var="habilitacion" status="rowstatus">
<label><input type="checkbox" name="habilitacionSeleccionada" value="${habilitacion}" 
    id="habilitacionesSeleccionadas[${rowstatus.index}]"/>
<s:property value="habilitacion"/>
</label>
<br>
</s:iterator>

This is showing the checkboxes in the same line (but I'm able to retrieve it in the landing page):

<br><s:checkboxlist label="Escoge" list="listaHabilitaciones" name="habilitacionesSeleccionadas" /><br>

This is the landing page:

Habilitaciones seleccionadas <s:property value="habilitacionesSeleccionadas"/><br><br>

I want to have the checkboxes in different lines and be able to get those check/unchecked values in the landing page.

Thanks in advance!!




Aucun commentaire:

Enregistrer un commentaire