This content has been marked as final.
Show 4 replies
-
1. Re: Validate fileUpload
pmuir Jun 27, 2007 8:23 AM (in response to mustaghattack)fileUpload is a EditableValueHolder in 1.3.0.ALPHA and 2.0.BETA
-
2. Re: Validate fileUpload
mustaghattack Jun 27, 2007 8:48 AM (in response to mustaghattack)Cool !
Thx -
3. Re: Validate fileUpload
mustaghattack Sep 26, 2007 12:22 PM (in response to mustaghattack)Hello,
fileUpload is a EditableValueHolder true and validate all attach a modelvalidator to it.
But the file upload occur during the update model phase so the data is not validated.
Cheers,
Bruno -
4. Re: Validate fileUpload
mustaghattack Sep 27, 2007 7:59 AM (in response to mustaghattack)I've submitted a patch for UIFileUpload.
http://jira.jboss.com/jira/browse/JBSEAM-1981
With this patch you can use the hibernate validator framework.
For example I've done an Image annotation which check if a byte[] can be read by ImageIO.@ValidatorClass(ImageValidator.class) @Target({ElementType.FIELD, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface Image { String message() default "not a valid image"; }
public class ImageValidator implements Validator<Image> { public void initialize(Image parameters) { } public boolean isValid(Object value) { if( value == null ) return true; if( ! (value instanceof byte[]) ) return false; byte[] data = (byte[])value; try { BufferedImage img = ImageIO.read( new ByteArrayInputStream( data ) ); return img == null ? false : true; } catch (IOException e) { return false; } } }
So you can use it in your Entity@Entity public class AnEntity { @Lob @Image private byte[] data; ... }
In the Facelets :<s:fileUpload id="uplEditedImage" value="#{image.data}"/>
About my last post, I'm not quite right :) file upload occur during the apply request value phase but the submittedValue attribute wasn't set and the ModelValidator need a "value" attribute instead of "data".