-
Dec 1st, 2010, 12:37 AM
#1
Setting reference conditionaly
Hi I am new to Spring roo. I am trying to build a demo.
I have a question about field reference.
I have a master table, which has the details for multiple masters based on a master type table.
Table - LocationMaster
Fields
1. Master Type (Region / Country)
2. Description
3. Status
Table - Person
Fields
1. Name
2. Country (here reference to LocationMaster, where Master type = 'Country')
3. Region (here reference to LocationMaster, where Master type = 'Region')
So is it possible to use reference like this?
-
Dec 1st, 2010, 12:54 AM
#2
I am not quite clear what you need exactly here but it sounds like you want to take a look at the 'field reference' command or at using enum type fields. You can see these in use in the clinic.roo sample script we ship with Roo.
HTH,
Stefan
-
Dec 1st, 2010, 01:17 AM
#3
Hi Stefan,
This is what i am trying out,
enum type --class ~.reference.Levels
enum constant --name Country
enum constant --name Region
enum type --class ~.reference.MasterStatus
enum constant --name Inactive
enum constant --name Active
enum constant --name Closed
entity --class ~.domain.MASTERS --testAutomatically
field enum --fieldName level type --type ~.reference.Levels --notNull
field string --fieldName displayText --notNull --sizeMin 3 --sizeMax 30
field enum --fieldName status type --type ~.reference.MasterStatus --notNull
entity --class ~.domain.Person
field string --fieldName name --notNull --sizeMin 3 --sizeMax 30
field reference --fieldName region --type ~.domain.MASTERS
field reference --fieldName country --type ~.domain.MASTERS
Here having trouble defining the last two lines.
I need to set the reference for the field Person.region to masters table where masters.level = "Region'
I need to set the reference for the field Person.country to masters table where masters.level = "Country'
The way i have defined, both the fields will refer to masters table, irrespective of the value of masters.level field.
-
Dec 1st, 2010, 01:38 AM
#4
I am sorry, maybe it is just me today, but I still have trouble understanding your example. Obviously Roo maps all relationships and references via JPA. Can you share the code snippet you think Roo *should* generate here to get your use case working?
It seems to me you should either rethink your domain model or you need to do some manual coding to get it to do what you need. Again, maybe I am just not getting it here
.
-Stefan
-
Dec 1st, 2010, 06:34 AM
#5
Basically, how to have different list of values populated in different dropdowns, refering to the same table.
-
Dec 1st, 2010, 08:17 AM
#6
Ok I have managed to do that.
But i had to change the create.jspx & update.jspx to do that.
I hope it does not get over written by roo.
<field:select field="region" id="c_domain_Person_region" itemValue="id" items="${regions}" path="/masterss" z="Nr8dznZnLG5xELJGd2guB+kdEIo="/>
<field:select field="country" id="c_domain_Person_country" itemValue="id" items="${countries}" path="/masterss" z="8DqDiASpQc+fBtY0oMXZnnHRpDM="/>
Both the fields had the same @ModelAttribute("masterss"). I changed them and modified the controller to define the new @ModelAttribute("regions") and @ModelAttribute("countries").
Do not know, if there is any other way to do the same, without directly modifying the jspx files.
Last edited by msjumbu; Dec 1st, 2010 at 08:21 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules