gpt4 book ai didi

编辑 Primefaces 递归树时出现 java.lang.NumberFormatException

转载 作者:行者123 更新时间:2023-12-01 04:10:59 24 4
gpt4 key购买 nike

现在我正在从 迁移3.5 至 4.0。
我正在使用递归方法创建这棵树并从数据库中检索该树。
使用 3.5 时,这按预期工作。但是当迁移到时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 7Mojarra 2.1.24Glassfish 3.1.2.2Primefaces 3.5 Primefaces 扩展 1.0Omnifaces 1.5

我很困惑,问题是什么,是primefaces、mojarra还是其他地方的bug,还是只有我一个人?
谢谢。

更新

也许我认为我发现了问题,在我用 firebug 检查生成的 html 后,我发现这个输入隐藏就在树下。看来里面的值是被选择的 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 值是 selectedTreeMenu 变量是罪魁祸首。在我注释填充 selectedTreeMenu 的行之后(我已经更新了上面片段上的注释行),现在我可以从数据库中检索数据并且树上选定的节点已被勾选。但是,在我立即更新所选树而不勾选/取消勾选所选节点后,它成功更新,但所选节点未更新/插入到数据库/删除。所以这是对的,这还不够

children.setSelected(true);

看来selectedTree变量也必须填写,但是如何正确填写呢? :/

最佳答案

最后,我找到了一些解决方法,快速补丁。我创建了新的 List 变量

private List<TreeNode> selectedTreeList;

并用节点填充它

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);
expand(children);
selectedTreeList.add(children); // --> filled with this
}

// recursive check
checkTreeNodes(children);
}
}
}

在显示给 UI 之前,我将节点的 List 更改为 Array

selectedTreeMenu = selectedTreeList.toArray(selectedTreeMenu);

瞧!

关于编辑 Primefaces 递归树时出现 java.lang.NumberFormatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19926218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com