这个问题主要针对PrimeFaces开发团队,但也许其他人知道解决方法。我无法在PrimeFaces支持论坛上上传截图,但我可以在这里链接到我的问题。
在PrimeFaces支持论坛中报道: http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&t=14022
我的网络应用中有<p:tree>
设置了selection="single"
模式。当<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中都表现出相同的行为。