java inheritance and JSTL
I want to acces to an attribute inherited by one of my java classes, in a jsp using jstl 1.2 :
Java :
public class LigneDeclarationBean {
private ELigneDeclaration ligneDecla;
private ETypeFormulaire typeForm;
...
public ELigneDeclaration getLigneDecla() {
return ligneDecla;
}
public class ELigneDeclaration extends ZELigneDeclaration implements Serializable {
...
}
public class ZELigneDeclaration implements Serializable {
private String sLibelle;
...
public String getSLibelle() {
return sLibelle;
}
}
JSP :
<%
List<LigneDeclarationBean> listelignes = (List) request.getAttribute("listeLignes");
// Affichage de la liste des ligneDeclas
for (int i = 0; i < listelignes.size(); i++) {
LigneDeclarationBean ligneDecla = listelignes.get(i);
%>
${ligneDecla.ligneDecla.sLibelle}
The error message :
message: The class 'package.ELigneDeclaratio开发者_如何学Gon ' does not have the property 'sLibelle'.
However in scriptlet it works fine
<%=ligneDecla.getLigneDecla().getSLibelle()%>
return the right value. Is this a limitation of the jstl?
Is there another way to acces to my attribute using this taglib? This project do not use a presentation framework and jstl seems to be the only taglibs I could use.
That might be because of the single letter in the beginning. Try referring to it as ${A.SLibelle}
. (i.e. both letters in upper-case).
That's a bit of a special case with EL, because your getter is getSLibelle()
, and the parser seems to be unable to understand whether the field is lower or upper-case.
Your problem is found in your getter method:
The correct way to creating a getter method for sLibelle
is:
/**
* @return the sLibelle
*/
public String getsLibelle() {
return sLibelle;
}
(yours have a capital S
on your getter method declaration name). You can use Bozho's solution or fix the naming of your getter method.
精彩评论