Accessing nested Item properties within a RepositoryFormHandler programatically

If you have a RepositoryItem which has a collection of other RepositoryItems as a property, editing things on them via a single form and RepositoryFormHandler can pose some difficulties.

For instance, you have an Item called Garage, and it has a List of Car RepositoryItems as a property named cars. If you are using a different type of collection, some of the following will need to be adjusted accordingly, but the overall approach is the same. A Car Item has a name and an option picture as properties. If you have a form to display and allow for editing of a Garage, including all of its cars, which is handled by a sub-class of a RepositoryFormHandler, you can edit values on both the Garage, as well as the Cars within cars, without much difficulty.

What gets tricky is if you need to access form submission values for properties on the Cars. For instance if you wanted to allow a user to delete a car by simply blanking it’s name, or if you wanted to automatically assign a picture based on the make and model in the name field. You can’t just access the submitted but un-updated values (say from within the preUpdateItem method) using simple nested getValueProperties. Here is what you can do:

Continue reading

ItemToXMLDroplet

This is an extremely simple Droplet with source, a config file, and a sample JSP. All the droplet does it transform a passed-in RepositoryItem into XML and dump it out. It would be handy for vending data to client-side logic in JavaScript or Flash, when you don’t want to write-up a full WebService.

You can download it all here.

The example JSP takes in a query parameter userId and generates the XML for the user profile with that id. For instance, if you call:

http://alita.local:8840/test/test.jsp?userId=930003

you get this……

Continue reading