Struts to solve actionform, action too many problems

Source: Internet
Author: User
Tags resource

1, solve the problem of too many action

Create an action that inherits from Dispatchaction by Dispatchaction This kind of action allows us to use a parameter in the form, to execute the action in different ways based on the parameters, and to implement the action in a multiple way.

Steps

① set up a inherited from dispatchaction action rule method name

② adds a hidden field value to the form page, assuming Codi value= "insert"

③ set the parameter parameter value to CODI in the action item in the corresponding form in Struts-config.xml

Then when the form is submitted, the Insert () method in the action is executed, changing the way the action is executed by altering the value in the hidden field

2, solve the problem of actionform too much

By means of dynamic actionform, i.e. Dynaactionform

Steps

① in Struts-config.xml

<form-beans>
<form-bean name=”abcForm” type=”org.apache.struts.action.DynaActionForm”>
<form-property name=”userid” type=”java.long.String”></form-property>
</form-bean>
</form-beans>

② in Struts-config.xml

Change the attribute and name in the appropriate action to Abcform

This will be configured with a dynamic actionform

3, solve the problem of dynamic actionform verification

By dynamically validating the actonform, i.e. Dynavalidatorform

Steps

① in Struts-config.xml

The first step with 2, but the type needs to be changed to Org.apache.struts.action.DynaValidatorForm

② Configure a Validation.xml file

<form-validation>
<formset>
<form name="abcForm">
<field property="userid" depends="required">
<arg key="err.userid" resource="true"/>
</field>
</form>
</formset>
</form-validation>

③ configures Err.userid, and errors.required in the Struts resource file

④ Configure the appropriate action in Struts-config.xml, add validate= "true" to add validation support

⑤ Add Struts plugin plugin, set plugin class to Org.apache.struts.validator.ValidatorPlugIn

Add Propertys

Property->pathnames

Value->/web-inf/validator-rules.xml,/web-inf/validation.xml

Such a validation framework is configured!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.