I have a search box that appears on every page. The JSP code for the search box is inserted on each page through the tiles.
In the search box there is a form and class of actions SearchActionthat need to preload some properties for drop-down lists. The class SearchActionhas a method input()that performs this initialization.
Some pages also have their own form in the main area. Also with their own class of actions. They also have a method input()that does some preloading.
- Can I use two actions in the same view?
- How each form can have access to its properties of its actions.
- And how do I manage to call the input method of both classes of actions before displaying the JSP?
Update:
I am adding a shorthand example, since it is probably not entirely clear what I'm trying to do. This is the registration page register.jspwith RegisterAction. And the page also contains a search form. (BTW: I left getter / setter and other things in action classes to keep it short):
register.jsp:
<s:form action="executeSearch">
<s:textfield key="name" label="Name"/>
<s:textfield key="age" label="Age"/>
<s:submit/>
</s:form>
<s:form action="executeRegister">
<s:textfield key="firstName" label="First Name"/>
<s:textfield key="lastName" label="Last Name"/>
<s:textfield key="age" label="Age"/>
<s:submit/>
</s:form>
struts.xml:
<action name="*Search" class="action.SearchAction" method="{1}">
<result name="success">/searchresult.jsp</result>
</action>
<action name="*Register" class="action.RegisterAction" method="{1}">
<result name="input">/register.jsp</result>
<result name="success">/registerOk.jsp</result>
</action>
SearchAction.java:
public class SearchAction extends ActionSupport {
private String name;
private int age;
@Override
public String input() throws Exception {
name = "test";
age = 20;
return INPUT;
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
...
}
RegisterAction.java:
public class RegisterAction extends ActionSupport {
private String firstName;
private String lastName;
private int age;
@Override
public String input() throws Exception {
firstName = "John";
lastName = "Rambo";
age = 10;
return INPUT;
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
...
}
Let's say I call an action inputRegister.action. Then called RegisterAction.input(). Properties set. And the result SUCCESScauses the display of register.jsp.
. . , ValueStack. SearchAction, . age . , RegisterAction -properties ( ValueStack). SearchAction. 20, 10.

. , .