Search code examples
javaspring-mvcspring-roo

Embedded Set with Spring Roo (Scaffolding)


I am struggling to scaffold a Class with an „embedded List“.

I have a Product where a scaled Price should be persisted and scaffolded (MVC) within the Product-Class.

The Class for the scale price looks like this

@RooJavaBean
@RooToString
@Embeddable
public class ScalePrice {
    int from;
    int to;
    BigDecimal price;

}

And my naive implementation of the Product-Class looks like this:

@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Product {

    @NotNull
    @Size(min = 2)
    private String shortDescription;

    private String longDescription;

    @Embedded
    private Set<ScalePrice> scalePrices;
} 

Since the List/Set for the Scale Price makes only sense for a particular product, the form should provide a way to enter the Scale Price directly within the product form.

My Question is: is this possible at all with Spring Roo? And if yes, how can this be accomplished?


Solution

  • Spring roo doesn't handle collections very well, so even if you had:

    private Set<Integer> scalePrices;
    

    You would not be able to enter multiple scalePrices on the one form. You could write your own custom tag to support this kind of thing though.