這個問題主要針對PrimeFaces開發團隊,但也許別人知道一個解決方法。我無法在PrimeFaces支持論壇上傳截圖,但我可以在這裏鏈接到我的問題。PrimeFaces 3.0 - 異常<p:tree>節點選擇當樹在一個<p:dialog>
在PrimeFaces報道支持論壇:http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&t=14022
我在web應用程序有selection="single"
模式設置有<p:tree>
。節點選擇正常工作時,<p:tree>
不是<p:dialog>
裏面如下所示:
然而,當<p:tree>
是一個對話框,裏面有一個異常在服務器端每一個節點被點擊時引發瀏覽器。選擇是從來沒有登記在支持bean:
以下堆棧跟蹤出現在我的服務器日誌一次樹節點由用戶點擊了瀏覽器的時間爲:
27-Jul-2011 3:21:52 PM com.sun.faces.context.PartialViewContextImpl processPartial
INFO: java.lang.NullPointerException
java.lang.NullPointerException
at org.primefaces.component.tree.TreeRenderer.decode(TreeRenderer.java:53)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1181)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:506)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1589)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIForm.visitTree(UIForm.java:344)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1600)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
下面是有問題的PrimeFaces方法:
@Override
public void decode(FacesContext context, UIComponent component) {
Tree tree = (Tree) component;
Map<String,String> params = context.getExternalContext().getRequestParameterMap();
String clientId = tree.getClientId(context);
TreeModel model = new TreeModel((TreeNode) tree.getValue());
if(tree.getSelectionMode() != null) {
String selection = params.get(clientId + "_selection");
String instantUnselection = params.get(clientId + "_instantUnselection");
boolean isSingle = tree.getSelectionMode().equalsIgnoreCase("single");
if(selection.equals("")) {
if(isSingle)
tree.setSelection(null);
else
tree.setSelection(new TreeNode[0]);
}
else {
String[] selectedRowKeys = selection.split(",");
if(isSingle) {
TreeNode selectedNode = treeExplorer.findTreeNode(selectedRowKeys[0], model);
tree.setSelection(selectedNode);
}
else {
TreeNode[] selectedNodes = new TreeNode[selectedRowKeys.length];
for(int i = 0 ; i < selectedRowKeys.length; i++) {
selectedNodes[i] = treeExplorer.findTreeNode(selectedRowKeys[i], model);
model.setRowIndex(-1); //reset
}
tree.setSelection(selectedNodes);
}
}
}
decodeBehaviors(context, component);
}
導致異常的行這一個:
if(selection.equals("")) {
在其中<p:tree>
位於<p:dialog>
的selection
值總是null
內部的情況。
任何想法如何解決這個問題?
我正在使用今天的PF 3.0-M3-SNAPSHOT的夜間版本。 PF 3.0-M2也會發生同樣的情況。在IE 7和Firefox 4.0.1中表現出相同的行爲。
我有同樣的確切問題。看來我們在同一天都有同樣的問題;)http://stackoverflow.com/questions/6824705/jsf-2-0-update-a-primefaces-dialog-not-working-the-first-time – Sydney
哈哈,真好!我今天浪費了很多時間試圖弄清楚爲什麼我的怪異樹選擇不起作用。我將一個簡化的例子放入一個測試應用程序中,並立即開始工作。我最終發現對話是唯一真正的區別,我並不太高興。我想我必須重新設計我的頁面才能在沒有對話框的情況下工作,直到PrimeFaces 3.0更加穩定。這是一種恥辱,因爲他們在正確工作時看起來非常好。 –
我對你很感興趣,但我幾乎已經放下自己去相信任何在''之內的東西都是一團糟。我總是會遇到問題,並在我遇到問題之前就開始思考JavaScript解決方法。 –