I have to write custom validation method where I iterate all "PageText" class
and validate it.
I want to use validate() method from ActionSupport class but the method is
invoke always.
I need invoke validator method only when is invoke method save();
Is better resolution?

public String save() throws Exception{              
        if (!isValid())
            return INPUT;
        
        pageService.update(page);
        return execute();
    }


 private boolean isValid(){               
        boolean success = true;
        for (Map.Entry<LanguageName, PageText> e :
page.getTexts().entrySet()){
            if (e.getValue().getDescription().length() < 6 ){               
                addFieldError(getComponentName(e.getValue(), "description"),
getText("validation.page.texts.description")); 
                success = false;        
            }
        }          
        return success; //==========>
    }






Kibo wrote:
> 
> Hi konference
> 
> How can I validate classes which are associated in collection.
> The class "Page" contents Map with "PageText" classes:
> 
> Page.java
> ------------------
> private Map<LanguageName, PageText> texts = new HashMap();
> 
>  ... getter / setter
> 
> PageText.java
> --------------------------
> private String description;
> 
> @StringLengthFieldValidator(message="Length too short",
> key="validate.minLength.6", trim=true, mimLength = "6")
>     public void setDescription(String description) {
>         this.description = description;
>     }
> 
> Action.java
> -------------------
> private Page page; 
> 
> //it work but I need validate all classes in Map, not only ['en']
>  @Validations( visitorFields = {
>         @VisitorFieldValidator(
>                 message = "Default message", key = "i18n.key",
>                 fieldName= "page.texts['en']", appendPrefix = false) } 
>     )
>     public String execute() throws Exception{                                 
>             
>         return Action.SUCCESS;
>     }
> 
> ------------------------
> 
> When I set: fieldName= "page.texts['en']" it work, but in Map are a lots
> of classes.
> I need validate all class in collection.
> When I set only: fieldName= "page.texts" it dont work.
> I need set something of : fieldName= "page.texts[*]" but it dont work.
> 
> How can I determine in attribute fieldName as to validate all classes in
> "page.texts" ?
> Is it possible or I must resolve it otherwise?
> 
> Thanks a lot
> 
> 


-----
Tomas Jurman
Czech Republic
-- 
View this message in context: 
http://www.nabble.com/Validate-associate-Map-tp19010237p19011738.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to