Thursday, July 31, 2003

I'm trying a new method for initializing a form. I still believe reset() is the best place to initialize form values, but for values that are needed in the JSP, but not for actually processing the form (contents of select boxes and other read only info), I think the Action is the best place to populate them. But how to avoid the problem I had earlier with validation? The answer is multiple mappings. So if I have an Action, EditUserAction, I might have two mappings as such:

<action
    path="/admin/initEditUser"
    type="com.company.action.EditUserAction"
    name="editUserForm"
    scope="request"
    parameter="dispatch"
    validate="false">
        <forward
name="initEditUser" path="/admin/editUser.jsp" redirect="false" />
</action>
   
<action
    path="/admin/editUser"
    type="com.company.action.EditUserAction"
    name="editUserForm"
    scope="request"
    validate="true"
    input="/admin/editUser.jsp"
    parameter="dispatch">
        <forward name="success"
path="/admin/index.html" redirect="false" />
        <forward
name="initEditUser" path="/admin/editUser.jsp" redirect="false" />
</action>

The first mapping has the correct form for the page, but with validate turned off. The second has it turned on. The first action would have a different dispatch than the second and would take care of initializing request attributes.


[BTW, is there a good way to just cut and paste XML into a blog? I.e. without having to escape all the tags?]

No comments: