- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
现在我正在从 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 扩展 1.0
、Omnifaces 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/
在 Tomcat 6/Ubuntu 12.04 上启动 Grails 2.1.0 应用程序时出现以下错误。 Error 500 - Internal Server Error. groovy.lang
在运行 Storm 拓扑时,我收到此错误。拓扑完美运行 5 分钟,没有任何错误,然后失败。我正在使用 Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS as 300 sec i
我有一个 jsp 代码在其中一台机器上运行良好。但是当我复制到另一台机器时,我得到了这个 no such method found 异常。我是 Spring 的新手。有人可以解释我错过了什么吗? 以下
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我的代码在下面给出了一个错误; Exception in thread "main" java.lang.NoSuchMethodError: com/myApp/Client.cypherCBC(L
我正在尝试一个 Restful web 服务示例,所以当我要访问 url 时,我遇到了异常 java.lang.NoSuchMethodError: jersey.repackaged.com.goo
我正在将一个 Spring web 项目转换为一个 Maven 项目,但我收到了这个错误: java.lang.NoSuchMethodError: org.jboss.logging.Logger.
在我的项目中,我有一个像这样的枚举: public enum MyEnum { FIRST(1), SECOND(2); private int value; private MyEnum(int v
我创建了这个简单的示例,用于读取 Linux 正常运行时间: public String getMachineUptime() throws IOException { String[] di
我正在使用 Eclipse,并且正在使用 Java。我的目标是使用 bogoSort 方法对 vector 进行排序在一个 vector (vectorExample)中适应我的 vector 类型,
我正在运行以下查询。它显示一条错误消息。如何解决这个错误? ListrouteList=null; List companyList = session.createS
我有以下模型类: @Entity @Table(name="user_content") @org.hibernate.annotations.NamedQueries({ @org.
我有那个错误。这是我的代码: GmailSettingsService service = new GmailSettingsService(APPLICATION_NAME, DOMAIN_NAME
实际上我在执行我的java程序时遇到了下面提到的错误 Exception in thread "pool-1-thread-1" java.lang.ClassCastException: jav
java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.String 我在以下代码中遇到此异常: Strin
我正在尝试从 linkedhashset 中检索随机元素。下面是我的代码,但它每次都给我异常。 private static void generateRandomUserId(Set userIds
我已经完成了 Android 中的代码: List spinnerArray = new ArrayList(); for (int i = 0; i item = (LinkedTreeMap)
这个问题已经有答案了: Explanation of ClassCastException in Java (12 个回答) 已关闭 6 年前。 我已经编写了 java 到 Json 的代码,同时从页
这个问题在这里已经有了答案: ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn (4 个答案) 关闭 6 年前
我在运行时遇到问题来编译这段代码,这给我一个错误,java.lang.Integer 无法转换为 Java.lang.Double。如果有人帮助我更正此代码,我将非常高兴 double x; pu
我是一名优秀的程序员,十分优秀!