tags:

views:

51

answers:

2

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.ELigneDeclaration ' 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.

+1  A: 

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.

Bozho
to be exact there is 2 syntax : one for inherited attribute, one for direct attribute so the solution here is : ${ligneDecla.ligneDecla.SLibelle}
jayjaypg22
A: 

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.

The Elite Gentleman