Raible's Wiki
Raible Designs AppFuseHomepage- Korean - Chinese - Italian - Japanese QuickStart Guide User Guide Tutorials Other ApplicationsStruts ResumeSecurity Example Struts Menu
Set your name in
UserPreferences
Referenced by
JSPWiki v2.2.33
Hide Menu |
This is version 12.
It is not the current version, and thus it cannot be edited. This is from a discussion on the struts-user mailing list. I'm continuing it here because I want to propose a new idea: Send your POJOs to the UI rather than converting them to ActionForms first. By this, I mean to say that I'd like to retrieve and display POJOs on the UI, and then capture their information (as ActionForms) when saving the form. The reason I want to do this is because of Hibernate's Lazy Loading feature and formatting Dates. Basically, Hibernate allows you to load children of an object lazily (i.e. resumes of a User), when the getResumes() method is called. The issue I'm seeing right now with lazily-loaded properties is that they're loaded when using BeanUtils.copyProperties() is called. I use this to convert POJOs to ActionForms, and consequently the getResumes() method is called. However, I don't want this. I'd rather the getResumes() method is called when I call it in my code (rather than by a 3rd party conversion utility). Therefore, I'm thinking that passing the POJO to the view is the best solution. Because I'm using the open-session-in-view pattern, those lazy collections are still available while the JSP is being rendered. This solves another issue too. It's nice to format dates on the UI, and you need a real date on your form to do this, rather than a String value of a date that's already been converted. One issue might be with checkboxes, but I can just use the Form for that, right? I haven't tried this yet, but I wanted to write my thoughts down and stir up some discussion on it beforehand. You might also be interested in my blog entry on the subject. Related Pages: Comments: I know it's not really useful to you, but WebWork gives you this natively. It's one of the big differences between WW and Struts, in that with WebWork you can make true model-driven actions, and then use them in your form. For example a form field called "pet/name" will call getPet() - your existing model POJO - and then setName() on it. Your action then just needs to store the updated POJO. Very neat. ~ mike cannon-brookes Matt, I have been actually meaning to ask you about this. I am trying to get a handle on how you are handling information passed down to the view. At this point in the game I am just passing my value object (are these supposed to be called DTOs now?) into my view. However, this brings me back to my first question to you. Consider the case where I want to display full name for a user. I would create a method getFullName() which would do a few tests to determine if the user has a first/middle/last name and then concat them together and split them out. I think, following your model, you would recommend putting this method in the UserForm object, but that would mean that I would have to transfer data from my user object into my UserForm object for use in the view. But then, would I still be able to get to the CompanyForm from the UserForm by using getCompany() in the UserForm? (nested forms). I am just trying to develop a standard here that I can use and I am floating around a bit.
|