| By Christian Landbo Frederiksen | Article Rating: |
|
| November 27, 2007 11:45 AM EST | Reads: |
10,770 |
JSF
JSF was chosen as the Web framework since it
has an extensive component model, where each HTML element needed is
represented by a Java object. It comes with built-in conversion and
validation and suits the project well.
Per XML element we want displayed we need a UIOutput object for the label and an UIInput object for the data.
Data Structure
We needed a data structure that
would wrap the SDO objects along with the needed JSF objects and found
the Composite design pattern useful (http://en.wikipedia.org/wiki/Composite_pattern).
Using this pattern we could store our own objects in a structure that
matches the SDO data graph. SDO containment properties (complex types)
went into the composites and SDO non-containment properties (simple
types) went into the leafs as illustrated in Figure 1.
Filling the Data Structure from XSD and XML
From the root data object obtained earlier we're going to construct the JSF components and fill the data structure.
Each property is extracted from the data object and handled recursively. The JSF components are generated, as we recursively traverse the structure, ending in the leafs (see Listing 2).
Now the data structure is filled with the SDO and JSF components - ready to be plugged into a GUI such as added to the child list of a panel:
private void setupXmlElement(XmlElement xmlElement) {
CompositeXmlElement comp = xmlElement.getCompositeXmlElement();
if (comp != null) {
for (XmlElement child : comp.getChildren()) {
setupXmlElement(child);
}
} else {
LeafXmlElement leaf = (LeafXmlElement) xmlElement;
if (leaf.getUiInput() != null && leaf.getUiInput().isRendered()) {
this.getPanel().getChildren().add(leaf.getLabel());
this.getPanel().getChildren().add(leaf.getUiInput());
}
}
}
This very simple example renders to this page (see Figure 2).
Because of the flexibility of JSF validation messages, such things as styles can be easily be added to each relevant component.
Submitting Data Back into the SDO Data Model
Submitting the form is easy. You just call submit on the XmlElement and
the composite pattern handles the rest by setting each value from the
UIInput in the leaf's submit method:
Object inputValue = this.uiInput.getValue();
String stringValue = inputValue.toString();
Object value = SDOUtil.createFromString(this.property.getType(), stringValue);
this.dataObject.set(property, value);
Conclusion
These were some of the basic operations
that made it possible for us to assemble a very generic system. Apache
Tuscany SDO turned out to be very flexible. Through its simple APIs it
was easy to work with schemas and data and easy to plug this into a
presentation framework. The final application contained a lot more than
exemplified here, since most schema constructs were supported, but
that's beyond the scope of this article. Supplying the application with
a Web Service interface was also easy since the SDOs could be used to
both import and generate XML directly as shown above.
Apache Tuscany also covers SCA and DAS but that's a whole different article.
Published November 27, 2007 Reads 10,770
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Christian Landbo Frederiksen
Christian Landbo Frederiksen is a senior consultant in Ementor Denmark and has worked with Java and J2EE since 2000. He holds an M.Sc. in IT from the IT University of Copenhagen and a B.Sc. in computer science from the University of Copenhagen. He is a SCJP, SCJD and SCWCD.
![]() |
Christian Schuhegger 05/25/08 03:25:53 PM EDT | |||
is the source code for this article available? |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?







































