java - Struts 2 validation concept understanding -
i don't understand conception of struts2 validation in next case :
my application consists of 2 actions:
- login.action
- drive.action
i can run drive.action
browser command line without filling user , password in login.action
how can implement validation code prevents run of drive.action
command line if user hasn't filled user , password in login.action
?
the validation concept
struts 2 validation configured via xml or annotations. manual validation in action possible, , may combined xml , annotation-driven validation.
validation depends on both validation , workflow interceptors (both included in default interceptor stack). validation interceptor validation , creates list of field-specific errors. workflow interceptor checks presence of validation errors: if found, returns "input" result (by default), taking user form contained validation errors.
if we're using default settings , our action doesn't have "input" result defined , there validation (or, incidentally, type conversion) errors, we'll error message telling there's no "input" result defined action.
it simple, map validators fields via validation configuration file, or via annotations. apply validation
interceptor action via referencing explicitly or implicitly via interceptor stack, custom stack or defaultstack
.
when validation started invokes validation manager perform actual validation , save errors validationaware
action.
your action should implement interface, or extend actionsupport
it's implemented, save errors. workflow
interceptor checks errors , if found of them redirect input
result, if no errors found action invocation executed. may add programmatic validation action implementing validateable
interface, actionsupport
implemented default, hence override validate()
method(s).
as supplement xml based validation apply annotation based configuration. server-side validation, client-side validation applied browser enabled javascript via struts tags used rendering validation content page being validated.
all of concept not applicable action requires authentication (unless authentication interceptor applied action). if use jaas authentication, should consider action implement principalaware
or use roles
interceptor restrict access action checks isuserinrole()
. may use action.login
result return login page in authentication interceptor if user not authenticated in is there way redirect action class without using on struts.xml example.
Comments
Post a Comment