模版数据模型中加入 request #56

Closed
ArmstrongCN opened this Issue Aug 4, 2012 · 8 comments

Projects

None yet

2 participants

@ArmstrongCN
Contributor

For some reasons, we want to have an if-else condition in *.ftl according to request parameters. For example, a parameter decides the style of html output. we can adjust the author-articles.ftl that only print major and clean html when a specified parameter met, so that a special page can refer to some given authors.

@88250
Member
88250 commented Aug 5, 2012

I think puts var into data model from the specified request instead of putting it directly is a better way:

  1. avoids server side process templates slower caused by a request such 'large object props'
  2. minimizes the logic control in template author-articles.ftl, all complexity in pure Java class is better

So, you could take a argument from the specified request and set it into template in a nutshell.

@88250 88250 closed this Aug 5, 2012
@ArmstrongCN
Contributor

Is there any difference between putting a var or a big object like 'request'?

  1. Passing an object may equal to 'passing a reference'. We only look for members that we really need. Never thinking about the look-up time in memory.
  2. The real 'big object' of a 'request' is already consumed by the request handler. We get nothing in template.

In develop strage, it's elegant to limit the logic control in so called 'pure java' part. It should be hard-coded in classes. In product circumstance, however, a good product should also provide a way to extends the functionality without too much hack-in your code.
The code is hacked-in means these things should be recompiled. In practice, we care the 'MVC' elegant no longer. If I want to produce a new page using 'MVC', I may probably wring another set of java classes to go through the architecture. But with the special flags, we can simply change the behave of a template. Believe it or not, convenience is more important than architecture beauty.
So I strongly recommend you to pass the convenience to the view, at least, the request parameters.
Another way to achieve this is to allow the dynamic binding of a ftl. You can take a look at struts2's action dynamic binding.

@88250
Member
88250 commented Aug 6, 2012

Oh, you are right!

No matter tech (*1, *2) or architecture philosophy ("convenience is more important than architecture beauty") you mentioned are totally right.

We will take your suggestion to put the 'request' into a template if it has a var "${request}".

Thank you again, we have a lot learn.

@88250 88250 was assigned Aug 6, 2012
@88250 88250 reopened this Aug 6, 2012
@88250 88250 closed this Aug 7, 2012
@ArmstrongCN
Contributor

So the latke framework is still in google code? If I want to "pull request", what am I supposed to do?

@88250
Member
88250 commented Aug 8, 2012

We will move the Latke to GitHub this weekend, thank you ;-)

@88250
Member
88250 commented Aug 9, 2012

The Latke has been moved to GitHub just now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment