MVC + JET [message #55951] |
Thu, 22 January 2009 08:52  |
Eclipse User |
|
|
|
Hello,
do you have some references or some tips to enforce a strict separation
between the model, the logic and the templates (MVC pattern or MVC-like)?
Thanks in advance.
|
|
|
Re: MVC + JET [message #56004 is a reply to message #55951] |
Thu, 22 January 2009 14:58   |
Eclipse User |
|
|
|
Hi:
Here is a basic pattern:
1) templates that generate content correspond to MVC views. These are
templates that are referenced from tags such as <ws:file>
Rules for view templates (VT):
VT1) Avoid doing calculations in the template. Many values may be
pre-calculated by using the <c:set> tag to create 'derived' attributes on
model elements. Such tags are executed in the controller
VT2) The most comment tags in view templates should be <c:get>,
<c:iterate> and conditionals (<c:if>, <c:choose>, ...)
2) templates that orchestrate the creation of contents correspond to the MVC
controller. The main.jet template is the primary controller, although it may
delegate to other templates via <c:include>
Rules for controller templates (CT1):
CT1) Perform any model manipulation and value pre-calculation in the
controller and not view templates. This is generally done by traversing the
model (c:iterate tags) and by using c:set to calculate values.
3) Models. A JET transformations input is a model. However, it may not be
exactly what you need for efficient template execution. You typically may do
one or both of the following (in the controler)
a) Calculate values and store their results as annotations on the
model via <c:set>. These annotations appear to the JET XPath engine as
normal attributes.
b) load or create additional models via tags such as <c:load> and
<c:loadContents>.
Other best practice rules:
1) In view templates, replace whole language tokens. That is:
Don't do: public int get<c:get select="camelCase($e/@fieldName)"/>();
Do do: public int <c:get select="$e/@getter"/>();
(of course, there will be a c:set tag something like this in the
controller (main.jet):
<c:set select="$e" name="getter">get<c:get
select="camelCase($e/@fieldName)"/></c:set>
2) Try to avoid Java code in templates. If you much do Java code, put most
of the code in a utility class, rather than directly in the template.
Hope this is a start.
I've created an JET FAQ page with this information. Please feel free to
share you experiences there:
http://wiki.eclipse.org/M2T-JET-FAQ/Are_there_equivalents_to _the_MVC_pattern_for_JET_transformations%3F
Paul
|
|
|
|
Powered by
FUDForum. Page generated in 0.03781 seconds