I typically build one screen for display/edit/new and try to organize the
screens based on the data.
example, say you have a race track with horses and jockies
/templates/app/screens/
|
\-/templates/app/screens/horse
|
\-/templates/app/screens/jockey
and each directory has a List.vm and an Edit.vm
List.vm will just be a display for all in list form leading you to Edit.vm
for Showing details and or edit with other functions
I usually send a parameter called mode=
if Edit.vm recieves no data parameter, it enters Insert mode, you could
send it a mode=display or mode=edit with the key to load the data
you access these screens with the $link.setPage("horse,List.vm") as such.
Remember to use comma's instead of slashes. Slashes signify data
parameters.
so you could use
$link.setPage("horse,Edit.vm").addPathInfo("mode", "edit").addPathInfo("horseId",
$entry.horseId)
and this would lead you to edit mode with the horse id passed along
you need to setup your screen class in the same directory format as your
templates.
org.myapp.modules.screens.horse.List
org.myapp.modules.screens.horse.Edit
org.myapp.modules.screens.jockey.List
org.myapp.modules.screens.jockey.Edit
and deal with the mode parameter with a case statement or if structure to
enter the correct mode.
you can test for Edit or New with #if ( $entry ) in your vm page. one
other trick is that you use just one set of input fields using
<input type="text" name="horseName" value="$!entry.HorseName">
The bang after the $ signifies to velocity that if the object does not
exist, it will ignore the entry and thus leave you with value="" which is
what you would expect for a new entry.
On Wed, 17 Sep 2003, cctech wrote:
> I'll fairly new to Turbine and Velocity, but nonetheless, I have gone
> Headlong into building a complex application with a large data model.
>
> I have been constructing screens using Velocity for both displaying
> Table data and for editing it. Trouble is, I seem to create Action
> Classes for both display and for edit that are both exactly the same.
I don't think you meant multiple action classes... you should really only
need one action class for HorseSQL.java and JockeySQL.java
you can set multiple clauses within each action class
org.myapp.modules.actions.HorseSQL
You want to follow the info on using action classes on the turbine site.
Action classes should really be thought of as anything that needs to
modify your data. doUpdate() doDelete() doAnything()
Which would be called from your form as eventSubmit_doUpdate
eventSubmit_doDelete and eventSubmit_doAnything
screen classes should be thought of as presenting your data (which may
also be nothing in the case of New entry)
>
> E.g. ShowDetails.java for ShowDetails.vm
> And EditDetails.java for EditDetails.vm (then goes to
> UpdateDetails.java)
>
> In this case the code for the two java classes (Show, Edit) is exactly
> the same except with different class names.
>
> Is there anyway of re-using the same class for different velocity
> templates?
> Have I missed something simple?
>
> Thanks,
> Steve
Jeffery Painter
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]