Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Model validation @Constraints is not working (based on form sample)

Received: by 10.224.105.205 with SMTP id u13mr4037807qao.6.1353110677420;
        Fri, 16 Nov 2012 16:04:37 -0800 (PST)
X-BeenThere: play-framework@googlegroups.com
Received: by 10.49.39.74 with SMTP id n10ls1289864qek.16.gmail; Fri, 16 Nov
 2012 16:04:28 -0800 (PST)
Received: by 10.224.207.66 with SMTP id fx2mr4039714qab.7.1353110668821;
        Fri, 16 Nov 2012 16:04:28 -0800 (PST)
Received: by 10.224.173.148 with SMTP id p20msqaz;
        Fri, 16 Nov 2012 07:10:06 -0800 (PST)
Received: by 10.49.71.135 with SMTP id v7mr1027420qeu.28.1353078604984;
        Fri, 16 Nov 2012 07:10:04 -0800 (PST)
Date: Fri, 16 Nov 2012 07:10:04 -0800 (PST)
From: adel alfar <a...@oax.com>
To: play-framework@googlegroups.com
Message-Id: <1a373c28-7c6b-4863-b329-9e8b9ccbcb4e@googlegroups.com>
In-Reply-To: <ed1a878f-1e1d-4833-855b-b82bdace32a0@googlegroups.com>
References: <4dc139cd-fc23-4372-9409-a511c69880b6@googlegroups.com>
 <8fbf2e81-4bdb-4ce2-bc1c-67050bb4f763@googlegroups.com>
 <3bb389b6-9e16-449d-b960-80cbba5d351e@googlegroups.com>
 <ed1a878f-1e1d-4833-855b-b82bdace32a0@googlegroups.com>
Subject: Re: [2.1 master] Model validation @Constraints is not working
 (based on form sample)
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_342_916756.1353078604209"

------=_Part_342_916756.1353078604209
Content-Type: multipart/alternative; 
	boundary="----=_Part_343_6445891.1353078604209"

------=_Part_343_6445891.1353078604209
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

James,

I submitted ticket #858...Thank again!


On Thursday, November 15, 2012 4:29:40 PM UTC-6, James Roper wrote:
>
> We support partial validation?  I didn't know that :)  If you think you 
> have found a bug, please raise it here:
>
> https://play.lighthouseapp.com/projects/82401-play-20/
>
> On Friday, 16 November 2012 02:48:50 UTC+11, adel alfar wrote:
>>
>> I actually found the error( on my part) , which was relating to the new 
>> 2.1 "Partial Validation" feature.   I had the following Action code (with 
>> the incorrect one commented):
>>
>>  //final static Form<Driver> signupForm = form(User.class, 
>> User.All.class);
>>
>>     final static Form<Driver> signupForm = form(User.class);
>> And since I did not specify the "groups=All.class" in the 
>> @Constraints.Require the Form did not bind correctly to the Model's 
>> validation errors.
>>
>> So, in order to bind correctly (for the reader of this post) you need to 
>> specify the same  Partial Interface you specified in the Action/Form 
>> binding in the @Constraints.Required   annotation...
>>
>> Speaking of which James:
>>
>> For the @Constraints.Min(Max,Length) annotations...why aren't there 
>> partial validation support (via groups=) like in the Required annotation?
>> I think in order to be able to stack the @Constraints for a field with 
>> partial validation support, all Play Validation annotation should support
>> partial validation. No?
>>
>> And thank you very much for response and your advice about the _error 
>> field!
>>
>>
>> On Wednesday, November 14, 2012 6:49:03 PM UTC-6, James Roper wrote:
>>>
>>> You shouldn't need the '_error field, the defaultFieldConstructor 
>>> renders the errors for you.  Can you show the action you are using to 
>>> handle the form submission?
>>>
>>> On Thursday, 15 November 2012 04:30:38 UTC+11, adel alfar wrote:
>>>>
>>>> I created an @Entity Model class and decorated a field with 
>>>> @Constraints.Required.  I then submitted the form without filling the 
>>>> field.   The page rendered with no errors showing that the field was 
>>>> required.  I wonder what am I missing or if something had changed... Here 
>>>> is some code
>>>>
>>>> package models;
>>>> ...
>>>>
>>>> @Entity
>>>>
>>>> public class Driver extends Model {
>>>>
>>>> public interface All {}
>>>>
>>>> public interface Step1 {}
>>>>
>>>> public interface Step2 {}
>>>>
>>>>  public User (
>>>>
>>>>  Long id
>>>>
>>>>  , String username
>>>>
>>>> ) {
>>>>
>>>>   this.id = id;
>>>>
>>>>  this.username = username;
>>>>
>>>> }
>>>>
>>>>     @Id
>>>>
>>>> public Long id;
>>>>
>>>>  @Constraints.Required
>>>>
>>>> public String username;
>>>>
>>>>  @Constraints.Required
>>>>
>>>> public String acceptedLicense;
>>>>
>>>>  }
>>>>
>>>>
>>>> template view:
>>>>
>>>>  @inputText(
>>>>
>>>>                 signupForm("username"), 
>>>>
>>>>                 '_label -> "Username", 
>>>>
>>>>                 '_help -> "Please choose a valid username.",
>>>>
>>>>                 '_error -> signupForm("username").errors().mkString(", 
>>>> "),
>>>>
>>>>                 '_showConstraints -> false
>>>>
>>>>             )
>>>>
>>>>
------=_Part_343_6445891.1353078604209
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

James,<div><br></div><div>I submitted ticket #858...Thank again!</div><div>=
<br><br>On Thursday, November 15, 2012 4:29:40 PM UTC-6, James Roper wrote:=
<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bor=
der-left: 1px #ccc solid;padding-left: 1ex;">We support partial validation?=
 &nbsp;I didn't know that :) &nbsp;If you think you have found a bug, pleas=
e raise it here:<div><br></div><div><a href=3D"https://play.lighthouseapp.c=
om/projects/82401-play-20/" target=3D"_blank">https://play.lighthouseapp.<w=
br>com/projects/82401-play-20/</a></div><div><br>On Friday, 16 November 201=
2 02:48:50 UTC+11, adel alfar  wrote:<blockquote class=3D"gmail_quote" styl=
e=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex=
">I actually found the error( on my part) , which was relating to the new 2=
.1 "Partial Validation" feature. &nbsp; I had the following Action code (wi=
th the incorrect one commented):<div><br><div>







<p><span>&nbsp;</span>//final static Form&lt;Driver&gt; signupForm =3D form=
(User.class, User.All.class);</p>
<p>&nbsp; &nbsp; <span>final</span> <span>static</span> Form&lt;Driver&gt; =
<span>signupForm</span> =3D form(User.<span>class</span>);</p>And since I d=
id not specify the "groups=3DAll.class" in the @Constraints.Require the For=
m did not bind correctly to the Model's validation errors.</div><div><br></=
div><div>So, in order to bind correctly (for the reader of this post) you n=
eed to specify the same &nbsp;Partial Interface you specified in the Action=
/Form binding in the @Constraints.Required &nbsp; annotation...</div><div><=
br></div><div>Speaking of which James:</div><div><br></div><div>For the @Co=
nstraints.Min(Max,Length) annotations...why aren't there partial validation=
 support (via groups=3D) like in the Required annotation?</div><div>I think=
 in order to be able to stack the @Constraints for a field with partial val=
idation support, all Play Validation annotation should support</div><div>pa=
rtial validation. No?</div><div><br></div><div>And thank you very much for =
response and your advice about the _error field!</div><div><br></div><div><=
br>On Wednesday, November 14, 2012 6:49:03 PM UTC-6, James Roper wrote:<blo=
ckquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-le=
ft:1px #ccc solid;padding-left:1ex">You shouldn't need the '_error field, t=
he defaultFieldConstructor renders the errors for you. &nbsp;Can you show t=
he action you are using to handle the form submission?<br><br>On Thursday, =
15 November 2012 04:30:38 UTC+11, adel alfar  wrote:<blockquote class=3D"gm=
ail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;p=
adding-left:1ex">I created an @Entity Model class and decorated a field wit=
h @Constraints.Required. &nbsp;I then submitted the form without filling th=
e field. &nbsp; The page rendered with no errors showing that the field was=
 required. &nbsp;I wonder what am I missing or if something had changed... =
Here is some code<div><br></div><div>package models;</div><div>...</div><di=
v><br></div><div>







<p>@Entity</p>
<p>public<span> </span>class<span> </span><span>Driver</span><span> </span>=
extends<span> Model {</span></p>
<p><span>=09</span>public<span> </span>interface<span> All {}</span></p>
<p><span>=09</span>public<span> </span>interface<span> Step1 {}</span></p>
<p><span>=09</span>public<span> </span>interface<span> Step2 {}</span></p>
<p><span>=09</span></p>
<p><span>=09</span><span>public</span> User (</p>
<p><span>=09</span><span>=09</span><span>=09</span>Long id</p>
<p><span>=09</span><span>=09</span><span>=09</span>, String username</p>
<p><span>=09</span>) {</p>
<p><span>=09</span><span>=09</span></p>
<p><span>=09</span><span>=09</span><span>this</span>.<span>id</span> =3D id=
;</p>
<p><span>=09</span><span>=09</span><span>this</span>.<span>username</span> =
=3D username;</p>
<p><span>=09</span>}</p>
<p><span>=09</span><span>=09</span><span>=09</span></p>
<p><span>=09</span><span>=09</span><span>=09</span></p>
<p><span>=09</span>@Id</p>
<p><span>=09</span><span>public</span> Long <span>id</span>;</p>
<p><span>=09</span></p>
<p><span>=09</span><span>@</span>Constraints.<span>Required</span></p>
<p><span>=09</span><span>public</span> String <span>username</span>;</p>
<p><span>=09</span></p>
<p><span>=09</span><span>@</span>Constraints.<span>Required</span></p>
<p><span>=09</span><span>public</span><span> String </span>acceptedLicense<=
span>;</span></p>
<p><span>=09</span></p>
<p>}</p><p><br></p><p>template view:</p><p>







</p><p>&nbsp;@inputText(</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; signupForm("user=
name"),&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '_label -&gt; "U=
sername",&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '_help -&gt; "Pl=
ease choose a valid username.",</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '_error -&gt; si=
gnupForm("username").errors(<wbr>).mkString(", "),</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '_showConstraint=
s -&gt; false</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )</p><p></p></div></blockquote=
></blockquote></div></div></blockquote></div></blockquote></div>
------=_Part_343_6445891.1353078604209--

------=_Part_342_916756.1353078604209--