Hopefully this won't sound too confusing. I'm leaving out a few details to
try to get right to the heart of the issue...(Struts 1.3)

I have an ActionForm that has a DynaBean that holds "answers." Imagine a
case where you have various surveys (templates) at different points in time
thus the questions and answers can vary at different times. (For simplicity
right now just ignore the questions.) The answers in this dynaBean will be
set up before going to the jsp... ultimately looking like...

answers.set("question_1","pizza"); //answer to a favorite food question
answers.set("question_2", colorsArray ); //a String[] of favorite colors

Notice that the answer to question 2 is a String[] which creates part of the
problem, since in the reset method this property needs to be set with an
empty array, otherwise when the form submits it will only submit one of the
answers if you had multiple checkboxes.

Since I'm not using a totally dynamic approach to my questionnaire stuff,
there exists a templateXYZ.jsp to match the questions and there is also a
TemplateXYZ class which holds my validation rules, a setup method, and was
going to hold a reset(ActionForm) method. Since this reset method could
reside in "TemplateXYZ" class it knows exactly what answers in the DynaBean
it should set to String[] arrays.

The problem is "In the ActionForm reset method I somehow need a handle to
what type of template I'm dealing with so I can pass the form instance to
the correct TemplateXYZ class to do the proper reset." The only way I can
think to do this is to temporarily store the 'template name' in Session
scope, which means in the ActionForm reset I can do:

reset(...) {
    String templateName =
(String)request.getSession().getAttribute("templateName");
    TemplateInterface template = SomeHelper.getCorrectInstance( templateName
);
    template.reset( this );
}

This way the correct Template type is found (TemplateXYZ ) and its reset is
called.

Is there a way to handle what I want to do without using Session scope for
the templateName? Or maybe a totally different approach all together is in
order?

Thanks for any help.

-- 
Rick

Reply via email to