Adam Hardy wrote:
On 19/05/05 21:29 Laurie Harper wrote:

This is what I decided to try first. I threw together a prototype last night, and it seams to work well. Basically, the idea is:

- extend the view API to include 'View.toMap(Map props)' and 'void View.fromMap(Map props)' on each view class

- you can then do view.fromMap(form.getMap()) and view.toMap(form.getMap()) to translate between views and form beans

- add a custom tag which takes a form bean and a view and loads the form's map from the view (I've implemented this so it can lookup the form bean from an enclosing <html:form/> tag, so you only have to pass in the view)

Now, my JSPs can do something like this:

<jsp:useBean id="view" class="MyViewBean"/>
... setup view (e.g. populate from db) ...
<x:loadForm view="${view}"/>

Now, the form bean associated with the enclosing form is populated from the view object. On subsequent page loads, I can skip the loadForm tag, and the form bean has the data from the previous submission.


You skip the whole tag? Using JSTL or something in the JSP? How do you tell? Can you do that inside the loadForm tag to keep the JSP cleaner?

I haven't settled on a mechanism for deciding yet; I'm leaning towards just having a query parameter reload=true or something, then using notPresent to wrap the loadForm tag.

Surely though you need some items of data just for display (which wont be resubmitted with the form because you didn't put them in form fields) and you can also use the view object to check whether you need to save (if nothing changed)?

Yes, quite likely, and using the pull model I can always get the data I need at the point where I need it. All this is just a mechanism on top of that to enable form data to be round-tripped cleanly.

BTW how does your viewbean behave? Does it call the back end when it is instantiated, or just when it decides it needs the data?

I have a service layer which implements the business transactions the system supports. It's responsible for using a DAO to load domain data and transfer it into view objects. So basically, the view objects / DTOs are the data encapsulation mechanism for interacting with the service layer.

From the presentation layer's perspective, the view objects are how it invokes data retrival operations on the service layer. So in my JSP I say 'use bean User, set view to loginId' and the bean takes care of calling the UserService.lookupUser(userId) method and populating itself.

Or something like that, the design is still emerging as I prototype :)

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to