basically the problem is creating the html form. You seem to have figured out your model. What you are missing is an idea. I did something like the following one time to create a model for a simple DB model.
I provide a list of fields, and the user interface is created based on the fields. I had only text fields, and I need only 2 cases (visible and invisible). Your usecase may require more complexity, so you can adapt if necessary.
dish.fields contains fields with relevant metadata. Any special things, such as require verification or are necessary, you will need to provide this information for presentation so that it can visualize the field accordingly.
The simplest way to simulate it would be to start with an HTML form and begin to generalize it one field at a time.
#{list items:dish.fields, as:'f'} #{field 'f'} #{if f.display } <div class="control-group"> <label class="control-label"> &{f.name} </label> <div class="controls"> <input type="text" class="input-xlarge" placeholder="&{f.name}" name="${dish.getFieldId(f)}" value="${dish.getValue(f)}" ></input> </div> </div> #{/if} #{else} <input type="hidden" class="input-xlarge" placeholder="&{f.name}" name="${dish.getFieldId(f)}" value="${dish.getValue(f)}" ></input> #{/else} #{/field} #{/list} #{else} No fields #{/else}
I needed to define my own fields, but you should be able to get this idea.
You will probably have to have many different input types for different use cases, so start with simple ones and generalize as you continue. You can also take a look at the implementation of the CRUD module.
my DisplayAttribute class (metadata for fields) looks something like this: You can use it as a starting point.
public class DisplayAttribute { public Boolean display = Boolean.TRUE; public String type = ""; public String name; public DisplayAttribute(String name){ this.name = name; this.display = Boolean.TRUE; } public DisplayAttribute(String name, Boolean display){ this.name = name; this.display = display; } ... overridden equals and hash }
edit How fields are processed? The controller passes the metadata ( DisplayAttribute ) to the view, in this case the metadata contains only the field name and can be displayed or not.
Model
Here, the model contains fields for rendering, but you can just as easily retrieve them from the database. My model is shared because I realized that I continued to do the same thing over and over for several models.
I implement my own interface, which gives me the getFields method. I also support two maps, so given the attribute, I can get its DisplayAttribute, and given the DisplayAttribute attribute, I get its name. I call the methods of this model from the view when necessary.
public class GenericSimpleDBModel implements SimpleDBModel { public static AmazonSimpleDB sdb = null; private static final String bracketRemovalPattern = "(^.*?\\[|\\]\\s*$)"; private Map<DisplayAttribute, Set<String>> data = new TreeMap<DisplayAttribute, Set<String>>(new UuidComparator()); private Map<String, DisplayAttribute> attributeCache = new HashMap<String, DisplayAttribute>(); protected final String DOMAIN_NAME; public GenericSimpleDBModel() { initialize(getFields()); this.DOMAIN_NAME = "dishes"; } protected void initialize(String[] fields) { data = new TreeMap<DisplayAttribute, Set<String>>(new UuidComparator()); attributeCache = new HashMap<String, DisplayAttribute>(); for (String f : fields) {