How to display many to many jpa collection in jsf?

前端 未结 1 905

i made many to many join table between users and groups tables . so i have a collection in each entitie ( Users and groups )

@ManyToMany(mappedBy = \"usersCo         


        
相关标签:
1条回答
  • 2021-01-14 19:53

    You normally use an iterating component such as <ui:repeat> or <h:dataTable> to iterate over a collection. You can perfectly nest it inside another iterating component.

    E.g.

    <p:column headerText="groupe"> 
        <ui:repeat value="#{user.groupsCollection}" var="groups">
            <h:outputText value="#{groups.groupname}" /><br/>
        </ui:repeat>
    </p:column>
    

    Unrelated to the concrete problem, you've there some poor naming convention. One group should be represented by a class named Group, not Groups. I suggest to rename the one and other so that the code becomes so much more self documenting:

    <p:column headerText="groups"> 
        <ui:repeat value="#{user.groups}" var="group">
            <h:outputText value="#{group.name}" /><br/>
        </ui:repeat>
    </p:column>
    

    The plural s in the field/variable name should already be indicative that it concerns a collection.

    0 讨论(0)
提交回复
热议问题