简体   繁体   English

复合组件递归传递支持bean

[英]composite component recursive passing backing bean

I everyone i'm trying to make a recursive menu using composite components but i cant figure out how to pass a backingbean in to the same composite component well mi code looks like this 我每个人都在尝试使用复合组件制作递归菜单,但是我不知道如何将backingbean传递到相同的复合组件中,mi代码看起来像这样

<composite:interface>
     <composite:attribute name="bean" required="true"/>
     <composite:attribute name="node" required="true"/>
</composite:interface>

<cc:implementation>
     <--some code here-->

     <c:if test="#{not empty cc.attrs.bean.obtainsubmenu(cc.attrs.node)}">
          <c:foreach items="cc.attrs.bean.obtainsubmenu(cc.attrs.node)" var="submenu">
               <!--some other code here-->
               <menu:recursivemenu
                   bean="#{cc.attrs.bean}"
                   node="#{submenu.idOpc}"
               />
          </c:foreach>    
     </c:if>
</cc:implementation>

the method obtainsubmenu only returns a list of objects the method looks something like this 方法getgetsubmenu仅返回对象列表,该方法看起来像这样

public List<myObject> obtainsubmenu(Long id){
 return mymap.get(id); //where my maps is parametized  this way Map<Long, List<MyObject>
}

For the first level of my menu it looks to work just fine the problem is when it tries to call itself to do the recursive it is not pasing the object reference as it should and i'm getting an stackoverflow exception cause because the map is null 对于我的菜单的第一个级别,它看起来可以正常工作,问题是当它尝试调用自身以进行递归时,它没有按原样粘贴对象引用,并且由于映射为空,我遇到了stackoverflow异常原因

is there a way to do this?? 有没有办法做到这一点??

Tanks for the help!! 坦克的帮助!

first of all, you shouldn't use JSTL tags, but JSF ones. 首先,您不应使用JSTL标签,而应使用JSF标签。

empty-check should not be necessary, either 也不应该进行空检查

<composite:interface>
     <composite:attribute name="bean" required="true"/>
     <composite:attribute name="node" required="true"/>
</composite:interface>

<cc:implementation>
     <--some code here-->

    <ui:repeat value="#{cc.attrs.bean.obtainsubmenu(cc.attrs.node)}" var="submenu">
        <!--some other code here-->
        <menu:recursivemenu bean="#{cc.attrs.bean}" node="#{submenu.idOpc}"/>
    </ui:repeat>    
</cc:implementation>

however, if you are creating a Primefaces menu, this approach will not work. 但是,如果创建的是Primefaces菜单,则此方法将不起作用。 you have to build your programmatic menu inside a MenuModel 您必须在MenuModel构建您的编程菜单

more generally, if your menu root component is responsible for rendering its child components itself ( menuComponent.getRendersChildren() returns true ) this kind of approach will not work. 更一般而言,如果菜单根组件负责呈现其子组件本身( menuComponent.getRendersChildren()返回true ),则这种方法将行不通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM