Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
DTOInForm
StrutsResumeSupport




JSPWiki v2.2.33

[RSS]


Hide Menu

POJOsToForms


Difference between current version and version 22:

At line 3 changed 1 line.
__Send your POJOs to the UI rather than converting them to ActionForms first.__
__Send your [POJO]s to the UI rather than converting them to ActionForms first.__
At line 30 changed 56 lines.
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.
~ [mojavelinux]
----
I'm beginning to think this is best done as it currently is in [AppFuse], where all objects are translated to Action Forms (even nested lists of objects). The reason? Because then my view is not tied to my model. If I start using POJOs in my view, then I'm tightly coupling my model to my view. And besides, since I've already done it this way - there's really no more work to be done. I have a DateConverter that's not in AppFuse that might be useful for converting dates (it's pretty simple really). Here's an example:
{{{
public class DateConverter implements Converter {
//~ Instance fields ========================================================
protected Log log = LogFactory.getLog(ListConverter.class);
//~ Methods ================================================================
/**
* Convert a String to a Date
*
* @param type the class type to output
* @param value the object to convert
*/
public Object convert(Class type, Object value) {
log.debug("entered 'convert' method...");
// for a null value, return null
if (value == null) {
return null;
} else {
if (value instanceof String) {
log.debug("value (" + value + ") instance of String");
try {
if (StringUtils.isEmpty(value.toString())) {
return null;
}
return DateUtil.convertStringToDate(value.toString());
} catch (ParseException pe) {
pe.printStackTrace();
}
} else if (value instanceof Date) {
log.debug("value (" + value + ") instance of Date");
return DateUtil.convertDateToString((Date) value);
}
}
throw new ConversionException("Could not convert "
+ value.getClass().getName() + " to "
+ type.getName() + "!");
}
}
}}}
Of course, the DateUtil class would help too, but this will give you a simple idea of how to do date conversions. Just register this class in BaseManager.java.
~ [MattRaible]
For example a form field called

Back to POJOsToForms, or to the Page History.