I narrowed the problem: I have to use my validation instance inside
the bind and inside my submit() method. but the stored validation
object will not be used by the bind. Is there done anything i must be
aware of when using variables inside of methods passed to the
S.submit?

On May 16, 1:49 am, Scalanewbie <[email protected]> wrote:
> In addtion to my problem, i found out that request vars live from the
> current request till the next request. And when i switch to simple
> vals i dont event have a value in my submit() form.
>
> On May 16, 12:06 am, Scalanewbie <[email protected]> wrote:
>
> > Hi Marius, thanks for your explanation but i have some trouble getting
> > the lifcycle right:
>
> > object name extends RequestVar("")
>
> > def dodo(form : NodeSeq) = {
>
> >     val myObject= new MyObject(name)
> >     val validation = Validator.prepare(myObject)
>
> >     def submit() {
> >       validation.validate()
> >       if(validation ok) //doStuff else {
> >           S.error("Invalid input")
> >           S.mapSnippet("Snippet.dodo", doBind)
> >       }
> >     }
>
> > def doBind(form : NodeSeq) = bind("myform", form,
> >   "name" -> SHtml.text(name.is, name(_),("class",validation css
> > "name")),
> >   "submit" -> SHtml.submit(S ? "send", submit))
>
> > doBind(form)
>
> > }
>
> > The problem is that the validation object inside the "submit()"
> > differs (other object reference) from the one used in the validation
> > css "name" method call.
> > The validation has a state that gets somehow lost/replaced.
>
> > Any suggestions on that?
>
> > On May 15, 11:00 pm, "marius d." <[email protected]> wrote:
>
> > > If you want to change CSS classes upon validation you can do:
>
> > > Non Ajax
>
> > > 1.
> > > .
> > > bind("myobject", xhtml,
> > >   "name" -> SHtml.text(name.is, name(_) % ("class" -> "read the value
> > > from you state"),
> > > ("class","dependsOnTheValidationResult"),
> > >   "submit" -> SHtml.submit("submit", submit)
> > > )
>
> > > Note that the rendering happens after you request functions have been
> > > invoked (obviously) so when rendering the text field you already know
> > > the class from your function logic.
>
> > > 2. On rendering use Snippet atrributes
>
> > > <text lift:snippet="ClassSnippet" ... />
>
> > > Ajax
>
> > > 1. In the Ajax JavaScript response you can easily change classes.
>
> > > On May 15, 11:20 pm, Scalanewbie <[email protected]> wrote:
>
> > > > Hi Marius,
> > > > this is what i do at the moment, but i dont see a way to put the css
> > > > class information into my elements after the validation.
> > > > This seems not to be possible with the msgs class. Because it just
> > > > prints out the error with a specific css class and
> > > > does not do any special node manipulation (which is good, because its
> > > > not the right place).
>
> > > > On May 15, 9:37 pm, "marius d." <[email protected]> wrote:
>
> > > > > On May 15, 10:18 pm, Scalanewbie <[email protected]> wrote:
>
> > > > > > Hi,
> > > > > > as a lift-scala-newbie i am trying out various things with lift to 
> > > > > > see
> > > > > > advantages etc. to other frameworks (rails, grails,...)
>
> > > > > > I am now trying to integrate a third party java validation library 
> > > > > > and
> > > > > > i want to embed the results into my webapp. First i want to put all
> > > > > > localized error messages into the error object, which seems to be
> > > > > > straightforward and i am not expecting any problems there.
>
> > > > > > my second step would be a integration with the binding to visualize
> > > > > > input/textareas depending on their validation results. My problem is
> > > > > > now the lifecycle of my snippet.
>
> > > > > > object name extends RequestVar("")
>
> > > > > > //someCode
>
> > > > > > def submit() { //validation would happen here }
>
> > > > > > bind("myobject", xhtml, "name" ->
> > > > > >   SHtml.text(name.is, name(_),
> > > > > > ("class","dependsOnTheValidationResult"),
> > > > > >   "submit" -> SHtml.submit("submit", submit)
> > > > > > )
>
> > > > > > My problem is, that the binding to the form happens at the same time
> > > > > > as the binding to the request vars. So it seems like there is no
> > > > > > simple way to:
>
> > > > > > 1. read the vars
> > > > > > 2. bind them to an object
> > > > > > 3. validate the object
> > > > > > 4. bind the validation result to the css attributes of the elements
>
> > > > > > AND: This should only happen when the user submits. Because there is
> > > > > > no need to validate when the user hits the page the first time. 
> > > > > > Should
> > > > > > i create 2 pages (one for the first view, one for the validation
> > > > > > cycle, separate binding methods,...). This seems not to be a DRY 
> > > > > > way.
>
> > > > > In fact it is very easy to do this:
>
> > > > > 1. For the function bound to the form fields you onyl accumulate the
> > > > > data and put it in whatever structure you want
> > > > > 2. Do the validation in the submit function
> > > > > 3. You can easily use <lift:msg> built in snippet to show error
> > > > > message near by th fields that failed to validate.
>
> > > > > For Ajax forms you can very easily use JSON forms (http://
> > > > > wiki.liftweb.net/index.php/HowTo_do_use_JSON_forms)
>
> > > > > ... All this of course without using any validations supported by
> > > > > Mapper and Record frameworks.
>
> > > > > > Any suggestions or best practices?
>
> > > > > > thanks in advance

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to