Now an expert is among us, i have to take the advantage to ask for his opinion about this. So Mr. Carnell (and others), please feel free to give your opinion...
We are just started with a new web application and it will be developed with the Jakarta
Struts Framework. One of our issues at this moment is the following: we have some beans (InfoA, InfoB, InfoC,...) that will be filled with info from a database. Each bean has some data members and methods (a1, getA1, setA1, a2, ...). Because each bean contains different information, we have for each bean a jsp-file (infoA.jsp, infoB.jsp, ...). We also have an info.jsp page containing a navigation-section (with a menu.jsp containing some links to infoA, infoB, infoC,...) and a body-section (must contain the right jsp-file after clicking on a link). Functionalities: reading and updating the bean-information.
Because i have the most experience with
JSF (and it is just my second JSF-project after a very small private website), I gave my collegue following advice:
make for each bean an ActionForm (FormA, FormB, FormC) and implement it as follows: class FormX extends ActionForm {
private InfoX info;
public FormX() { info = new InfoX(); }
public void setXXX(value) { info.setXXX(value); }
public datatype getXXX() { return info.getXXX(); }
public InfoX getInfoX() { return info; }
public void setInfoX(InfoX i) { info = new InfoX(i); }
}
in struts-config.xml - for each ActionForm:
<form-bean name="formX" type="be.test.FormX" />
- for each DispatchAction
<action path="/infoX" type="be.test.ActionX" name="formX" scope="request" validate="false" parameter="action" input="/jsp/info.jsp">
<forward name="SUCCESS" path="/jsp/info.jsp" />
<forward name="SUCCESS.SAVE" path="/jsp/save.jsp" />
</action>
- for each bean a global-forward
<forward name="INFO.X" path="/kaart.do?actie=initInfoX" redirect="false" />
make also for each ActionForm a DispatchAction and implement it as follows: class ActionX extends DispatchAction {
public ActionForward initInfoX(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
InfoX info = new InfoX();
// fill object with values from database
request.getSession().setAttribute("INFOX", info);
request.getSession().setAttribute("PAGE", "infoX.jsp");
return mapping.findForward("SUCCESS");
}
public ActionForward saveInfoX(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
FormX formX = (FormX)form;
InfoX info = new InfoX(formX.getInfoX());
// save values from object into database
return mapping.findForward("SUCCESS.SAVE");
}
}
the menu.jsp : for each jsp-page make a link: <html:link forward="initInfoX">See info x</html:link>
design each jsp-page as follows: <bean

efine id="info" name="INFOX" scope="session" />
<html:form action="/infoX">
<html:hidden name="action" value="saveInfoX" />
<html:text name="info" property="x1" />
<html:text name="info" property="x2" />
...
<html:submit>Save</html:submit>
</html:form>
I hope it is a little bit clear and understandable. Is this the way how to do it or where could it be made more effective.
All tips, hints, suggestions, pros and cons are welcome.