Wednesday, August 13, 2003

More quickies:

- A few times now I have struggled with the JSTL tags complaining that they can't find a property I'm trying to access in my Struts ActionForm. The <html:> tags find the property with no trouble, so I know it's there. The key was that I was using a DynaForm, where the properties are dynamically defined in the struts-config.xml file, and I had forgotten the ".map." that you need to access properties via JSTL. E.g.:

<c:out value="${}" >

If you leave out the .map., you'll get an exception complaining that there is "No such property in bean".

- The second thing I learned, was not to forget the scope attribute on your Struts action mappings. I had two action mappings, an initMyAction and myAction, both of which used the same form. I was submitting some initial values to the init form, but they weren't showing up in the JSP that the init form redirected to. And I could see in the debug logs that the <html:form> was causing a new instance of my form bean to be instatiated, when it should have already existed. I put debugging statements in the Action execute() method and I could see the value there, so I knew it was getting set. The problem was that I had left out the scope="request" from the <action> mapping for the initAction, but not from the myAction. So myAction was looking for the bean in the request scope and not finding it. (I'm assuming the default value for scope is "session").

No comments: