JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Web Framework » Struts  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 form 的validate可以依照不同情況作不同的validate嗎
shasun





發文: 118
積分: 0
於 2006-09-07 10:15 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在使用struts時是否有遇到相同的問題,
明明JSP畫面是同一個form,
但是卻必需依照使用者執行不同的action作不同欄位的validate,
像這種情形, 不同action使用同一個form卻要作不同的validate,
請問各位先進有什麼好方法?


reply to postreply to post
作者 Re:form 的validate可以依照不同情況作不同的validate嗎 [Re:shasun]
shasun





發文: 118
積分: 0
於 2006-09-25 11:18 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
對不起~~

想請教一下, 是不是我的發言不恰當?
還是我的問題不夠明確,

因為我還是新手, 不管是不是發言不恰當,
希望大家見諒也能給點意見, 呵呵~~

謝謝~~


reply to postreply to post
作者 Re:form 的validate可以依照不同情況作不同的validate嗎 [Re:shasun]
chihiro33





發文: 6
積分: 0
於 2006-09-25 11:55 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我在這樣的情況之下仍舊實作不同的from來處理
但你可以將getter & setter提至parent form
children form 繼承 parent form 個別覆寫 validate method就好


reply to postreply to post
作者 Re:form 的validate可以依照不同情況作不同的validate嗎 [Re:shasun]
shasun





發文: 118
積分: 0
於 2006-09-26 09:28 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝你的回答~~

但是不知道在struts的己知的版本中,
是否有讓validation.xml中的form可以有tiles-definitions中的definition
一樣可以有繼承的關係?

例如:

1
2
<form name="action1Form" extends="baseForm">
</form>


reply to postreply to post
作者 Re:form 的validate可以依照不同情況作不同的validate嗎 [Re:shasun]
brando





發文: 6
積分: 4
於 2006-10-27 20:24 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
ValidatorActionForm 可以解你的問題,請參
考下列連結

http://www.oracle.com/technology/oramag/oracle/04-jan/o14dev_struts.html

<擷取自上述連結之部分原文>
In addition to the two standard options for creating Form Beans, Validator provides an advanced feature for tying multiple validation definitions to one Form Bean definition. When you use validatorForm- or DynaValidatorForm-based Form Beans, Validator uses the logical name for the Form Bean from the struts-config.xml file to map the Form Bean to validation definitions in the validation.xml file. This mechanism is great in most cases, but in some scenarios, Form Beans are shared among multiple actions. One action may use all of the Form Bean's fields, and another action may use only a subset of the fields. Because validation definitions are tied to the Form Bean, the action that uses only a subset of the fields has no way of bypassing validations for the unused fields. When the Form Bean is validated, it generates error messages for the unused fields, because Validator has no way of knowing not to validate the unused fields; it simply sees them as missing or invalid.

To solve this problem, Validator provides two additional ActionForm subclasses that allow you to tie validations to actions instead of to Form Beans. That way you can specify which validations to apply to the Form Bean based on which action is using the Form Bean. For concrete Form Beans, you subclass org.apache.struts.validator.ValidatorActionForm


reply to postreply to post
» JWorld@TW »  Web Framework » Struts

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8