I have two database tables.
One table stores data for a commitment that a supervisor is responsible for.
The other is a lookup table of available programs. The program primary key is a foreign key in the commitment table (A commitment is against a particular funded program).
I have two Javabean objects that represent these tables, I think they are called DTO?? Anyways….
Now in my jsp view (for editing or inserting a commitment), I don’t want users to see or have to enter the primary key to the program, but instead would rather they use a select pull down that shows the resolved program name with the fk id as the select option value.
My question is:
Should I be passing two attributes in the request – ‘commitment’ which represents the single row record in the db of that specific commitment (if editing) and the programList a list of available prgrams that I iterate over to display in a pull down??
Or should I modify my commitment DTO and make it have an attribute that can store a list of available programs (as program DTO’s) so that then I’d only need to pass in the commitment DTO in a request attribute to my view?
Your first approach is more self-documenting. A commitment is tied to a specific program, not to multiple programs. Having a
List<Program>inCommitmentis therefore confusing to others (and also to yourself when you look back one year later).That said, if the
List<Program>is application-wide (read: it’s always the same list for every user/session), I’d just put it in the application scope rather than the request scope.