D
Daniel
Hi,
I'm trying to understand the workflow in struts, and have some
difficulties. I want to load a form and submit it. Then I want to go
to one of several pages (which are also part of the form).
In the form I have some data that needs to be loaded in selects and
multiple checkboxes. To do this, it seems I should use beans.
First question, how do I define this in the struts-config.xml?
I'm using tiles, so in the tiles-config it looks like this:
<definition name=".testForm" extends=".main.layout">
<put name="left" value="/pages/left.jsp" />
<put name="body" value="/pages/test.jsp" />
</definition>
In the struts-config.xml:
<forward
name="testForm"
path="/testForm.do"/>
....
<action
path="/testForm"
forward=".testForm"/>
Where do I add the beans I need. And where do I load the data into
them?
If I add an action type, how do I forward it?
<action
path="/testForm"
type="test.TestAction"
forward=".testForm"/>
In the test action class I can load the data into beans, I suppose;
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
HashMap items = getItems();
//request.setAttribute("items", items);
//servlet.getServletContext().setAttribute("items", items);
HttpSession session = request.getSession();
session.setAttribute("items", items);
return mapping.findForward("testForm");
}
I could connect to the database and populate a HashMap in the getItems
method.
But what about the findForward? Doesn't that lead back to the very
same action - like an iternal loop?
If so, do I need to create a new action, that forwards to this one?
<action
path="/testForm"
type="test.TestAction"
forward=".testForm"/>
...
<action
path="/testForm2"
forward=".testForm2"/>
...
return mapping.findForward("testForm2");
I guess there is no use to continue before I got these things sorted
out.
Thanks in advance for your help!
I'm trying to understand the workflow in struts, and have some
difficulties. I want to load a form and submit it. Then I want to go
to one of several pages (which are also part of the form).
In the form I have some data that needs to be loaded in selects and
multiple checkboxes. To do this, it seems I should use beans.
First question, how do I define this in the struts-config.xml?
I'm using tiles, so in the tiles-config it looks like this:
<definition name=".testForm" extends=".main.layout">
<put name="left" value="/pages/left.jsp" />
<put name="body" value="/pages/test.jsp" />
</definition>
In the struts-config.xml:
<forward
name="testForm"
path="/testForm.do"/>
....
<action
path="/testForm"
forward=".testForm"/>
Where do I add the beans I need. And where do I load the data into
them?
If I add an action type, how do I forward it?
<action
path="/testForm"
type="test.TestAction"
forward=".testForm"/>
In the test action class I can load the data into beans, I suppose;
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
HashMap items = getItems();
//request.setAttribute("items", items);
//servlet.getServletContext().setAttribute("items", items);
HttpSession session = request.getSession();
session.setAttribute("items", items);
return mapping.findForward("testForm");
}
I could connect to the database and populate a HashMap in the getItems
method.
But what about the findForward? Doesn't that lead back to the very
same action - like an iternal loop?
If so, do I need to create a new action, that forwards to this one?
<action
path="/testForm"
type="test.TestAction"
forward=".testForm"/>
...
<action
path="/testForm2"
forward=".testForm2"/>
...
return mapping.findForward("testForm2");
I guess there is no use to continue before I got these things sorted
out.
Thanks in advance for your help!