You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "Ing.Thomas Kernstock" <t....@e-technologies.at> on 2011/09/08 21:28:39 UTC

Bean Validation

Hi Group !

I have a weird problem with bean validation in JSF and hope someone can help
me. 

I have a JEE6 project using JPA2, JSF2, MyFaces CODI 1.0 and MyFaces Extval
2.0.5 (bean, core and property module).

I have an entity with a field ->


@Entity
@Table(name="bewerbungen")
public class Bewerbung extends BaseEntityVersioned implements Serializable {
.....
	@Lob
	@Column(name="Bemerkung")
	private String bemerkung;
.....
}

a Form with h:inputTextarea that writes directly to the entity ->

<h:outputLabel for="bemerkung" value="#{msgs.bewerben_bemerkungen}" />
<h:inputTextarea id="bemerkung"
value="#{applyForJobPage.bewerbung.bemerkung}" rows="12" cols="75"
label="#{msgs.bewerben_bemerkungen}"  />

and a view bean->

@Named
@ViewAccessScoped
public class ApplyForJobPage extends AbstractProfilePage{

	private Bewerbung bewerbung;

... getter and setter ...
}


There are no validations defined but when I copy a text longer than 255
character into the text field I get a validation Error ! (=> Anschreiben:
Überprüfungsfehler: Wert ist größer als der zulässige Maximalwert "255")

I also tried to change the code to:

 <h:inputTextarea id="bemerkung"
value="#{applyForJobPage.bewerbung.bemerkung}" rows="12" cols="75"
label="#{msgs.bewerben_bemerkungen}" >
<f:validateLength maximum="512" />
</h:inputTextarea>

and

@Lob
@Size(max=512)
@Column(name="Bemerkung")
private String bemerkung; 

Both didn't work. The only thing that works would be to define a string in
the view bean and move this string into the entity later. 

I couldn't find any hints in the internet about a default length of 255
characters. 

Any ideas ?

best regards

Thomas




Re: AW: Bean Validation

Posted by Mark Struberg <st...@yahoo.de>.
Btw, slightly OT:

it is always a good idea to explicitly set the column size. There are a few arguments for it:

Why waste space for e.g. an internal shortcut which is defined to be 20 chars wide in the gui?

By default a database page is still only 8kB (or even 4kB sometimes) in most database setups. In the Java/UTF world this means 4000 resp 2000 chars in 1 page!
If you have large objects, then you'll quickly exceed this size, thus slowing down your database.

Another bummer: In most databases, a combined unique index (by default) must not exceed 1kB (500chars). Thus you cannot even combine 2 columns of that kind to an unique index ;)

LieGrue,
strub



----- Original Message -----
> From: Ing.Thomas Kernstock <t....@e-technologies.at>
> To: 'MyFaces Discussion' <us...@myfaces.apache.org>; 'Mark Struberg' <st...@yahoo.de>
> Cc: 
> Sent: Friday, September 9, 2011 11:22 AM
> Subject: AW: Bean Validation
> 
> hi mark,
> 
> thanx for the clarification !
> 
> best regards
> Thomas
> 
> -----Ursprüngliche Nachricht-----
> Von: Mark Struberg [mailto:struberg@yahoo.de] 
> Gesendet: Freitag, 09. September 2011 10:42
> An: MyFaces Discussion
> Betreff: Re: Bean Validation
> 
> Yup, Gerhard is right.
> 
> The reason is that JPA defines String fields as VARCHAR(255) by default.
> Strings of larger size will be stored in CLOBs which have completely
> different indexing, etc.
> 
> LieGrue,
> strub
> 
> 
> 
> ----- Original Message -----
>>  From: Gerhard Petracek <ge...@gmail.com>
>>  To: MyFaces Discussion <us...@myfaces.apache.org>
>>  Cc: 
>>  Sent: Thursday, September 8, 2011 9:34 PM
>>  Subject: Re: Bean Validation
>> 
>>  hi thomas,
>> 
>>  length of @Column should help. e.g. @Column(length = 512)
>> 
>>  regards,
>>  gerhard
>> 
>>  http://www.irian.at
>> 
>>  Your JSF powerhouse -
>>  JSF Consulting, Development and
>>  Courses in English and German
>> 
>>  Professional Support for Apache MyFaces
>> 
>> 
>> 
>>  2011/9/8 Ing.Thomas Kernstock <t....@e-technologies.at>
>> 
>>>   Hi Group !
>>> 
>>>   I have a weird problem with bean validation in JSF and hope someone 
>>>  can  help  me.
>>> 
>>>   I have a JEE6 project using JPA2, JSF2, MyFaces CODI 1.0 and MyFaces 
>>>  Extval
>>>   2.0.5 (bean, core and property module).
>>> 
>>>   I have an entity with a field ->
>>> 
>>> 
>>>   @Entity
>>>   @Table(name="bewerbungen")
>>>   public class Bewerbung extends BaseEntityVersioned implements 
>>>  Serializable  {  .....
>>>          @Lob
>>>          @Column(name="Bemerkung")
>>>          private String bemerkung;
>>>   .....
>>>   }
>>> 
>>>   a Form with h:inputTextarea that writes directly to the entity ->
>>> 
>>>   <h:outputLabel for="bemerkung" 
>>  value="#{msgs.bewerben_bemerkungen}" />
>>>   <h:inputTextarea id="bemerkung"
>>>   value="#{applyForJobPage.bewerbung.bemerkung}" 
>>  rows="12" cols="75"
>>>   label="#{msgs.bewerben_bemerkungen}"  />
>>> 
>>>   and a view bean->
>>> 
>>>   @Named
>>>   @ViewAccessScoped
>>>   public class ApplyForJobPage extends AbstractProfilePage{
>>> 
>>>          private Bewerbung bewerbung;
>>> 
>>>   ... getter and setter ...
>>>   }
>>> 
>>> 
>>>   There are no validations defined but when I copy a text longer than 
>>>  255  character into the text field I get a validation Error ! (=>
>>  Anschreiben:
>>>   Überprüfungsfehler: Wert ist größer als der zulässige Maximalwert
>>  "255")
>>> 
>>>   I also tried to change the code to:
>>> 
>>>    <h:inputTextarea id="bemerkung"
>>>   value="#{applyForJobPage.bewerbung.bemerkung}" 
>>  rows="12" cols="75"
>>>   label="#{msgs.bewerben_bemerkungen}" >  
> <f:validateLength 
>>>  maximum="512" />  </h:inputTextarea>
>>> 
>>>   and
>>> 
>>>   @Lob
>>>   @Size(max=512)
>>>   @Column(name="Bemerkung")
>>>   private String bemerkung;
>>> 
>>>   Both didn't work. The only thing that works would be to define a 
>>>  string
>>  in
>>>   the view bean and move this string into the entity later.
>>> 
>>>   I couldn't find any hints in the internet about a default length 
> of 
>>>  255  characters.
>>> 
>>>   Any ideas ?
>>> 
>>>   best regards
>>> 
>>>   Thomas
>>> 
>>> 
>>> 
>>> 
>> 
>

AW: Bean Validation

Posted by "Ing.Thomas Kernstock" <t....@e-technologies.at>.
hi mark,

thanx for the clarification !

best regards
Thomas

-----Ursprüngliche Nachricht-----
Von: Mark Struberg [mailto:struberg@yahoo.de] 
Gesendet: Freitag, 09. September 2011 10:42
An: MyFaces Discussion
Betreff: Re: Bean Validation

Yup, Gerhard is right.

The reason is that JPA defines String fields as VARCHAR(255) by default.
Strings of larger size will be stored in CLOBs which have completely
different indexing, etc.

LieGrue,
strub



----- Original Message -----
> From: Gerhard Petracek <ge...@gmail.com>
> To: MyFaces Discussion <us...@myfaces.apache.org>
> Cc: 
> Sent: Thursday, September 8, 2011 9:34 PM
> Subject: Re: Bean Validation
> 
> hi thomas,
> 
> length of @Column should help. e.g. @Column(length = 512)
> 
> regards,
> gerhard
> 
> http://www.irian.at
> 
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
> 
> Professional Support for Apache MyFaces
> 
> 
> 
> 2011/9/8 Ing.Thomas Kernstock <t....@e-technologies.at>
> 
>>  Hi Group !
>> 
>>  I have a weird problem with bean validation in JSF and hope someone 
>> can  help  me.
>> 
>>  I have a JEE6 project using JPA2, JSF2, MyFaces CODI 1.0 and MyFaces 
>> Extval
>>  2.0.5 (bean, core and property module).
>> 
>>  I have an entity with a field ->
>> 
>> 
>>  @Entity
>>  @Table(name="bewerbungen")
>>  public class Bewerbung extends BaseEntityVersioned implements 
>> Serializable  {  .....
>>         @Lob
>>         @Column(name="Bemerkung")
>>         private String bemerkung;
>>  .....
>>  }
>> 
>>  a Form with h:inputTextarea that writes directly to the entity ->
>> 
>>  <h:outputLabel for="bemerkung" 
> value="#{msgs.bewerben_bemerkungen}" />
>>  <h:inputTextarea id="bemerkung"
>>  value="#{applyForJobPage.bewerbung.bemerkung}" 
> rows="12" cols="75"
>>  label="#{msgs.bewerben_bemerkungen}"  />
>> 
>>  and a view bean->
>> 
>>  @Named
>>  @ViewAccessScoped
>>  public class ApplyForJobPage extends AbstractProfilePage{
>> 
>>         private Bewerbung bewerbung;
>> 
>>  ... getter and setter ...
>>  }
>> 
>> 
>>  There are no validations defined but when I copy a text longer than 
>> 255  character into the text field I get a validation Error ! (=>
> Anschreiben:
>>  Überprüfungsfehler: Wert ist größer als der zulässige Maximalwert
> "255")
>> 
>>  I also tried to change the code to:
>> 
>>   <h:inputTextarea id="bemerkung"
>>  value="#{applyForJobPage.bewerbung.bemerkung}" 
> rows="12" cols="75"
>>  label="#{msgs.bewerben_bemerkungen}" >  <f:validateLength 
>> maximum="512" />  </h:inputTextarea>
>> 
>>  and
>> 
>>  @Lob
>>  @Size(max=512)
>>  @Column(name="Bemerkung")
>>  private String bemerkung;
>> 
>>  Both didn't work. The only thing that works would be to define a 
>> string
> in
>>  the view bean and move this string into the entity later.
>> 
>>  I couldn't find any hints in the internet about a default length of 
>> 255  characters.
>> 
>>  Any ideas ?
>> 
>>  best regards
>> 
>>  Thomas
>> 
>> 
>> 
>> 
>



Re: Bean Validation

Posted by Mark Struberg <st...@yahoo.de>.
Yup, Gerhard is right.

The reason is that JPA defines String fields as VARCHAR(255) by default.
Strings of larger size will be stored in CLOBs which have completely different indexing, etc.

LieGrue,
strub



----- Original Message -----
> From: Gerhard Petracek <ge...@gmail.com>
> To: MyFaces Discussion <us...@myfaces.apache.org>
> Cc: 
> Sent: Thursday, September 8, 2011 9:34 PM
> Subject: Re: Bean Validation
> 
> hi thomas,
> 
> length of @Column should help. e.g. @Column(length = 512)
> 
> regards,
> gerhard
> 
> http://www.irian.at
> 
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
> 
> Professional Support for Apache MyFaces
> 
> 
> 
> 2011/9/8 Ing.Thomas Kernstock <t....@e-technologies.at>
> 
>>  Hi Group !
>> 
>>  I have a weird problem with bean validation in JSF and hope someone can
>>  help
>>  me.
>> 
>>  I have a JEE6 project using JPA2, JSF2, MyFaces CODI 1.0 and MyFaces Extval
>>  2.0.5 (bean, core and property module).
>> 
>>  I have an entity with a field ->
>> 
>> 
>>  @Entity
>>  @Table(name="bewerbungen")
>>  public class Bewerbung extends BaseEntityVersioned implements Serializable
>>  {
>>  .....
>>         @Lob
>>         @Column(name="Bemerkung")
>>         private String bemerkung;
>>  .....
>>  }
>> 
>>  a Form with h:inputTextarea that writes directly to the entity ->
>> 
>>  <h:outputLabel for="bemerkung" 
> value="#{msgs.bewerben_bemerkungen}" />
>>  <h:inputTextarea id="bemerkung"
>>  value="#{applyForJobPage.bewerbung.bemerkung}" 
> rows="12" cols="75"
>>  label="#{msgs.bewerben_bemerkungen}"  />
>> 
>>  and a view bean->
>> 
>>  @Named
>>  @ViewAccessScoped
>>  public class ApplyForJobPage extends AbstractProfilePage{
>> 
>>         private Bewerbung bewerbung;
>> 
>>  ... getter and setter ...
>>  }
>> 
>> 
>>  There are no validations defined but when I copy a text longer than 255
>>  character into the text field I get a validation Error ! (=> 
> Anschreiben:
>>  Überprüfungsfehler: Wert ist größer als der zulässige Maximalwert 
> "255")
>> 
>>  I also tried to change the code to:
>> 
>>   <h:inputTextarea id="bemerkung"
>>  value="#{applyForJobPage.bewerbung.bemerkung}" 
> rows="12" cols="75"
>>  label="#{msgs.bewerben_bemerkungen}" >
>>  <f:validateLength maximum="512" />
>>  </h:inputTextarea>
>> 
>>  and
>> 
>>  @Lob
>>  @Size(max=512)
>>  @Column(name="Bemerkung")
>>  private String bemerkung;
>> 
>>  Both didn't work. The only thing that works would be to define a string 
> in
>>  the view bean and move this string into the entity later.
>> 
>>  I couldn't find any hints in the internet about a default length of 255
>>  characters.
>> 
>>  Any ideas ?
>> 
>>  best regards
>> 
>>  Thomas
>> 
>> 
>> 
>> 
>

Re: Bean Validation

Posted by Gerhard Petracek <ge...@gmail.com>.
you are welcome! (see [1])

regards,
gerhard

[1]
https://cwiki.apache.org/confluence/display/EXTVAL/Property+Validation+Usage#PropertyValidationUsage-JPAbasedvalidation

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces



2011/9/8 Ing.Thomas Kernstock <t....@e-technologies.at>

> hi gerhard,
>
> once again you saved my day (or better night in this case :-)) !  thanx a
> lot.
>
> Just for my curiosity -> I couldn't find any hint on the internet that a
> @Lob will be validated with a length of 255 by default. Do you know if this
> is an extval "feature" or if it is defined elsewhere ?
>
> best regards
> Thomas
>
>
> -----Ursprüngliche Nachricht-----
> Von: Gerhard Petracek [mailto:gerhard.petracek@gmail.com]
> Gesendet: Donnerstag, 08. September 2011 21:34
> An: MyFaces Discussion
> Betreff: Re: Bean Validation
>
> hi thomas,
>
> length of @Column should help. e.g. @Column(length = 512)
>
> regards,
> gerhard
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>
>
>
> 2011/9/8 Ing.Thomas Kernstock <t....@e-technologies.at>
>
> > Hi Group !
> >
> > I have a weird problem with bean validation in JSF and hope someone
> > can help me.
> >
> > I have a JEE6 project using JPA2, JSF2, MyFaces CODI 1.0 and MyFaces
> > Extval
> > 2.0.5 (bean, core and property module).
> >
> > I have an entity with a field ->
> >
> >
> > @Entity
> > @Table(name="bewerbungen")
> > public class Bewerbung extends BaseEntityVersioned implements
> > Serializable { .....
> >        @Lob
> >        @Column(name="Bemerkung")
> >        private String bemerkung;
> > .....
> > }
> >
> > a Form with h:inputTextarea that writes directly to the entity ->
> >
> > <h:outputLabel for="bemerkung" value="#{msgs.bewerben_bemerkungen}" />
> > <h:inputTextarea id="bemerkung"
> > value="#{applyForJobPage.bewerbung.bemerkung}" rows="12" cols="75"
> > label="#{msgs.bewerben_bemerkungen}"  />
> >
> > and a view bean->
> >
> > @Named
> > @ViewAccessScoped
> > public class ApplyForJobPage extends AbstractProfilePage{
> >
> >        private Bewerbung bewerbung;
> >
> > ... getter and setter ...
> > }
> >
> >
> > There are no validations defined but when I copy a text longer than
> > 255 character into the text field I get a validation Error ! (=>
> Anschreiben:
> > Überprüfungsfehler: Wert ist größer als der zulässige Maximalwert
> > "255")
> >
> > I also tried to change the code to:
> >
> >  <h:inputTextarea id="bemerkung"
> > value="#{applyForJobPage.bewerbung.bemerkung}" rows="12" cols="75"
> > label="#{msgs.bewerben_bemerkungen}" > <f:validateLength maximum="512"
> > /> </h:inputTextarea>
> >
> > and
> >
> > @Lob
> > @Size(max=512)
> > @Column(name="Bemerkung")
> > private String bemerkung;
> >
> > Both didn't work. The only thing that works would be to define a
> > string in the view bean and move this string into the entity later.
> >
> > I couldn't find any hints in the internet about a default length of
> > 255 characters.
> >
> > Any ideas ?
> >
> > best regards
> >
> > Thomas
> >
> >
> >
> >
>
>

AW: Bean Validation

Posted by "Ing.Thomas Kernstock" <t....@e-technologies.at>.
hi gerhard,

once again you saved my day (or better night in this case :-)) !  thanx a
lot.

Just for my curiosity -> I couldn't find any hint on the internet that a
@Lob will be validated with a length of 255 by default. Do you know if this
is an extval "feature" or if it is defined elsewhere ?

best regards
Thomas


-----Ursprüngliche Nachricht-----
Von: Gerhard Petracek [mailto:gerhard.petracek@gmail.com] 
Gesendet: Donnerstag, 08. September 2011 21:34
An: MyFaces Discussion
Betreff: Re: Bean Validation

hi thomas,

length of @Column should help. e.g. @Column(length = 512)

regards,
gerhard

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces



2011/9/8 Ing.Thomas Kernstock <t....@e-technologies.at>

> Hi Group !
>
> I have a weird problem with bean validation in JSF and hope someone 
> can help me.
>
> I have a JEE6 project using JPA2, JSF2, MyFaces CODI 1.0 and MyFaces 
> Extval
> 2.0.5 (bean, core and property module).
>
> I have an entity with a field ->
>
>
> @Entity
> @Table(name="bewerbungen")
> public class Bewerbung extends BaseEntityVersioned implements 
> Serializable { .....
>        @Lob
>        @Column(name="Bemerkung")
>        private String bemerkung;
> .....
> }
>
> a Form with h:inputTextarea that writes directly to the entity ->
>
> <h:outputLabel for="bemerkung" value="#{msgs.bewerben_bemerkungen}" /> 
> <h:inputTextarea id="bemerkung"
> value="#{applyForJobPage.bewerbung.bemerkung}" rows="12" cols="75"
> label="#{msgs.bewerben_bemerkungen}"  />
>
> and a view bean->
>
> @Named
> @ViewAccessScoped
> public class ApplyForJobPage extends AbstractProfilePage{
>
>        private Bewerbung bewerbung;
>
> ... getter and setter ...
> }
>
>
> There are no validations defined but when I copy a text longer than 
> 255 character into the text field I get a validation Error ! (=>
Anschreiben:
> Überprüfungsfehler: Wert ist größer als der zulässige Maximalwert 
> "255")
>
> I also tried to change the code to:
>
>  <h:inputTextarea id="bemerkung"
> value="#{applyForJobPage.bewerbung.bemerkung}" rows="12" cols="75"
> label="#{msgs.bewerben_bemerkungen}" > <f:validateLength maximum="512" 
> /> </h:inputTextarea>
>
> and
>
> @Lob
> @Size(max=512)
> @Column(name="Bemerkung")
> private String bemerkung;
>
> Both didn't work. The only thing that works would be to define a 
> string in the view bean and move this string into the entity later.
>
> I couldn't find any hints in the internet about a default length of 
> 255 characters.
>
> Any ideas ?
>
> best regards
>
> Thomas
>
>
>
>


Re: Bean Validation

Posted by Gerhard Petracek <ge...@gmail.com>.
hi thomas,

length of @Column should help. e.g. @Column(length = 512)

regards,
gerhard

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces



2011/9/8 Ing.Thomas Kernstock <t....@e-technologies.at>

> Hi Group !
>
> I have a weird problem with bean validation in JSF and hope someone can
> help
> me.
>
> I have a JEE6 project using JPA2, JSF2, MyFaces CODI 1.0 and MyFaces Extval
> 2.0.5 (bean, core and property module).
>
> I have an entity with a field ->
>
>
> @Entity
> @Table(name="bewerbungen")
> public class Bewerbung extends BaseEntityVersioned implements Serializable
> {
> .....
>        @Lob
>        @Column(name="Bemerkung")
>        private String bemerkung;
> .....
> }
>
> a Form with h:inputTextarea that writes directly to the entity ->
>
> <h:outputLabel for="bemerkung" value="#{msgs.bewerben_bemerkungen}" />
> <h:inputTextarea id="bemerkung"
> value="#{applyForJobPage.bewerbung.bemerkung}" rows="12" cols="75"
> label="#{msgs.bewerben_bemerkungen}"  />
>
> and a view bean->
>
> @Named
> @ViewAccessScoped
> public class ApplyForJobPage extends AbstractProfilePage{
>
>        private Bewerbung bewerbung;
>
> ... getter and setter ...
> }
>
>
> There are no validations defined but when I copy a text longer than 255
> character into the text field I get a validation Error ! (=> Anschreiben:
> Überprüfungsfehler: Wert ist größer als der zulässige Maximalwert "255")
>
> I also tried to change the code to:
>
>  <h:inputTextarea id="bemerkung"
> value="#{applyForJobPage.bewerbung.bemerkung}" rows="12" cols="75"
> label="#{msgs.bewerben_bemerkungen}" >
> <f:validateLength maximum="512" />
> </h:inputTextarea>
>
> and
>
> @Lob
> @Size(max=512)
> @Column(name="Bemerkung")
> private String bemerkung;
>
> Both didn't work. The only thing that works would be to define a string in
> the view bean and move this string into the entity later.
>
> I couldn't find any hints in the internet about a default length of 255
> characters.
>
> Any ideas ?
>
> best regards
>
> Thomas
>
>
>
>