Announcement Announcement Module
Collapse
No announcement yet.
Problems with MVC scaffolding if date is part of composite key Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with MVC scaffolding if date is part of composite key

    I'm playing around / evaluation roo. Some things are fantastic, but this is one of the quirks I've found. Unfortunately, I have many existing tables with 'effective date' as part of the key, so hopefully there's a good fix soon

    As a test case, I'm attaching the example pizzashop.roo file that is the same as the stock example but with a date field added to PizzaOrderPk.

    First thing that seems odd is that when creating an order the date formatting is not honored on the entry field in the generated ui. In PizzaOrderController, I don't see the pattern added here - should it be?

    Code:
        void PizzaOrderController.addDateTimeFormatPatterns(Model uiModel) {
            uiModel.addAttribute("pizzaOrder_deliverydate_date_format", DateTimeFormat.patternForStyle("M-", LocaleContextHolder.getLocale()));
        }
    When I enter all the required information and hit Save, it simply takes me back to the same page with no error message and the primary key fields blanked out. I pushed in some of the code from the PizzaOrderPk_Roo_Json.aj and stepped through it. It seems to me that the date is coming through in a manner that flexjson doesn't understand and so it bombs out. Unfortunately, there is no form binding with the primary key fields, so the user doens't even get an error message for this, just the same page.

    I fixed the issue in this one case by pushing in and changing the json serialization methods and explicitly putting the date format I wanted in create.jspx. However, I have a lot of tables like this. Is there a good way to make this work in general or should a JIRA issue be opened on this?

    Thanks!

    --For some reason I had problems uploading the file, so here's the text in case it didn't work:

    Code:
    tailor activate --name web-simple
    // Create a new project
    project --topLevelPackage com.springsource.pizzashop --projectName pizzashop
    
    // Setup JPA persistence using EclipseLink and H2
    jpa setup --provider ECLIPSELINK --database H2_IN_MEMORY
    
    // Create domain entities
    entity jpa --class ~.domain.Base --activeRecord false --testAutomatically
    field string --fieldName name --sizeMin 2 --notNull
    
    entity jpa --class ~.domain.Topping --activeRecord false --testAutomatically
    field string --fieldName name --sizeMin 2 --notNull
    
    entity jpa --class ~.domain.Pizza --activeRecord false --testAutomatically
    field string --fieldName name --notNull --sizeMin 2
    field number --fieldName price --type java.math.BigDecimal
    field set --fieldName toppings --type ~.domain.Topping
    field reference --fieldName base --type ~.domain.Base
    
    entity jpa --class ~.domain.PizzaOrder --testAutomatically --activeRecord false --identifierType ~.domain.PizzaOrderPk
    field string --fieldName name --notNull --sizeMin 2
    field string --fieldName address --sizeMax 30
    field number --fieldName total --type java.math.BigDecimal
    field date --fieldName deliveryDate --type java.util.Date
    field set --fieldName pizzas --type ~.domain.Pizza
    
    field string --fieldName shopCountry --class ~.domain.PizzaOrderPk
    field string --fieldName shopCity
    field string --fieldName shopName
    field date --fieldName orderDate --type java.util.Date
    
    // Define a repository layer for persistence
    repository jpa --interface ~.repository.ToppingRepository --entity ~.domain.Topping
    repository jpa --interface ~.repository.BaseRepository --entity ~.domain.Base
    repository jpa --interface ~.repository.PizzaRepository --entity ~.domain.Pizza
    repository jpa --interface ~.repository.PizzaOrderRepository --entity ~.domain.PizzaOrder
    
    // Define a service/facade layer
    service --interface ~.service.ToppingService --entity ~.domain.Topping
    service --interface ~.service.BaseService --entity ~.domain.Base
    service --interface ~.service.PizzaService --entity ~.domain.Pizza
    service --interface ~.service.PizzaOrderService --entity ~.domain.PizzaOrder
    
    // Offer JSON remoting for all domain types through Spring MVC
    json all --deepSerialize
    web mvc json setup
    web mvc json all --package ~.web
    
    web mvc setup
    web mvc all --package ~.web
    
    // Example scripts for JSON remoting:
    // curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{name: "Thin Crust"}' http://localhost:8080/pizzashop/bases
    // curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '[{name: "Cheesy Crust"},{name: "Thick Crust"}]' http://localhost:8080/pizzashop/bases/jsonArray
    // curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '[{name: "Fresh Tomato"},{name: "Prawns"},{name: "Mozarella"},{name: "Bogus"}]' http://localhost:8080/pizzashop/toppings/jsonArray
    // curl -i -X DELETE -H "Accept: application/json" http://localhost:8080/pizzashop/toppings/7
    // curl -i -X PUT -H "Content-Type: application/json" -H "Accept: application/json" -d '{id:6,name:"Mozzarella",version:1}' http://localhost:8080/pizzashop/toppings
    // curl -i -H "Accept: application/json" http://localhost:8080/pizzashop/toppings
    // curl -i -H "Accept: application/json" http://localhost:8080/pizzashop/toppings/6
    // curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{name:"Napolitana",price:7.5,base:{id:1},toppings:[{name: "Anchovy fillets"},{name: "Mozzarella"}]}' http://localhost:8080/pizzashop/pizzas
    // curl -i -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{name:"Stefan",total:7.5,address:"Sydney, AU",deliveryDate:1314595427866,id:{shopCountry:"AU",shopCity:"Sydney",shopName:"Pizza Pan 1"},pizzas:[{id:8,version:1}]}' http://localhost:8080/pizzashop/pizzaorders
Working...
X