I'm trying to get some specialities
from a function called getAllSpecialities()
(which's inside of MedicBean
) and store them in a JSTL/EL var called specialitiesList
. This function returns an ArrayList
of Strings
and it works fine, it returns all the specialities, the problem comes in the jsp. I don't know why, the var specialitiesList
is not being filled, it's just null
, so I can't iterate over it to populate the select
.
This is what I've been trying to do:
<select>
<option value="" disabled selected>Select an speciality</option>
<jsp:useBean id="medicAux" class="Model.MedicBean"/>
<c:set var="specialitiesList" value="${medicAux.allSpecialities}"/>
<c:forEach items="${specialitiesList}" var="speciality">
<option value="${speciality}">${speciality}</option>
</c:forEach>
</select>
This is the getAllSpecialities()
method:
public ArrayList<String> getAllSpecialities(){
ResultSet rs = null;
Connection conn = null;
PreparedStatement ps = null;
ArrayList<String> specialities = new ArrayList<>();
try {
conn = Conexion.conectar();
String query = "SELECT DISTINCT SPECIALITY FROM MEDICO";
ps = conn.prepareStatement(query); // create a statement
rs = ps.executeQuery();
while (rs.next()) {
specialities.add(rs.getString("speciality"));
}
} catch (SQLException ex) {
Logger.getLogger(MedicoBean.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("error: "+ex.getMessage());
}
Conexion.desconectar(conn);
return specialities;
}`
What am I doing wrong? If you need some extra info, just ask for it. Thanks!