There is no problem when the action configuration in struts.xml is like this:
<action name="customer-form">
<result name="success" type="tiles">/customer.tiles</result>
</action>
The problem comes when I access the action class on action configuration (struts.xml). I access the class before displaying the form because I want the dropdown option in the form to display the appropriate value as I instantiate it in action class. But it turns out, it will return "input" and I must handle it.
method in action class:
public String addCusto(){
custoType = new ArrayList<String>();
custoType.add("ABC");
custoType.add("EFG");
System.out.println(custoType.size());
return SUCCESS;
}
struts.xml:
<action name="customer-form" class="com.satunol.struts.template.action.CustomerAction" method="addCusto">
<result name="success" type="tiles">/customer.tiles</result>
<result name="input" type="tiles">/customer.tiles</result>
</action>
form in jsp
<s:form action="savecusto" method="post" validate="true">
<s:select
label="Customer Type"
list="custoType"
emptyOption="true"
headerKey="-1"
headerValue="None"/>
<s:textfield name="custo.name" key="custo.name" size="20" />
<s:textfield name="custo.email" key="email" size="20" />
<s:textfield name="custo.address" key="address" size="20" />
<s:textfield name="custo.phone" key="phone" size="20" />
<s:submit method="addCustomer" key="label.add.customer" align="center" />
The result? The addCusto
method is not executed, and my form is directly/automatically validated although not yet submitted.
How can I solve this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…