我想我有一個解決方案...
在您的XHTML頁面添加這樣:
<ice:outputText id="myHiddenCompo" rendered="#{DebugXHTML}" value="#{bean.getFileNameAndPath()}" />
在BackingBean創建這樣一個方法:
public final String getFileNameAndPath(){
FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot root = context.getViewRoot();
UIComponent c = JSFHelper.findComponent(root, "myHiddenCompo");
return c.getValueExpression("value").toString();
}
JSFHelper.java提取物:
public static UIComponent findComponent(final UIComponent c, final String id) {
if (id.equals(c.getId())) {
return c;
}
Iterator<UIComponent> kids = c.getFacetsAndChildren();
while (kids.hasNext()) {
UIComponent found = findComponent(kids.next(), id);
if (found != null) {
return found;
}
}
return null;
}
結果:
/WEB- INF /包括/文件夾/ verticalTabs/folderDisplay.xhtml @ 8,114 值= 「#{#{bean.getFileNameAndPath()}}」
後,您可以使用字符串來獲得您需要的部分。
我找到了一個 '好' 的實現,是因爲上面,我們有多個ID的一個問題(JSF 2查找重複的ID)
就在XHTML中加入這一行:
<ice:outputText rendered="#{DebugXHTML}" value="#{bean.getFileNameAndPath(component)} "/>
組件是表示當前組件的jsf 2的關鍵字。
並修改支持bean代碼:
public final String getFileNameAndPath(UIComponent hiddenCompo) {
String manipString = hiddenCompo.getValueExpression("value").toString();
return manipString.substring(0, manipString.indexOf(".xhtml") + 6);
}
編輯你的問題保持「禮貌」記住,這樣我們就不會從閱讀分心。我們知道你可能會筋疲力盡,但不應該把重點放在我們身上。 – skuntsel 2013-04-26 13:42:53
這不應該是粗魯的,編輯! – Wis 2013-04-26 19:18:48
謝謝。但我明白你一定感受到了什麼!現在你有兩個答案,這取決於你想輸出的內容:查看我是否或請求URL。 – skuntsel 2013-04-26 19:29:32