gpt4 book ai didi

jsf 2.0 托管 bean 的属性未找到

转载 作者:行者123 更新时间:2023-12-01 19:35:05 25 4
gpt4 key购买 nike

JSF 错误:/fstation/search.jspx(24,62) '#{vManager.fStations}' 在 vm.beans.VisitorManagertype 类型上找不到属性 'fStations'

vManager 是我的托管对象:

<小时/>

搜索.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>
<小时/>

管理代码如下:

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;
}
}

最佳答案

如果属性名称以两个或多个大写字符开头,则将假定它正是这种情况。 getter getFStations() 指示 FStations 的属性名称,因此您应该按如下方式访问它:

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

这在 JavaBeans Specification 第 8.8 章中指定:

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.

请注意,属性名称是根据 getter 方法名称而不是私有(private)字段名称定义/解析的。

<小时/>

与具体问题无关,但我强烈建议不要缩写这样的属性名称。您的代码是这样的,不是 self 记录的。不要偷懒,把字写完整:

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

或者也许:

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

关于jsf 2.0 托管 bean 的属性未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13907783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com