现在我正在从primefaces 3.5 迁移到 4.0。
我正在使用递归方法创建这棵树并从数据库中检索树。
使用 3.5 时,这按预期工作。但是当迁移到primefaces 4 时,我无法使用 hibernate jpa 进行编辑/合并。错误仅出现在 glassfish 控制台java.lang.NumberFormatException: For input string: "null"。
看看我的实体:
@Entity
@Table(schema = "public", name = "menu")
@XmlRootElement
public class Menu implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(nullable = false)
private Integer menuid;
@Size(max = 100)
@Column(length = 100)
private String menuname;
private Integer parentid;
private Integer level;
private Integer ordering;
@Temporal(TemporalType.DATE)
private Date sessiondate;
@Size(max = 15)
@Column(length = 15)
private String action;
@Size(max = 15)
@Column(length = 15)
private String menutype;
@Column(name = "icon")
private String icon;
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "parentid")
@OrderBy(value = "ordering")
private List<Menu> children = new LinkedList<>();
//appropriate getter setter
}
和我创建递归的方法:
public void generateMenuTree() throws SQLException {
// findUserConfirmationDefault root menu
rootMenu = menuFacadeLocal.findHomeMenu();
//recursively createUserConfirmationDefault tree menu
menuTree = createTree(rootMenu, null);
}
public TreeNode createTree(Menu menu, TreeNode rootNode) throws SQLException {
TreeNode newNode = new DefaultTreeNode(menu, rootNode);
for (Menu subMenu : menu.getChildren()) {
if (("mm").equalsIgnoreCase(subMenu.getMenutype())) {
TreeNode newNode2 = createTree(subMenu, newNode);
}
}
return newNode;
}
我使用以下方法显示树:
<p:tab title="Access Menus">
<p:tree value="#{managePositionBean.menuTree}" var="menutree" selectionMode="checkbox" selection="#{managePositionBean.selectedTreeMenu}" animate="true">
<p:treeNode icon="#{menutree.icon}">
<h:outputText value="#{msgs[menutree.menuname]}"/>
</p:treeNode>
</p:tree>
唯一可能的事情可能null
只是#{menutree.icon}
。
啊,是的,堆栈跟踪:
INFO: java.lang.NumberFormatException: For input string: "null"
java.lang.NumberFormatException: For input string: "null"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.parseInt(Integer.java:527)
at org.primefaces.component.api.UITree.findTreeNode(UITree.java:156)
at org.primefaces.component.api.UITree.setRowKey(UITree.java:87)
at org.primefaces.component.tree.TreeRenderer.decodeSelection(TreeRenderer.java:86)
at org.primefaces.component.tree.TreeRenderer.decode(TreeRenderer.java:56)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787)
at org.primefaces.component.api.UITree.processDecodes(UITree.java:294)
at org.primefaces.component.tree.Tree.processDecodes(Tree.java:370)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at org.primefaces.util.ComponentUtils.processDecodesOfFacetsAndChilds(ComponentUtils.java:414)
at org.primefaces.component.tabview.TabView.processDecodes(TabView.java:325)
at javax.faces.component.UIForm.processDecodes(UIForm.java:225)
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.UIForm.visitTree(UIForm.java:354)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
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 org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57)
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:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:98)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.omnifaces.facesviews.FacesViewsForwardingFilter.doFilter(FacesViewsForwardingFilter.java:121)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.omnifaces.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:115)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.omnifaces.filter.GzipResponseFilter.doFilter(GzipResponseFilter.java:148)
at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at ch.qos.logback.classic.helpers.MDCInsertingServletFilter.doFilter(MDCInsertingServletFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:744)
我什至删除了显示的图标,但仍然无法正常工作..我 的
环境是JEE 7
,,,,,,,。Mojarra 2.1.24
Glassfish 3.1.2.2
Primefaces 3.5
Primefaces Extension 1.0
Omnifaces 1.5
我很困惑,问题是什么,是primefaces或mojarra或其他地方的错误还是只是我?
谢谢。
更新
也许认为我发现了问题,在我检查生成后html
,我在树下firebug
发现了这个。input hidden
它里面的值似乎是被选中的 id 组件。在我勾选并取消勾选某些或树节点后,其中的值填充或消失。
<input type="hidden" id="Position:tView:j_idt110_selection" name="Position:tView:j_idt110_selection" value="null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,0,0_0,0_1,0_2,0_3,0_4,0_5,4,4_0,4_1,4_2,6,6_0,6_0_0,6_0_1,6_0_2,6_0_3,6_0_4,6_1,6_1_0,6_1_0_0,6_1_0_1,6_1_0_2,6_1_0_3,6_1_0_4,6_1_0_5,6_1_0_6,6_1_1,6_1_2,6_1_3,6_1_4,6_1_5,6_1_6,6_1_7,6_1_8,6_1_9,6_1_10,6_1_11,6_1_12,6_1_13,6_1_14,6_1_15,6_1_16,6_1_17,6_2,6_2_0,6_2_0_0,6_2_0_1,6_2_1,6_2_2,6_2_3,6_2_4,6_2_5,6_2_6,6_2_6_0,6_2_6_1,6_2_6_2,6_2_7,6_3,6_3_0,6_3_1,6_3_2,6_4,6_4_0,6_4_1,6_4_2,6_4_3,6_4_3_0,6_4_3_1,6_4_3_2,1,1_0,1_0_0,1_0_1,1_0_2,1_1,1_1_0,1_1_1,1_1_2,1_1_3,2,2_0,2_0_0,2_0_1,2_0_2,2_0_3,2_0_4,2_0_5,2_1,2_1_0,2_1_1,2_1_2,2_1_3,2_1_4,2_1_5,2_1_6,2_1_7,2_2,3,3_0,3_1,3_2,3_3,3_3_0,3_3_1,5,5_0,5_0_0,5_0_1,5_0_2,5_0_3,5_0_4,5_0_5,5_1,5_1_0,5_1_1,5_1_2,5_1_3,5_1_4,5_1_5,5_2,5_2_0,5_2_1,5_2_2,5_2_3,5_2_4,5_3,5_3_0,5_3_1,5_3_2,5_3_3,5_3_4,5_3_5,5_3_6,5_4">
我将展示我的编辑方法:
public void editingPosition(final Position pList) {
position = pList;
List<PrivilageuserDefault> defaults = privilageuserDefaultFacadeLocal.findPrivilageuserDefaultByPositionid(position.getPositionid());
positionPrivilegesMap = privilageuserDefaultFacadeLocal.searchMapPrivilegeUserDefault(position.getPositionid());
if (!defaults.isEmpty()) {
PrivilageuserDefault[] arrayOfPositionPrivileges = defaults.toArray(new PrivilageuserDefault[defaults.size()]);
int i = 0;
// this.selectedTreeMenu = new TreeNode[defaults.size()]; --> commented on 2nd update
for (PrivilageuserDefault pd : arrayOfPositionPrivileges) {
// TreeNode node = new DefaultTreeNode(pd.getMenu(), null); --> commented on 2nd update
// this.selectedTreeMenu[i] = node; --> commented on 2nd update
i++;
}
checkTreeNodes(menuTree);
}
status = 2;
}
如果存在,这将用于勾选树:
private void checkTreeNodes(TreeNode root) {
if (root.getChildCount() > 0) {
for (TreeNode children : root.getChildren()) {
Menu menu = (Menu) children.getData();
if (positionPrivilegesMap.containsKey(menu.getMenuid())) {
children.setSelected(true);
}
// recursive check
checkTreeNodes(children);
}
}
}
我认为,我在 CRUD 概念中做错了关于勾选/取消勾选树,或者我错过了一些步骤。
更新
是的,我是对的,null
来自上述输入的值 hidden 是 selectedTreeMenu 变量是罪魁祸首。在我评论填充 selectedTreeMenu 的行之后(我已经更新了上面片段上的评论行),现在我可以从数据库中检索数据并且树上的选定节点被勾选。但是在我没有勾选/取消勾选选定节点的情况下立即更新选定的树后,它成功更新,但选定的节点没有更新/插入到数据库/删除。所以它是正确的,这还不够
children.setSelected(true);
看来, selectedTree 变量也必须填写,但是如何正确填写呢?:/