Announcement Announcement Module
No announcement yet.
How to display set of Strings in table Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to display set of Strings in table

    I our domain class we have something like this

    @CollectionTable(name = "principalpermission")
    @Column(name = "permission", length = 100, nullable = false)
    private Set<String> permissions = new HashSet<String>();

    Everything is OK with domain. Getters and setters are created (@RooJavaBean annotation). But problem is how to display this HashSet in roo table tag ij jspx. To be precise, what to specufy for typeIdFieldName attribute value in table tag and what to specify for property value in column tag.

    We are using Roo version 1.2.2 and web mvc add on.


  • #2
    I don't believe the Roo table is set up for this kind of thing. This structure you're showing is an internally owned/managed set. When you update it, I think Hibernate would delete/insert all rows, managing the keys itself.

    What do you want to do with this set? Make it editable? Just show it as a read-only list?

    For read-only lists, you could just iterate over the collection with c:forEach from the EL tag library - they do that in the Spring table.tagx tag anyway if you want to pull the syntax.

    For read-write, you may be trying to oversimplify the model. The problem with the approach above is that Roo is encapsulating the set for you, but sets aren't in a guaranteed order (unless you're using @OrderBy or @Sort, server or client sorting). So, if you want a guaranteed order (let's say you want to move them up/down with Javascript until the order is just right) you can use a bag of values:

    @JoinTable( name = "principalpermission", 
       joinColumns = @JoinColumn(name = "principal"))
    @OrderColumn(name = "permission_index")
    @Column(name = "permission") 
    private Collection<String> permissions = new ArrayList<String>();
    side note - why does a collection column have length and not null?

    Now JPA manages them in the proper order, since there is an internal index column. So, whatever order you return them in, it will delete/insert them in the same order going forward.

    Now, to showing the collection:

    You can just mount the standard el tags and do a c:forEach tag to iterate the items. Nothing stopping you there.

    And forms:

    You're probably on your own, even if these are entities, unless you are just showing the entities themselves. The Roo tags are very specifically able to support basic entity / collection structures, but aren't as flexible as just directly using the Spring MVC forms library.