More PMD custom rules 1
I still love PMD. Last week, I was doing some formhandler stuff, and realized that there were two bugs I fell for, hook line and sinker.
Compare and contrast:
String msg = getUserMessage(USER_NOT_FOUND, profile, pRequest); addFormException(new DropletFormException(msg, USER_NOT_FOUND);
with
String msg = getUserMessage(USER_NOT_FOUND, profile, pRequest); addFormException(new DropletException(msg, USER_NOT_FOUND));
The first example is incorrect. DropletFormException takes in a property path as the second argument, so that the designer can mark the property as failed (i.e. by making the login form field red). In the three argument form, it’s the third argument that is the message key, so that i18n can be done on the actual page using droplets, so the designer can override a message key for a specific page.
(Which means that even
addFormException(new DropletFormException(msg, getAbsoluteName(), USER_NOT_FOUND);
is wrong. The second argument needs to be getAbsoluteName() + “.login”, to include the property.)
Of course, once I realized what I’d done, I realized how horrible it would be to find and fix all of these. Worse, I’d have to review the code to make sure this kind of error wouldn’t creep in again.
Using PMD and XPath Explorer, I can flag the two argument form of DropletFormException with an XPath expression:
//Name[@Image="DropletFormException" and count(following-sibling::Arguments/ArgumentList/Expression) = 2]
And suddenly everything becomes clear. I can include these in the custom rules for the project and I will never have to think about this again. Thank you PMD.
I have a very basic, beginner’s question regarding ATG Dynamo formhandlers - however it is not a coding problem but rather a problem related to the actual Dynamo server itself - I would appreciate any feedback which you may be able to provide. I am wondering how you actually create a form handler component from a form handler java class (i.e,. MyFormHandler.java) which you have already compiled. When I go to ATG Control Center, click on “Component by Path”, click on “New Component”, and then try to create a Generic Component, I can not create a component for the form handler class (the error “can’t find class atg.droplet.GenericFormHandler” appears) - I know that I must be creating this form handler component in the wrong place/directory in the Control Center, but I do not know where to create it otherwise. If you would be able to provide any instructions on this matter, however brief, I would appreciate it very much. Thank you.