找不到jsf 2.0托管bean的属性 [英] jsf 2.0 managed bean's property not found
问题描述
JSF错误:/fstation/search.jspx(24,62) '#{vManager.fStations}' Property 'fStations' not found on type vm.beans.VisitorManagertype
vManager是我管理过的:
vManager is my managed been:
search.jspx
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;
}
}
推荐答案
如果属性名称以两个或多个大写字符开头,则将假定为这种情况.吸气剂getFStations()
表示属性名称为FStations
,因此您应该这样访问它:
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">
8.8推断名称的大写.
...
8.8 Capitalization of inferred names.
...
因此,当我们从现有Java名称的中间提取属性或事件名称时, 通常将第一个字符转换为小写.但是,为了支持偶尔使用所有大写的名称,我们检查名称的前两个字符是否均为大写,是否保留为大写.例如,
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"成为"fooBah"
- "Z"变成"z"
- "URL"成为"URL"
- "FooBah" becomes "fooBah"
- "Z" becomes "z"
- "URL" becomes "URL"
我们提供了一种方法 Introspector.decapitalize
来实现此转换规则.
We provide a method Introspector.decapitalize
which implements this conversion rule.
请注意,属性名称是根据getter方法名称而不是私有字段名称来定义/解析的.
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">
或者也许:
<h:dataTable value="#{visitor.fireStations}" var="fireStation">
这篇关于找不到jsf 2.0托管bean的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!