Validation enhancements?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Validation enhancements?

FDominicus
Another question which I should forward to this list.

The validation of elements. If we add input elements to forms we do it
via the  add..Aspect:for: functions. But we have to declare the
validation in an extra step. According to Janko the following code does
that:


field := e newCell addInputFieldAspect: #tanNr for: self observee.
        field
                validIfTrue: [:value | self observee parent noOtherTanMatches: value ];
                errorText: 'Tan numbers must be unique'.

Shouldn't this validatoin functoin be added to the above line with e.g a
block?

like this:
field := e newCell addInputField: ... for: ... validateAgainst:
someBlock? someValidatorObject?


And building upon this shouldn't we than have either some extra classes
which make this "easier accessible".

field := e newCell addNumericConraintField: #tanNr....

well than we still have the question on when this validation will be
handeled. If JavaScript is active this validation can be run directly
on the Client, but we probably need some other validation rules (either
if someone does not have JavaScript active) or if we want to assure that
our model data are ok. Anyway the code probably has to emit two
different validation functions. One in JavaScript one in Smalltalk.

I think it would be terrible to have

field := e newCell addNumericContraintField: #tanNr
clientSideValidation: [someJavaScript validation block]
serverSideValidatin: [some Smalltalk validation block]

if I look over this we probably be bette of using ValidationObjects.

something like
WebValidatorObject

    clientSideValidatorFun: whatToValidateOnClient
    serverSideValidationFun: whatToValidateOnServer
    modelValidationFun: ValidatorForTheModel.

.
yes indeed it looks clumsy, but the use of it would be simple


field := e newCell addNumericContraintField: #tanNr validator:
IntegerInputFieldValidator .....

or the like.

It would be best of course to get at least some logging if the
validatoin failed. It seems debugging Aida wite the Smalltalk debugger
is not that "nice". At least I wasn't able to step through my code
because some other context function was debugged while I just said step
over.

But maybe it's just me beeing to dumb...

Regards
Friedrich





--
Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim
Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Validation enhancements?

Herbert König
Hi Friedrich,

FD> The validation of elements. If we add input elements to forms we do it
FD> via the  add..Aspect:for: functions. But we have to declare the
FD> validation in an extra step.

let me speak from my experience so far. In general I agree with both
of your posts.

But I doubt, my validator would solve your problems or that yours
would be useful to me. My abstract class InputValidator verifies the
basics String, REBInteger and REBFloat instead of Integer and Float.

The concrete classes verify over groups of inputs. In the attachment
you can see verification for some of the CRUD operations.

FD> field := e newCell addInputFieldAspect: #tanNr for: self observee.

In this case I write
e addInputFieldAspect: #floatNumberText for: self observee.

floatNumberText allows for + 123 456,789 as a Float before validation.

FD> like this:
FD> field := e newCell addInputField: ... for: ... validateAgainst:
FD> someBlock? someValidatorObject?

yes but also depending on the particular CRUD operation. See
attachment. I have buttons for add, update, delete which trigger the
validator.

FD> well than we still have the question on when this validation will be
FD> handeled. If JavaScript is active this validation can be run directly
FD> on the Client, but we probably need some other validation rules (either
FD> if someone does not have JavaScript active) or if we want to assure that
FD> our model data are ok. Anyway the code probably has to emit two
FD> different validation functions. One in JavaScript one in Smalltalk.

For this I have WebElement>>addClickDo: aBlock andUpdateFunction: aJavaScript
which is still an ugly hack but I want to propose this for inclusion
in AIDA when it's ready.

For some information on the rationale behind this see:
http://article.gmane.org/gmane.comp.web.server.aida/2649

In the even older discussions with Alex Baran we planned to have a
whole event system based on this.

FD> But maybe it's just me beeing to dumb...

Definitely not! We need CRUD operations on a grid, we need input
verification and we need parts done in the server and parts done in
the browser. All IMHO that is.

There's another thing I wish for and that's sending JSON back and
forth.

When somebody clicks on a line in a grid which should be
highlighted (rowBoldIfTrue: aBlock) instead of the previously
highlighted line, up to now we are:

-letting the server know about the newly selected line,
-rebuilding the component(s),
-replacing the new id's with the old ones
-creating the whole HTML of the component(s) and
-sending it

I want to just send:
[{id=1 class='WebGrid'},... {id=7 class='Blue'} ...] and have some
JavaScript update the DOM.

Maybe I'm straying too far from the path of REST here. But I need my
web application perform like my locally running spreadsheet, so in my
very constrained time I work towards this.

Another thing my grids need is a slider. The current way (rowsOnPage)
was not acceptable for me last time I looked.
Right now I have a slider beside my grid which indicates which of the
100 rows of a table are displayed in the 10 row grid. Navigating the
grid with the slider doesn't work yet. And it will put a big load on
the server if it has to go through all the above steps instead of
sending a JSON array of 50 floats and have JavaScript update the HTML.

Cheers,

Herbert                            mailto:[hidden email]
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida

RB# DA53Validator.png (56K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Validation enhancements?

FDominicus
Herbert König <[hidden email]> writes:

> Hi Friedrich,
>
> FD> The validation of elements. If we add input elements to forms we do it
> FD> via the  add..Aspect:for: functions. But we have to declare the
> FD> validation in an extra step.
>
> let me speak from my experience so far. In general I agree with both
> of your posts.
>
> But I doubt, my validator would solve your problems or that yours
> would be useful to me.
Well I would think that we have a let's say pluggable Object for that.
And all of our validators should derive from this Object and while we
declare the elements we choose either one of the prefabricated
validators (one wich surly springs to your mind also is a
IntegerInputField), I doubt that this would not be useful to you also.

That was the point on how to add a validator. Should validator just be a
block (than I ask how you will combine them with and:; or:

or if we might use something like

aValidator := IntegerValidator new.
aValidator minValue : 1
aValidator maxValue : 10

someWebElement := WebElementWithValidator new.
   someWebElement use: aValidator....


we than also may have a form validation function which defaults may be
to

something

form runThroughAlleFormElementscollectingValidationResults

and there
we either collect all bugs on page and whil rendering we look through it
and e.g highlight the fields with "errors" ....



>
> In the even older discussions with Alex Baran we planned to have a
> whole event system based on this.
I think this may be the best ans most extensible but also the easiest to
comprehend approach. ...
>
> There's another thing I wish for and that's sending JSON back and
> forth.
Very funny. I suggested to add this facility to a software which is
currently developed. It's for the German EANV system which is about
handling waste and digitally signing such things. My idea to a port of
our current software, is to use JSON objects for WebServices. It's
definitly more lightweight than XML and let's see it like it is it's
easier to handle in every language. I don't have to mention XPATH or
even worse XSLT or do I ;-)

>
> When somebody clicks on a line in a grid which should be
> highlighted (rowBoldIfTrue: aBlock) instead of the previously
> highlighted line, up to now we are:
>
> -letting the server know about the newly selected line,
> -rebuilding the component(s),
> -replacing the new id's with the old ones
> -creating the whole HTML of the component(s) and
> -sending it
>
> I want to just send:
> [{id=1 class='WebGrid'},... {id=7 class='Blue'} ...] and have some
> JavaScript update the DOM.
>
> Maybe I'm straying too far from the path of REST here.
I don't know but if we provide a JSON api shouldn't that be a good
replacement?


>
> Another thing my grids need is a slider. The current way (rowsOnPage)
> was not acceptable for me last time I looked.
> Right now I have a slider beside my grid which indicates which of the
> 100 rows of a table are displayed in the 10 row grid. Navigating the
> grid with the slider doesn't work yet. And it will put a big load on
> the server if it has to go through all the above steps instead of
> sending a JSON array of 50 floats and have JavaScript update the HTML.
I think I'm on your side here. We really must see that we just send as
less information as is needed. Not everywhere you can get above let's
say even 50 KB/sec. For most of my customers needs I think less than 2 K
are really needed at once. And for one applicaton specifically I can get
away with a 9600 serial line....

I also think that JSSON could be quite easy be compressed, it's nothing
really "fancy" in it. You can see that this works for XML also... But we
have much less redundance but JSON has eveything we need to marshall
objects. And if you look ad JavaScript and Smalltalk you can see there
is a nearly 1:1 match....

Another advantage see ther are at least two quite Databases using JSON
and if we look  a little further, couldn't it be that using some of
those Databases would be a nice way for a Smalltalk Revision control but
with the advantage that every language able to treat JSON can use the
Data?

Of course you can say we have our SQL interfaces, but I'm looking into
OODB since ages and if you look at diverse ORM based tools. It often
just is as if our Objects should be "flattened". Inheritance is often
not used? The reason for that alone can't be that we won't use OO but
that we just constrain ourselves on "flatter" objects.  Just look at one
hallmark of an ORM Active Records but see how many words there have been
written over it.. Should that be "easy"?


--
Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim
Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Validation enhancements?

Herbert König
Friedrich,

FD> That was the point on how to add a validator. Should validator just be a
FD> block (than I ask how you will combine them with and:; or:

by some accident I stumbled over:
http://www.aidaweb.si/form-validation.html
showing that the block type validation seems to be built into AIDA
already.

FD> or if we might use something like
FD> aValidator := IntegerValidator new.
FD> aValidator minValue : 1
FD> aValidator maxValue : 10

Block validation should be sufficient for String, Float and Integer
and is applied on the single Input field.

FD> we than also may have a form validation function which defaults may be

Yes though although I do it on components of a form which are then
Ajax updated.

FD> to something
FD> form runThroughAlleFormElementscollectingValidationResults

The validation classes for complex objects must assure uniqueness in
some sense (e.g. the combination of several ivars must be unique) to
allow a create. This is more than the sum of all the inputs
validation.

But yes, thinking about it in terms of CRUD it seems possible to do
some generalisation regarding the different operations.
Maybe:
Creation only of unique objects in the above sense.
Update only if the fields required for uniqueness above are unchanged
Delete ????
Forgot something?

http://www.squeaksource.com/ComplexCondition may come in handy for
this.

All this said all my validators are used by the WebApplication's
observee which mediates between the actual model and its view. Which
seems to say that complex input validation is not the business of the
web framework at all. Following strict Aida philosophy each model
class should have had its own WebApplication. In that case my
assumption may not hold.

FD> and there
FD> we either collect all bugs on page and whil rendering we look through it
FD> and e.g highlight the fields with "errors" ....

For uniqueness you can change one of several fields, so I opted for
one error line representing only the last error. But again attaching
some JavaScript to the errorfield which sets the class of the affected
inputs to red is a good idea.

>>
>> There's another thing I wish for and that's sending JSON back and
>> forth.
FD> It's
FD> definitly more lightweight than XML and let's see it like it is it's
FD> easier to handle in every language. I don't have to mention XPATH or
FD> even worse XSLT or do I ;-)

Lucky me spent his life without XML except looking at it with disgust
when some programmers I supervised used it for object storage. But
they also used C++ and XML was the rage then so what should I expect :-))

>> I want to just send:
>> [{id=1 class='WebGrid'},... {id=7 class='Blue'} ...] and have some
>> JavaScript update the DOM.
FD> I don't know but if we provide a JSON api shouldn't that be a good
FD> replacement?

That's what I meant to say :-))

FD> Another advantage see ther are at least two quite Databases using JSON

I'm happy that Igor Stasenko maintains a Squeak CouchDB interface. But
up to now, wherever I went I heard SQL say "I'm already here" like the
hedgehog in the fairy tale.


Cheers,

Herbert                            mailto:[hidden email]

_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Validation enhancements?

Janko Mivšek
Hi guys,

Just FYI, JSON is actually already in forthcoming Aida 6.2 and currently
I'm working on WebSocket support for always there Comet functionality.
This means that WebSocket will be always open and will allow to send
messages to browser at any time. One of those messages is also an update
JSON command, to update some element on the web page. So, updating pages
will be as easy as you can imagine, just by 'e update' and that element
will be instantly updated on the browser. Herbert, you'll sure love that :)

About form validation, my current goal is to make an ajaxified
validation of inputs, that means immediately after user enters some
input. If wrongly, an error message is immediately shown and form is not
allowed to post.

Example how to use ajaxified validation is in
WebDemoApp>>ajaxValidationExample (in 6.1 too)

Validation should be improved, yes, also with predefined validation,
like for dates, emails, numbers etc.

Now back to WebSocket for me :)

Best regards
Janko

On 27. 11. 2010 19:12, Herbert König wrote:

> Friedrich,
>
> FD> That was the point on how to add a validator. Should validator just be a
> FD> block (than I ask how you will combine them with and:; or:
>
> by some accident I stumbled over:
> http://www.aidaweb.si/form-validation.html
> showing that the block type validation seems to be built into AIDA
> already.
>
> FD> or if we might use something like
> FD> aValidator := IntegerValidator new.
> FD> aValidator minValue : 1
> FD> aValidator maxValue : 10
>
> Block validation should be sufficient for String, Float and Integer
> and is applied on the single Input field.
>
> FD> we than also may have a form validation function which defaults may be
>
> Yes though although I do it on components of a form which are then
> Ajax updated.
>
> FD> to something
> FD> form runThroughAlleFormElementscollectingValidationResults
>
> The validation classes for complex objects must assure uniqueness in
> some sense (e.g. the combination of several ivars must be unique) to
> allow a create. This is more than the sum of all the inputs
> validation.
>
> But yes, thinking about it in terms of CRUD it seems possible to do
> some generalisation regarding the different operations.
> Maybe:
> Creation only of unique objects in the above sense.
> Update only if the fields required for uniqueness above are unchanged
> Delete ????
> Forgot something?
>
> http://www.squeaksource.com/ComplexCondition may come in handy for
> this.
>
> All this said all my validators are used by the WebApplication's
> observee which mediates between the actual model and its view. Which
> seems to say that complex input validation is not the business of the
> web framework at all. Following strict Aida philosophy each model
> class should have had its own WebApplication. In that case my
> assumption may not hold.
>
> FD> and there
> FD> we either collect all bugs on page and whil rendering we look through it
> FD> and e.g highlight the fields with "errors" ....
>
> For uniqueness you can change one of several fields, so I opted for
> one error line representing only the last error. But again attaching
> some JavaScript to the errorfield which sets the class of the affected
> inputs to red is a good idea.
>
>>>
>>> There's another thing I wish for and that's sending JSON back and
>>> forth.
> FD> It's
> FD> definitly more lightweight than XML and let's see it like it is it's
> FD> easier to handle in every language. I don't have to mention XPATH or
> FD> even worse XSLT or do I ;-)
>
> Lucky me spent his life without XML except looking at it with disgust
> when some programmers I supervised used it for object storage. But
> they also used C++ and XML was the rage then so what should I expect :-))
>
>>> I want to just send:
>>> [{id=1 class='WebGrid'},... {id=7 class='Blue'} ...] and have some
>>> JavaScript update the DOM.
> FD> I don't know but if we provide a JSON api shouldn't that be a good
> FD> replacement?
>
> That's what I meant to say :-))
>
> FD> Another advantage see ther are at least two quite Databases using JSON
>
> I'm happy that Igor Stasenko maintains a Squeak CouchDB interface. But
> up to now, wherever I went I heard SQL say "I'm already here" like the
> hedgehog in the fairy tale.
>
>
> Cheers,
>
> Herbert                            mailto:[hidden email]

--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Validation enhancements?

Herbert König
Hi Janko,


JM> Just FYI, JSON is actually already in forthcoming Aida 6.2 and currently
JM> I'm working on WebSocket support for always there Comet functionality.

great! great! great!

JM> This means that WebSocket will be always open and will allow to send
JM> messages to browser at any time.

I was already searching for this because you mentioned it on
aidaweb.si. These will help to make AidaCharts and WebSlider really
interactive.

JM> Herbert, you'll sure love that :)

You bet :-)


Cheers,

Herbert                            mailto:[hidden email]

_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Validation enhancements?

FDominicus
In reply to this post by Herbert König
Herbert König <[hidden email]> writes:

> Hi Friedrich,
>
> FD> The validation of elements. If we add input elements to forms we do it
> FD> via the  add..Aspect:for: functions. But we have to declare the
> FD> validation in an extra step.
>
> let me speak from my experience so far. In general I agree with both
> of your posts.
>
> But I doubt, my validator would solve your problems or that yours
> would be useful to me. My abstract class InputValidator verifies the
> basics String, REBInteger and REBFloat instead of Integer and Float.
>
> The concrete classes verify over groups of inputs. In the attachment
> you can see verification for some of the CRUD operations.

Well have you a examples of it in an Aida application?

Regards
Friedrich

--
Q-Software Solutions GmbH; Sitz: Bruchsal; Registergericht: Mannheim
Registriernummer: HRB232138; Geschaeftsfuehrer: Friedrich Dominicus
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Validation enhancements?

Herbert König
Hi Friedrich,

FD> Well have you a examples of it in an Aida application?

I'm not sure if I understand you here but this is how it goes:

The add/change Button triggers the action method #addOrChangePosition
in the Aida application.

This sends self observee addOrChangeSelectedPosition.

This reads:
addOrChangeSelectedPosition
                self isValidSelectedPosition ifFalse: [^self].
        self canAddSelectedPosition
                ifTrue: [self addSelectedPosition]
                ifFalse:
                        [self canChangeSelectedPosition
                                ifTrue: [self changeSelectedPosition]]

Finally  isValidSelectedPosition is implemented as:
isValidSelectedPosition
        |validator isValid|
        validator := DA53Validator new. "<---------------------------"
        validator
                dA53: selectedPosition;
                abrechnung: abrechnung.
        isValid := validator isValid .
        lastError := validator lastError.
        ^isValid


I'm still not sure if the model should have readily initialized
validators.
       
As I said in another post basic type validation happens in the Web
application. It goes like:

In viewAddPosition (which is active in the browser in the png) the 4
lines for entering a position are put in a method
#displayPositionForEntryComponent which consists of four statements
like:
self
    addTabbingLineTo: e
    header: 'Vorgabemasse:'
    selector: #vorgabeMasseText
    receiver: selectedPosition
    size: 40.
   
where #vorgabeMasseText(:) are implemented in the receiver for
accessing a Float ivar.

This comes from a suggestion of Janko that Aida itself could deal with
getters and setters for Strings and Integers on its own and that for
Floats one should implement accessors #floatText which do the Float to
String conversion.

I used this for implementing basic validation and formatting like:
DA53>>vorgabeMasseText
        ^vorgabeMasse printShowingDecimalPlaces: 3

and:
DA53>>vorgabeMasseText: aString
        aString ifValidForFloatSend: #vorgabeMasse: to: self

So I added to the clutter in String by burdening it with basic input
validation.

Hopefully that answers your question.

Cheers,

Herbert                            mailto:[hidden email]
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida

browser.PNG (53K) Download Attachment