這是(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的新實例。現在編譯正確,現在我可以開始測試它了。再次感謝 –
沒問題比爾! –