Strutsã§ValidatorFormã使ãã¨Validatorãåããªãã¨ããç¾è±¡
ValidatorFormã使ã£ãå ´åãvalidation.xmlã®<form>ã®nameå±æ§ã«è¨è¿°ããå¤ã¯ãã¢ã¯ã·ã§ã³ãã©ã¼ã Beanã®è«çåï¼struts-config.xmlã®<form-bean>ã®nameå±æ§ï¼ã ValidatorActionFormã使ã£ãå ´åã¯ãstruts-config.xmlã®<action>ã¿ã°ã®pathå±æ§ãè¨è¿°ããã
ãããã£ãæãã§èªèãã¦ãã¾ãããããããã§ã ãã¶ãããã¾ãããValidatorActionFormã使ã£ãå ´åã¯åãã®ã ãã©ãValidatorFormã使ãã¨åããªãã¨ããç¾è±¡ã§ãã
æ¬ãè¦ã¦ãã°ã°ã£ã¦ãã ãããä¸è¨ã®ãããªæãã§æ¸ãã¦ããã®ã§æ°ã¥ãã«ããã£ãã®ã§ãããValidatorFormã使ãå ´åã¯ãå®éã«ã¯ã¢ã¯ã·ã§ã³ãã©ã¼ã Beanã®è«çåã§ã¯ãªãã¦ã<action>ã®attributeå±æ§ã®å¤ãæ¸ãããã§ãããã¡ããããã¯attributeå±æ§ãæ¸ããå ´åã ãã®è©±ã§ãã以ä¸ãã¢ã¯ã·ã§ã³ãã©ã¼ã Beanåã¯hogeFormã ãã©attributeå±æ§ã®å¤ã¯formã®å ´åã
<!-- struts-config.xml --> <struts-config> <form-beans> <form-bean name="hogeForm" type="samples.HogeForm"/> </form-beans> <action-mappings> <action path="/hoge" type="samples.HogeAction" input="/error.jsp" name="hogeForm" attribute="form" scope="request" validate="true"> <forward name="SUCCESS" path="/success.jsp"/> </action> </action-mappings> ï¼ </struts-config>
<!-- validation.xml --> <form-validation> <formset> <!-- nameå±æ§ã«ã¯ "hogeForm" ã§ã¯ãªã "form" ãæ¸ã--> <form name="form"> <field property="title" depends="required"> <arg key="error.hoge"/> </field> </form> </formset> </form-validation>
ã¤ã¾ãã¯ãvalidation.xmlã®<form>ã®nameå±æ§ã«ã¯ãã¢ã¯ã·ã§ã³ãã©ã¼ã Beanãä½ã¨ããå称ã§ã³ã³ããã¹ãã¸ç»é²ãããããæ¸ãã°ããã¨ããæå³ãªã®ãã¨æãã¾ãã
Struts1.2.8ï¼ã¨1.2.4ï¼ã§è©¦ãã¾ããããä»ã®ãã¼ã¸ã§ã³ï¼ç¹ã«1.1ç³»ï¼ã§ã¯è©¦ãã¦ããªãã®ã§1.2.8ã«éã£ã話ãªã®ãã©ããã¯ãããã¾ãããããããã¦åèã«ããæ¬ã1.1ç³»ãªã®ã§ãããã§ããªãä½ãééãã¦ããæãã¦ãã ããã