这是(Managed-Bean best practice)的扩展。我写了一个类AppProperties定义在类的各种物品:除Managed Bean最佳实践
public class AppProperties implements Serializable {
private static final long serialVersionUID = 1L;
//contents of AppProperties Object
private String appRepID;
private String helpRepID;
private String ruleRepID;
private String filePath;
private Vector formNames;
//end content
private Session s;
private String serverName;
public String getAppRepID() {
return appRepID;
}
public void setAppRepID(String appRepID) {
this.appRepID = appRepID;
}
//rest if getters and setters
}
在我的豆我有以下几点:
import ca.wfsystems.core.AppProperties;
private final Map<String, AppProperties> internalMap = new HashMap<String, AppProperties>();
public ApplicationMap() {
this.buildMap(internalMap);
}
private void buildMap(Map<String, AppProperties> theMap) {
try{
AppProperties ap = null;
Session s = ExtLibUtil.getCurrentSession();
vwApps = s.getCurrentDatabase().getView("vwWFSApplications");
veCol = vwApps.getAllEntries();
ve = veCol.getFirstEntry();
tVE = null;
while (ve != null){
Vector colVal = ve.getColumnValues();
String tAppRepID = colVal.get(2).toString();
ap.setAppRepID(colVal.get(2).toString());
ap.setHelpRepID(colVal.get(3).toString());
ap.setRuleRepID(colVal.get(4).toString());
theMap.put(colVal.get(0).toString(), ap);
}
}catch(Exception e){
System.out.println(e.toString());
}finally{
Utils.recycleObjects(s,vwApps);
}
}
一切似乎除了在ap.setAppRepID OK(colVal( 2).toString())有一个编译器错误:“空指针访问变量ap只能在此时为空”setAppRepID和setHelpRepID的代码是相同的,并且setHelpRepID或setRuleRepID都没有编译器错误。我不确定问题是否在设置AppProperties ap = null试图创建AppProperties ap =新的AppProperties,但它不喜欢。我觉得我真的很接近做这个工作,但是......
感谢所有在我爬上JAVA斜坡时一直非常耐心的人。
感谢卡梅伦就是这样 - 在需要的空的构造我AppProperties Class,所以我可以创建一个AppProperties的新实例。现在编译正确,现在我可以开始测试它了。再次感谢 –
没问题比尔! –