Geertjan's Blog

  • April 18, 2007

xwork.xml in MultiView Editor

Geertjan Wielenga
Product Manager
A simplistic start to creating a multiview editor for the xwork.xml file:

Most of it works, but there are several bugs to fix. An editor such as this only makes sense when (a) all elements/attributes are exposed and (b) no bugs remain. So those are the two things I'm striving for.

Want to create a multiview editor for an XML file too? The principles of getting started are easy. Here are some resources:

  • NetBeans: schema2beans library - User Documentation
  • Toni Epple's blog has some really good resources about getting started with Schema2Beans. His blog is here. He and Vadiraj, who has been very helpful to me over the past few days, are thinking of writing a wizard that will generate all the beans via Schema2Beans, as well as some basic implementation classes from the XML MultiView API. That would be really brilliant to have. Anyone out there want to help them? You can get in touch with them via their blogs.

Writing a multiview editor for XML files is not exactly easy, but it could also be a lot harder than it is. There's a lot to become comfortable with. The most obvious question is: "Where do I start?" Well, you start by generating Java classes from the Schema or DTD to which the XML file conforms. So, you are not really writing a multiview editor for an XML file. You are writing it for a Schema or DTD file. Using the Schema2Beans JAR provided by NetBeans, here, you can use either Java code or Ant scripts to generate your Java classes. These Java classes form the basis of your implementation of the XML Multiview API. In other words, they are the model of your application.

Once you have these classes, of which there could be about 10 (in fact, one class per element in the Schema or DTD), put them in your module. Then go to your DataObject and change its extension class from whatever it is to XmlMultiViewDataObject. This means you'll have to create a dependency on the XML MultiView API. After that, you will have to implement many many many methods, over several classes. The best way to go about this, in my humble opinion, is to (a) get the BookMultiView Sample from my update center (or get it from Vadiraj, because he has fixed an annoying bug in the module) and (b) read these of Vadiraj's blog entries extremely carefully. They introduce you to the sample, as well as to the API as a whole. They're excellent and describe the whole picture on a very technical yet readable level:

With all of the above resources, you'll be off to an excellent start. My own approach is to gradually merge the BookMultiView Sample with my own scenario, bit by bit and piece by piece. What is also helpful is that if you go here in the NetBeans sources...


...you will find several other multiview editors, such as the editor used by the web.xml file. You can open the forms in the IDE and then... you can let them "inspire" you. Or just do what I did and copy whatever makes sense to your own scenario.

Join the discussion

Comments ( 4 )
  • Peter Williams Wednesday, April 18, 2007
    Could you clarify what the annoying bug in the BookMultiView sample is? I scanned Vadiraj's blog, but saw no obvious reference to the bug.
  • Geertjan Thursday, April 19, 2007
    Hi Peter. In the first of Vadiraj's 3 part series, search for the line "In the original book example, there are two errors:". And then the two errors are mentioned.
  • Otavio Biasutti Saturday, July 16, 2011

    I know this article is a bit old, but I'm finding kinda hard to implement a multiview functionality for my application. At this moment I have the XML file in the disk and it generates the a view, which is contained in a JPanel. However, I would like to have a multiview editor with both, the xml editor view and this my own view. Same as traditional, the user select it from a tool bar from the editor's pane. The other documents I read from you are using SectionPanels, and I don't think I need that, right??

    Any help will be appreciated. Thanks in advance!

  • Geertjan Saturday, July 16, 2011
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.