Saturday April 14, 2007
Menu Items for Registering/Deregistering WebWork Actions
For the NBWebWorkSupport project, I need highly versatile menu items, for registering/deregistering Actions in the xwork.xml configuration file. They need to meet the following requirements:
- First, they need to appear on Java nodes, but only for projects that support WebWork. This requirement, and its solution, was discussed in Show/Hide Menu Items Based on Deployment Descriptor Content.
- Second, the menu item for deregistering a Java class's Actions needs to be enabled only when there are Actions to be deregistered. When there are no Actions registered for the current class, the menu item for deregistering them needs to be disabled.
For the second requirement, to understand it better, look at the screenshot below. In the xwork.xml file, there are no Actions for the selected class in the xwork.xml file. In other words, the class "Login" is selected, the right-click contextual menu appears, and shows the "Deregister from WebWork Actions" menu item is disabled. Why? Well, look in the xwork.xml file below... it shows there is one Action and the class attribute's value is "com.acme.action.HelloWorld":
Hence, there are no Actions registered for the Login class and, for that reason, the menu item is disabled. As soon as an Action is registered for the class, which is done using this (currently very rudimentary) dialog box...
...the menu item becomes enabled. Everything is done, on this point, based on the Action's "class" attribute in the Action's Action element. That required heavy use of regular expressions. When the menu item for deregistration of Actions is chosen (after I registered three Actions for the Login class), this dialog box is shown, just as a confirmation of the event that is about to happen:
Again, a lot of regular expressions were needed to get the Action names into the drop-down above. Right now, the code works exactly as it should. As soon as there are no more related Actions in the xwork.xml file, the deregistration menu item automatically disables. As soon as a Java class is registered, just once, the deregistration menu item enables automatically. Pretty cool. The code is in the project's CVS directory, if you're interested.
In other news. My colleague Troy completed the world's best, most detailed, and funniest MySQL tutorial for web applications in NetBeans IDE. Read Creating a Simple Web Application in NetBeans Using MySQL and laugh while you learn!
Apr 14 2007, 02:19:55 PM PDT Permalink


