鑑於託管bean(爲myBean),其延伸一個抽象類(AbstractMapModel),其本質上是一個地圖的包裝:表達式語言bean屬性評價順序
的AbstractMapModel類包括的getValue(對象key)方法。
MyBean類包含一個getName()方法。
XPage的值爲#{MyBean.name}。
我發現它調用MyBean.getValue(「Name」)並忽略MyBean.getName()。我的問題是,這是正確的操作?
邏輯上,它似乎應該在嘗試廣義getValue(「Name」)之前嘗試更具體的getName()。做一些研究,看起來如果getValue()返回null,它應該尋找一個特定的getter,即使我發現邏輯可疑,至少會得到正確的最終結果。但是,兩者都沒有發生。
我已經解決了這個問題,下面的代碼:
public Object getValue(final Object key) {
/* Following code added to check for specific getter before performing getValues() */
String propertyName = key.toString();
propertyName = propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
Method method = null;
try {
method = this.getClass().getMethod("get" + propertyName, new Class[] {});
if (method != null) {
return method.invoke(this);
}
} catch (Exception e) {
// Do nothing
}
try {
method = this.getClass().getMethod("is" + propertyName, new Class[] {});
if (method != null) {
return method.invoke(this);
}
} catch (Exception e) {
}
/* --------------------------------------------- */
return getValues().get(key);
}
它似乎並不喜歡這個解決辦法應該是必要的,所以我不知道如果我有什麼事情的一些基本誤解。或者,我應該做些什麼更好的方法?
我很久沒見過它了,但Tim Tripcony爲NotesIn9做了一個關於這個的視頻,並且如果我沒有記錯的話就會談到這個確切的問題。基本上Tim提出的是最好的解決方案。 –
我正在做的是來自Tim的工作。我有一段時間沒有回顧過NI9,我想我只記得這是如何工作的。謝謝! –