Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsf 2.0 managed bean's property not found

Tags:

jsf

jsf-2

JSF error: /fstation/search.jspx(24,62) '#{vManager.fStations}' Property 'fStations' not found on type vm.beans.VisitorManagertype

vManager is my managed been:


search.jspx

<h:form>
     <h:dataTable value="#{vManager.fStations}" var="row">
          <h:column>
              <f:facet name="header"><h:outputText value="ID"/></f:facet>
              <h:outputText value="#{row.id}"/>
          </h:column>
          <h:column>
               <f:facet name="header"><h:outputText value="NAME"/></f:facet>
              <h:outputText value="#{row.name}"/>
          </h:column>
     </h:dataTable>
</h:form>

managed been code like this:

package vm.beans;
import vm.model.DataManager;
import java.util.ArrayList;
import java.util.List;

public class VisitorManager {

    private List<FireStation> fStations;
    private DataManager dataManager = new DataManager();
    private String fireStationName;

    public String searchFireStation(){
        //String fName =fStation.getName();
        System.out.println("this is "+fireStationName);
        return null;
    }

    public void deleteStation(){    
    }

    /*
    * getter and setter
    */

    public String getFireStationName(){
        return fireStationName;
    }

    public void setFireStationName(String name1){
        this.fireStationName=name1;
    }

    public List<FireStation> getFStations(){
        //return dataManager.getFireStations();
        fStations = new ArrayList<FireStation>();
        fStations.add(new FireStation("001", "a1"));
        fStations.add(new FireStation("002", "a2"));
        fStations.add(new FireStation("003", "a3"));
        return fStations;
    }

    public void setFStations(List<FireStation> fs){
        this.fStations = fs;
    }
}
like image 570
user1825831 Avatar asked Dec 17 '12 03:12

user1825831


1 Answers

If a property name starts with two or more uppercased characters, then it will be assumed to be in exactly that case. The getter getFStations() indicates a property name of FStations, so you should then access it as such:

<h:dataTable value="#{vManager.FStations}" var="row">

This is specified in chapter 8.8 of the JavaBeans Specification:

8.8 Capitalization of inferred names.

...

Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone. So for example,

  • “FooBah” becomes “fooBah”
  • “Z” becomes “z”
  • “URL” becomes “URL”

We provide a method Introspector.decapitalize which implements this conversion rule.

Note that the property name is definied/resolved based on getter method name, not on private field name.


Unrelated to the concrete problem, I however strongly recommend to not abbreviate property names like that. Your code is this way not self-documenting. Don't be lazy and write words full out:

<h:dataTable value="#{visitorManager.fireStations}" var="fireStation">

or maybe:

<h:dataTable value="#{visitor.fireStations}" var="fireStation">
like image 198
BalusC Avatar answered Sep 26 '22 15:09

BalusC