You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Christopher Gardner <ch...@gmail.com> on 2007/10/10 12:27:58 UTC

Use of the Presentation Model Pattern

I've been experimenting with the Model-View-Presenter
(http://martinfowler.com/eaaDev/PassiveScreen.html) and the
Presentation Model
(http://martinfowler.com/eaaDev/PresentationModel.html) patterns in
Wicket.  It seems like a variation of the Presentation Model approach
could work well and /may/ reduce the need for things like
LoadableDetachableModels.

In this variation, model attributes could access service objects
dynamically.   For example:

class PlanSetup extends WebPage {
 ...
 PlanSetup(String customerId) {
   ...
   setModel(new CompoundPropertyModel(new PlanSetupPresentation(customerId))
 }
 ...
}

class PlanSetupPresentation {
 ...

 List<Plan> getPlans() {
   //would a LoadableDetachableModel still be needed to call this method?
   //you could still use one if necessary.
   return planService.findPlansByCustomerId(customerId)
 }

 void setPlanId(Integer planId) {
   //this would be provided by a component in PlanSetup culled from
   //the planId of a Plan that the user selected from among
   //the plans returned by getPlans().
   this.planId = planId
 }

 Plan getPlan()
   //if necessary other things could be done in this method based on plan
   //attributes before actually returning the plan (e.g., setting an warning
   //message in another property).
   this.plan = planService.findByPlanId(planId}
   return plan
 }

 void updatePlan() {
   planService.update(plan)
 }
 ...
}

One issue would be how the presentation model accessed service objects
(e.g., planService).  Perhaps it could use a proxy or a lookup
mechanism to get around serialization requirements.

If there are no real gotchas, this approach would let you write less
Wicket code and test your presentation logic without Wicket.  Wicket
wouldn't need to know anything about service or application level
objects, for example.  And, heaven forbid, if the corporate standards
committee makes you replace Wicket with JSF (and things like that do
happen), you still might be able to use the same presentation model.

Has anyone on the list tried something like this?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org