You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Matthew Koranda <ma...@orkan.no> on 2002/03/19 11:44:05 UTC

Dynamic Forms

I am trying to create an action that would allow me to build an html form based on the table it is meant to insert into. What I mean is that instead of having "static" templates for each form, the page would be built based on the fields it was to insert into. I have had a bit of luck so far but I was coming into a few problems and hoped that someone could give me a little push in the right direction, or perhaps has implemented something similar.

What I have so far is this:

This is the screen code that retrieves a list if the columns:
===================================================================
public class AddBrand extends SecureScreen
{
    /**
     * Place all the data in the context
     * for use in the template.
     */
    public void doBuildTemplate( RunData data, Context context )
    {
        context.put("entries", getEntries());
    }

    /**
     * Get a map of all of the existing columns in this table
     */
    private ColumnMap[] getEntries()
    {
        try
        {
            return BrandsPeer.getColumnMap();
        }
        catch (Exception e)
        {
            return null;
        }
    }
}
==================================================================

The template gets the info and loops through the columns and places a field based on the data type of the field:

 #foreach ($entry in $entries) 
  <tr>
   #if( $entry.getType().getClass().toString() == "class java.lang.String" )
      #formText ("$entry.getColumnName()" "$entry.getColumnName()" "")
   #elseif( $entry.getType().getClass().toString() == "class java.lang.Object" )
      #formTextArea ("$entry.getColumnName()" " "$entry.getColumnName()" " "")
   #elseif( $entry.getType().getClass().toString() == "class java.lang.Integer" )
      #formText ("$entry.getColumnName()" "$entry.getColumnName()" "")
   #else
      "Type not Found!"
   #end
  
  </tr>
 #end


This all works quite well but there are a few problems.
1) I cannot add a "friendly" label to the fields. I see that there is an option to add a description attribute in the XXXXXX-schema.xml file but I don't see hoe I might retrieve it later. I was hoping to add a "human-readable" description of the field in the schema, and then use that description as a form label........is this possible?

2) I would want to use some data types, an integer for example, in different ways. An integer could refer to a drop-down list, a text field, or a checkbox, depending on it's pourpose. The only way I could think of imlementing this was to add some additional ionformation to the schema somehow, Any ideas?

I thnk this would be a useful feature as it would allow me to change my schemas at any time, re-ant, and go, without changing any forms or other logic. It might also allow users to add features on the fly. An example would be a manager wanting to add a description field to a product

Any help would be greatly appreciated, I am quite new to this so please let me know if there is an easier way or if I am completely off-base in my approach.

Thanks!

  Matthew Koranda               
  Brand Theater AS         
  Maridalsvn. 87b, Bygn. 6     
  0461 Oslo                     
                                
  matt@orkan.no                 
  Phone  (+47) 23 12 19 09      
  Mobile (+47) 40 00 82 20