You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@roller.apache.org by Allen Gilliland <al...@sun.com> on 2006/06/16 22:08:17 UTC
New page models design (was Re: Atlas proposals: Frontpage weblog and
new Page Macro/Models)
Dave,
I wanted to go back to the beginning of this discussion and sidetrack on
a discussion about how the PageModel interface is defined and how the
page models are instantiated and used.
Right now the PageModel interface has this method for init ...
public void init(HttpServletRequest request);
... and I'm wondering if it would be better to make that init method
even more generic. I think that each page model implementation will
probably want to get a different set of initial data to make use of in
the model. For example, I can imagine that the WeblogPageModel may want
to use a parsed WeblogPageRequest, or a WebsiteData and WeblogEntryData
objects. So, I think there is definitely some potential uses for
initializing a page model with more than just the request object.
I am thinking that we could modify that init() method to this ...
public void init(Map data) throws ModelInitializationException;
... this way whatever piece of code is initializing that page model can
pass in a set of data that may be useful to the page model. We also
allow the page model to throw an exception during init if somehow the
page model doesn't receive all the data it needs or something else bad
happens during init.
think that makes sense?
The other smaller thing that I wanted to touch on is the idea that page
models do not need to be so generic that they don't behave differently
given different input. I think that some page models will certainly
want to behave a little differently based on the input they are given
during initialization. A good example of this would be the
WeblogPageModel.
I think it could be very useful if this model had a method like
getEntries() which simply returned the list of entries represented by
the request the model was constructed for. So if the request was for
the weblog homepage then it returns the most recent XX entries as
defined by the weblog settings. If the request is for a permalink then
it returns only a single entry. If the request is constrained by date,
category, etc, then it returns only the entries that are appropriate.
The benefit of an approach like this is that it takes the logic of what
entries to query for out of the macros and puts it into the model. This
is good because it keeps logic out of the "View" which is supposed to
only deal with display stuff.
Another example might be methods like getNextPageLink() and
getPrevPageLink() which may return links to the next/prev month in one
condition, but return links to next/prev entry in another situation.
The logic would be built into the method so that the view doesn't need
to worry about whether it's looking for the next entry, next month, next
entry in category, etc. All it needs is to ask for the next/prev links
and it gets back the right thing.
Anyways, you may already have been planning on doing that, but I wanted
to throw it out there anyways.
-- Allen
Dave Johnson wrote:
> I've already started implementation of the new Atlas frontpage proposal:
> http://rollerweblogger.org/wiki/Wiki.jsp?page=Proposal_Atlas
>
> And today I posted the first draft of a new Atlas Page Macro/Models
> proposal:
> http://rollerweblogger.org/wiki/Wiki.jsp?page=ProposalAtlasMacroModels
>
> The new Atlas macro/models proposal is pretty significant. I'm
> proposing that we replace the old page models and macros that are used
> in all existing Roller themes with an entirely new set of models and
> macros. It's important that we get this right -- we don't want to have
> to do this again.
>
> The old system will still be available, but it will be possible to
> either 1) leave it in place, 2) leave it in place but not allow new
> blogs to use it or 3) to turn if off entirely.
>
> Please review and offer feedback.
>
> - Dave
Re: New page models design (was Re: Atlas proposals: Frontpage weblog and new Page Macro/Models)
Posted by Dave Johnson <sn...@gmail.com>.
Just to wrap this up: We're going with init(Map map) so that (someday)
we can remove Servlet API stuff from our page models (or some subset
of them) and support static rendering.
- Dave
Re: New page models design (was Re: Atlas proposals: Frontpage weblog
and new Page Macro/Models)
Posted by Allen Gilliland <al...@sun.com>.
another thought below ...
Allen Gilliland wrote:
> comments below ...
>
> Dave Johnson wrote:
>> Comments inline...
>>
>> On 6/17/06, Allen Gilliland <Al...@sun.com> wrote:
>>> Dave Johnson wrote:
>>> > On 6/16/06, Allen Gilliland <al...@sun.com> wrote:
>>> >> I am thinking that we could modify that init() method to this ...
>>> >>
>>> >> public void init(Map data) throws ModelInitializationException;
>>> >
>>> >> ... this way whatever piece of code is initializing that page
>>> model can
>>> >> pass in a set of data that may be useful to the page model. We also
>>> >> allow the page model to throw an exception during init if somehow the
>>> >> page model doesn't receive all the data it needs or something else
>>> bad
>>> >> happens during init.
>>> >>
>>> >> think that makes sense?
>>> >
>>> > I don't think we can anticipate all of the things that a page model
>>> > author will need to access within a model and using a request here
>>> > stikes a good balance. Authors have access to the request and at the
>>> > same time we can provide access to request related things like the
>>> > parsed WeblogPageRequest object via request attibutes.
>>>
>>> I agree, we can't anticipate everything that a page model would need,
>>> but to me that is more of a reason to give it mode data than less data.
>>> I definitely think that the original request will still go in the Map
>>> of data passed into each page model, but using the Map instead of just
>>> the request has a couple benefits in my mind ...
>>
>> The request attribute already give us a map: request attributes.
>>
>>
>>> 1. It's extensible. If at any time in the future we decide that each
>>> page model should have something else at init time then it's trivial to
>>> add it. Using just the request means we would have to refactor the
>>> interface and all implementors to fit the need.
>>
>> Could use request attributes, that's what they're for.
>>
>>
>>> 2. Custom implementations have more options. What if someone wants to
>>> create their own servlet to add some functionality that we don't provide
>>> and they create a custom page model for it? What if they want that page
>>> model to be initialized with more data. Using a Map makes that easy
>>> because the code that constructs the page model can pass in any data
>>> they want.
>>>
>>> 3. It's more efficient. In many cases a servlet or other code will
>>> already have done some parsing/validation on the request before the page
>>> model is constructed. Why force that work to be duplicated? By letting
>>> additional objects be passed into the init method we can reduce
>>> redundant work like parsing the request, looking up pojos like the
>>> Website object, etc.
>>
>> The model could just pull a parsed WeblogRequest object from the
>> request attributes.
>>
>> I would have added "easier unit testing" as an advantage to using a
>> Map, but the fact that all page models need the request negates that
>> advantage.
>>
>>
>>> So I think I am still a fan of using a Map instead of just the servlet
>>> request for page model init. I don't think there is anything to lose by
>>> doing it. We could alternatively have the init method be init(request,
>>> Map data), so the page model is guaranteed to get the request and the
>>> Map is purely optional extra data.
>>
>> I really don't like the idea of sticking the request in a map.
>> So if you insist on a map, I'd like to do as you suggest:
>>
>> init(request, Map)
>
> weird, i thought i had actually suggested that, but maybe i just thought
> about it and didn't say it. in any case, yes, i think this is a better
> approach than just using a map.
>
> i still prefer this approach over using request attributes mainly
> because the problem with request attributes is that they are then
> attached to the request for the rest of its processing, which may not be
> desired. the data we are planning to put in the Map is supposed to only
> be made available to the page model, so i think it's a bit cleaner to
> use our own Map rather than request attributes.
One additional thing to consider is that on some level it may be
undesirable to have the page model be based off of the request object.
I'm not really sure if that's practical yet, but if you consider that we
would like to be able to support static rendering of any page at some
point then the request probably shouldn't be part of the page model.
For static page rendering you would need to be able to construct page
models without the use of a request, so maybe it's better if instead of
using a request we break things down into our own set of objects which
get passed into the page model init() method. This way we can ensure
that page models are not tied to the request/response cycle.
-- Allen
>
> -- Allen
>
>
>>
>> - Dave
Re: New page models design (was Re: Atlas proposals: Frontpage weblog
and new Page Macro/Models)
Posted by Allen Gilliland <al...@sun.com>.
comments below ...
Dave Johnson wrote:
> Comments inline...
>
> On 6/17/06, Allen Gilliland <Al...@sun.com> wrote:
>> Dave Johnson wrote:
>> > On 6/16/06, Allen Gilliland <al...@sun.com> wrote:
>> >> I am thinking that we could modify that init() method to this ...
>> >>
>> >> public void init(Map data) throws ModelInitializationException;
>> >
>> >> ... this way whatever piece of code is initializing that page model
>> can
>> >> pass in a set of data that may be useful to the page model. We also
>> >> allow the page model to throw an exception during init if somehow the
>> >> page model doesn't receive all the data it needs or something else bad
>> >> happens during init.
>> >>
>> >> think that makes sense?
>> >
>> > I don't think we can anticipate all of the things that a page model
>> > author will need to access within a model and using a request here
>> > stikes a good balance. Authors have access to the request and at the
>> > same time we can provide access to request related things like the
>> > parsed WeblogPageRequest object via request attibutes.
>>
>> I agree, we can't anticipate everything that a page model would need,
>> but to me that is more of a reason to give it mode data than less data.
>> I definitely think that the original request will still go in the Map
>> of data passed into each page model, but using the Map instead of just
>> the request has a couple benefits in my mind ...
>
> The request attribute already give us a map: request attributes.
>
>
>> 1. It's extensible. If at any time in the future we decide that each
>> page model should have something else at init time then it's trivial to
>> add it. Using just the request means we would have to refactor the
>> interface and all implementors to fit the need.
>
> Could use request attributes, that's what they're for.
>
>
>> 2. Custom implementations have more options. What if someone wants to
>> create their own servlet to add some functionality that we don't provide
>> and they create a custom page model for it? What if they want that page
>> model to be initialized with more data. Using a Map makes that easy
>> because the code that constructs the page model can pass in any data
>> they want.
>>
>> 3. It's more efficient. In many cases a servlet or other code will
>> already have done some parsing/validation on the request before the page
>> model is constructed. Why force that work to be duplicated? By letting
>> additional objects be passed into the init method we can reduce
>> redundant work like parsing the request, looking up pojos like the
>> Website object, etc.
>
> The model could just pull a parsed WeblogRequest object from the
> request attributes.
>
> I would have added "easier unit testing" as an advantage to using a
> Map, but the fact that all page models need the request negates that
> advantage.
>
>
>> So I think I am still a fan of using a Map instead of just the servlet
>> request for page model init. I don't think there is anything to lose by
>> doing it. We could alternatively have the init method be init(request,
>> Map data), so the page model is guaranteed to get the request and the
>> Map is purely optional extra data.
>
> I really don't like the idea of sticking the request in a map.
> So if you insist on a map, I'd like to do as you suggest:
>
> init(request, Map)
weird, i thought i had actually suggested that, but maybe i just thought
about it and didn't say it. in any case, yes, i think this is a better
approach than just using a map.
i still prefer this approach over using request attributes mainly
because the problem with request attributes is that they are then
attached to the request for the rest of its processing, which may not be
desired. the data we are planning to put in the Map is supposed to only
be made available to the page model, so i think it's a bit cleaner to
use our own Map rather than request attributes.
-- Allen
>
> - Dave
Re: New page models design (was Re: Atlas proposals: Frontpage weblog and new Page Macro/Models)
Posted by Dave Johnson <sn...@gmail.com>.
Comments inline...
On 6/17/06, Allen Gilliland <Al...@sun.com> wrote:
> Dave Johnson wrote:
> > On 6/16/06, Allen Gilliland <al...@sun.com> wrote:
> >> I am thinking that we could modify that init() method to this ...
> >>
> >> public void init(Map data) throws ModelInitializationException;
> >
> >> ... this way whatever piece of code is initializing that page model can
> >> pass in a set of data that may be useful to the page model. We also
> >> allow the page model to throw an exception during init if somehow the
> >> page model doesn't receive all the data it needs or something else bad
> >> happens during init.
> >>
> >> think that makes sense?
> >
> > I don't think we can anticipate all of the things that a page model
> > author will need to access within a model and using a request here
> > stikes a good balance. Authors have access to the request and at the
> > same time we can provide access to request related things like the
> > parsed WeblogPageRequest object via request attibutes.
>
> I agree, we can't anticipate everything that a page model would need,
> but to me that is more of a reason to give it mode data than less data.
> I definitely think that the original request will still go in the Map
> of data passed into each page model, but using the Map instead of just
> the request has a couple benefits in my mind ...
The request attribute already give us a map: request attributes.
> 1. It's extensible. If at any time in the future we decide that each
> page model should have something else at init time then it's trivial to
> add it. Using just the request means we would have to refactor the
> interface and all implementors to fit the need.
Could use request attributes, that's what they're for.
> 2. Custom implementations have more options. What if someone wants to
> create their own servlet to add some functionality that we don't provide
> and they create a custom page model for it? What if they want that page
> model to be initialized with more data. Using a Map makes that easy
> because the code that constructs the page model can pass in any data
> they want.
>
> 3. It's more efficient. In many cases a servlet or other code will
> already have done some parsing/validation on the request before the page
> model is constructed. Why force that work to be duplicated? By letting
> additional objects be passed into the init method we can reduce
> redundant work like parsing the request, looking up pojos like the
> Website object, etc.
The model could just pull a parsed WeblogRequest object from the
request attributes.
I would have added "easier unit testing" as an advantage to using a
Map, but the fact that all page models need the request negates that
advantage.
> So I think I am still a fan of using a Map instead of just the servlet
> request for page model init. I don't think there is anything to lose by
> doing it. We could alternatively have the init method be init(request,
> Map data), so the page model is guaranteed to get the request and the
> Map is purely optional extra data.
I really don't like the idea of sticking the request in a map.
So if you insist on a map, I'd like to do as you suggest:
init(request, Map)
- Dave
Re: New page models design (was Re: Atlas proposals: Frontpage weblog
and new Page Macro/Models)
Posted by Allen Gilliland <Al...@Sun.COM>.
Dave Johnson wrote:
> On 6/16/06, Allen Gilliland <al...@sun.com> wrote:
>> I am thinking that we could modify that init() method to this ...
>>
>> public void init(Map data) throws ModelInitializationException;
>
>> ... this way whatever piece of code is initializing that page model can
>> pass in a set of data that may be useful to the page model. We also
>> allow the page model to throw an exception during init if somehow the
>> page model doesn't receive all the data it needs or something else bad
>> happens during init.
>>
>> think that makes sense?
>
> I don't think we can anticipate all of the things that a page model
> author will need to access within a model and using a request here
> stikes a good balance. Authors have access to the request and at the
> same time we can provide access to request related things like the
> parsed WeblogPageRequest object via request attibutes.
I agree, we can't anticipate everything that a page model would need,
but to me that is more of a reason to give it mode data than less data.
I definitely think that the original request will still go in the Map
of data passed into each page model, but using the Map instead of just
the request has a couple benefits in my mind ...
1. It's extensible. If at any time in the future we decide that each
page model should have something else at init time then it's trivial to
add it. Using just the request means we would have to refactor the
interface and all implementors to fit the need.
2. Custom implementations have more options. What if someone wants to
create their own servlet to add some functionality that we don't provide
and they create a custom page model for it? What if they want that page
model to be initialized with more data. Using a Map makes that easy
because the code that constructs the page model can pass in any data
they want.
3. It's more efficient. In many cases a servlet or other code will
already have done some parsing/validation on the request before the page
model is constructed. Why force that work to be duplicated? By letting
additional objects be passed into the init method we can reduce
redundant work like parsing the request, looking up pojos like the
Website object, etc.
So I think I am still a fan of using a Map instead of just the servlet
request for page model init. I don't think there is anything to lose by
doing it. We could alternatively have the init method be init(request,
Map data), so the page model is guaranteed to get the request and the
Map is purely optional extra data.
-- Allen
>
> I do think the init method should throw an exception.
>
>
>> The other smaller thing that I wanted to touch on is the idea that page
>> models do not need to be so generic that they don't behave differently
>> given different input. I think that some page models will certainly
>> want to behave a little differently based on the input they are given
>> during initialization. A good example of this would be the
>> WeblogPageModel.
>>
>> I think it could be very useful if this model had a method like
>> getEntries() which simply returned the list of entries represented by
>> the request the model was constructed for. So if the request was for
>> the weblog homepage then it returns the most recent XX entries as
>> defined by the weblog settings. If the request is for a permalink then
>> it returns only a single entry. If the request is constrained by date,
>> category, etc, then it returns only the entries that are appropriate.
>
> Yes and that's essentially how the page model works now. It behaves
> differerently based on what is in the request, so it does different
> things if a specific day or month is specified.
>
>
>> The benefit of an approach like this is that it takes the logic of what
>> entries to query for out of the macros and puts it into the model. This
>> is good because it keeps logic out of the "View" which is supposed to
>> only deal with display stuff.
>>
>> Another example might be methods like getNextPageLink() and
>> getPrevPageLink() which may return links to the next/prev month in one
>> condition, but return links to next/prev entry in another situation.
>> The logic would be built into the method so that the view doesn't need
>> to worry about whether it's looking for the next entry, next month, next
>> entry in category, etc. All it needs is to ask for the next/prev links
>> and it gets back the right thing.
>
> Yep. That's how they worked in 2.0 and they should continue to work.
>
> - Dave
Re: New page models design (was Re: Atlas proposals: Frontpage weblog and new Page Macro/Models)
Posted by Anil Gangolli <an...@busybuddha.org>.
comment inline
----- Original Message -----
From: "Dave Johnson" <sn...@gmail.com>
To: <ro...@incubator.apache.org>
Sent: Friday, June 16, 2006 2:28 PM
Subject: Re: New page models design (was Re: Atlas proposals: Frontpage
weblog and new Page Macro/Models)
> On 6/16/06, Allen Gilliland <al...@sun.com> wrote:
>> I am thinking that we could modify that init() method to this ...
>>
>> public void init(Map data) throws ModelInitializationException;
>
>> ... this way whatever piece of code is initializing that page model can
>> pass in a set of data that may be useful to the page model. We also
>> allow the page model to throw an exception during init if somehow the
>> page model doesn't receive all the data it needs or something else bad
>> happens during init.
>>
>> think that makes sense?
>
> I don't think we can anticipate all of the things that a page model
> author will need to access within a model and using a request here
> stikes a good balance. Authors have access to the request and at the
> same time we can provide access to request related things like the
> parsed WeblogPageRequest object via request attibutes.
>
> I do think the init method should throw an exception.
This suggests it would be a checked exception. I don't see any reason not
to make ModelInitializationException a subclass of RuntimeException here.
Re: New page models design (was Re: Atlas proposals: Frontpage weblog and new Page Macro/Models)
Posted by Dave Johnson <sn...@gmail.com>.
On 6/16/06, Allen Gilliland <al...@sun.com> wrote:
> I am thinking that we could modify that init() method to this ...
>
> public void init(Map data) throws ModelInitializationException;
> ... this way whatever piece of code is initializing that page model can
> pass in a set of data that may be useful to the page model. We also
> allow the page model to throw an exception during init if somehow the
> page model doesn't receive all the data it needs or something else bad
> happens during init.
>
> think that makes sense?
I don't think we can anticipate all of the things that a page model
author will need to access within a model and using a request here
stikes a good balance. Authors have access to the request and at the
same time we can provide access to request related things like the
parsed WeblogPageRequest object via request attibutes.
I do think the init method should throw an exception.
> The other smaller thing that I wanted to touch on is the idea that page
> models do not need to be so generic that they don't behave differently
> given different input. I think that some page models will certainly
> want to behave a little differently based on the input they are given
> during initialization. A good example of this would be the
> WeblogPageModel.
>
> I think it could be very useful if this model had a method like
> getEntries() which simply returned the list of entries represented by
> the request the model was constructed for. So if the request was for
> the weblog homepage then it returns the most recent XX entries as
> defined by the weblog settings. If the request is for a permalink then
> it returns only a single entry. If the request is constrained by date,
> category, etc, then it returns only the entries that are appropriate.
Yes and that's essentially how the page model works now. It behaves
differerently based on what is in the request, so it does different
things if a specific day or month is specified.
> The benefit of an approach like this is that it takes the logic of what
> entries to query for out of the macros and puts it into the model. This
> is good because it keeps logic out of the "View" which is supposed to
> only deal with display stuff.
>
> Another example might be methods like getNextPageLink() and
> getPrevPageLink() which may return links to the next/prev month in one
> condition, but return links to next/prev entry in another situation.
> The logic would be built into the method so that the view doesn't need
> to worry about whether it's looking for the next entry, next month, next
> entry in category, etc. All it needs is to ask for the next/prev links
> and it gets back the right thing.
Yep. That's how they worked in 2.0 and they should continue to work.
- Dave