Pages

Friday, January 24, 2014

Any Struts 1 Experts Out There?

There are several JSPs that share some forms, but not others. The first of these, w_psi_s1_11.jsp (great name, what?) has access to offenderEmploymentForm. From this JSP, we call an action method OffenderEmployment.editEmployer. This action method transfers control to w_psi_s1_16.jsp (another great name), which has access to offenderEmploymentForm and employerSearchForm. The user hits the add button, which does a submit over to action method OffenderEmploymentAction.findEmployer. (Yes, the class is not the same as the other action method that I have already mentioned.) The findEmployer action method transfers control to w_psi_s1_14.jsp, where the user gets to add a new employer to the list. This JSP also has access to offenderEmploymentForm -- however, the action method that it calls on save, EmployerAction.save, does not have access to offenderEmploymentForm.

The problem is that when the submit on this last JSP happens, I need to update the employerId field in offenderEmploymentForm. I have the employerId visible in the JSP, but it does no good to pass it to the EmployerAction.save action method, because that class does not have access to the session form offenderEmploymentForm. I can read offenderEmploymentForm.employerId from the JSP -- but how do I write it from the JSP?

I have looked at a variety of methods around this. I thought that I could pass the offenderEmploymentForm using setAttribute in the JSP and getAttribute in the EmployerAction.save method -- but no, Struts 1 can't pass objects, and I really need to to update the existing session offenderEmploymentForm.

Our Struts expert is out sick, and I am running out of strings to Google to solve this.

UPDATE: I found a solution, but it was not very pretty.  I now understand how you switch from one action block to another.  The trick was to switch from the findEmployer action to the offenderEmployer action, invoking an action method in the offenderEmployer action.  Also, request.setParameter("employerId", the Form.getEmployerId()); in the action method from where I was forwarding, and request.getParameter("employerId") in the receiving action method.  Ugly.

2 comments:

  1. Not a Struts expert...or even a novice.

    Just a thought: I suspect those odd-looking file names are references to Spec/Design documents.

    PSI_Section1_Object11, or something like that. Whatever "PSI" stands for.

    ReplyDelete
  2. PSI stands for Pre-Sentence Investigation, and there are parts of the application that include this... but none of these screens have anything to do with that.

    ReplyDelete