我想计算我的 xhtml 页面上的所有元素。我希望每个下一个元素都以更大的顺序放入 HashMap 中。
private void addComponents(HashMap infos, List components, Integer order, FacesContext context){
System.out.println("Start: "+order); if ((components == null) || components.isEmpty()) { System.out.println("return: "+order); return; } order = order + 1000; for (UIComponent c : components) { System.out.println("HashMap: "+order); infos.put(c.getClientId(context), order); addComponents(infos, c.getChildren(), order, context); System.out.println("Out: "+order); order = order + 1000; } System.out.println("End: "+order); return;
}
我有输出和错误的编号
HashMap: 1000
Start: 1000
return: 1000
Out: 1000
HashMap: 2000
Start: 2000
return: 2000
Out: 2000
HashMap: 3000
Start: 3000
HashMap: 4000
Start: 4000
return: 4000
Out: 4000
HashMap: 5000
Start: 5000
return: 5000
Out: 5000
HashMap: 6000
Start: 6000
return: 6000
Out: 6000
End: 7000
Out: 3000
HashMap: 4000
同时以下方法效果很好
private int addComponents(HashMap infos, List components, Integer order, FacesContext context) { if ((components == null) || components.isEmpty()) return order;
for (UIComponent c : components) { order = order + 1000; infos.put(c.getClientId(context), order); order = addComponents(infos, c.getChildren(), order, context); } return order;
}
为什么这两种方法的工作方式不同?