Using Oracle DB when we create the Spring MVC pages using Spring Roo command it creates pages with listing having foreign key replaced by the corresponding record.
I want to show the Foreign key only and don't need the key replaced by record.
Is there a option to get the same. I am not able to figure out the same form the forums.
Regards
Given...
// Spring Roo 1.2.4.BUILD-SNAPSHOT [rev 7c12381] log opened at 2013-06-15 17:13:26
project --topLevelPackage org.foo.bar --projectName baz
jpa setup --provider HIBERNATE --database HYPERSONIC_PERSISTENT
entity jpa --class ~.db.Customer
field string name
entity jpa --class ~.db.Sale
field string --fieldName description
field number --type java.math.BigDecimal --fieldName amount
field reference --fieldName customer --type ~.db.Customer --cardinality MANY_TO_ONE
focus --class ~.db.Customer
field set --fieldName sales --type ~.db.Sale --cardinality ONE_TO_MANY
web mvc setup
web mvc all --package ~.web
quit
When you show the list of Customers (one side) it shows just the customer data. For the sales (many) side, it shows the Customer column, with the field value of all fields concatenated together (which in our case is just name) for the foreign key.
Here are the relevant tags:
<table:table data="${sales}"
id="l_org_foo_bar_db_Sale"
path="/sales" z="4N/i5ige4wSEk62VRQK6R47NPIQ=">
...
<table:column id="c_org_foo_bar_db_Sale_customer"
property="customer" z="v8Cm6lkbb5e5TiYflyqTaRGopvg="/>
...
</table>
Unfortunately the table and column tags are a bit tricky. The column tags are used in the rendering of the table heading and body for each row, so that the table:table tag is in charge. And it doesn't allow something like property="customer.id"
so that kills that strategy.
One way out of this is to 'push-in' refactor the converter for Customer in the ApplicationConversionServiceFactoryBean. Look at the .aj file and pull out the method for your entity, replacing it with something that just returns the ID:
public Converter<Customer, String> getCustomerToStringConverter() {
return new Converter<Customer, String>() {
public String convert(Customer customer) {
return customer.getId().toString();
}
};
The problem is that every drop-down list will get the new value. So if you have an edit form and you want to reference the name of the customer in there so people can make an informed decision, it won't work out of the box.
There is a way around that, too. You can modify the field:select
tag in the update and create forms of the sale domain - adding the itemLabel
property to determine which field to show in the drop-down. It doesn't take an expression, so you may want to create getters that return multiple fields concatenated when you have to show them.
We cover that kind of customization of the scaffolding in RooInAction chapter 6. However, eventually you may want to switch to building the forms yourself just using straight Spring MVC - you have more options then for view file types, implementation patterns, etc...
Ken