LiftScreen automagically redirecting to '/'

94 views
Skip to first unread message

Aditya Vishwakarma

unread,
Feb 13, 2012, 9:07:28 AM2/13/12
to lif...@googlegroups.com
I have a snippet defined like this. There is no wizard-all.html in templates-hidden. Whenever I click finish Button, the browser is redirected to / from /login.  I also never see the notices.

class UserLogin extends LiftScreen {
  override def screenTop =
  <b>User Login Form </b>

  val username = field("UserName","")
  val pass = password("Password","")
  def finish(){
    S.notice("Got user:" + username)
    S.notice("got password:" + pass)
  }
}

Any ideas? Firebug shows me I am getting a 303 from form post.

Aditya


David Pollak

unread,
Feb 13, 2012, 9:21:49 AM2/13/12
to lif...@googlegroups.com
It's defined behavior.  When the wizard/screen is finished it goes back to the referrer or /


Aditya


--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


Aditya Vishwakarma

unread,
Feb 13, 2012, 9:39:02 AM2/13/12
to lif...@googlegroups.com
Finished means finish() function completes successfully?

Also, how do I get around styling the generated form? My designer has given me a basic css classes and layout but I have no idea how to associate the css with generated Form elements.

Thanks
Aditya

Sören Kress

unread,
Feb 13, 2012, 4:58:21 PM2/13/12
to lif...@googlegroups.com, adi.vis...@gmail.com
Hi,

finish() is defined in LiftScreen as follows:

  protected def finish(): Unit

  protected def doFinish(): JsCmd = {
    validate match {
      case Nil =>
        val snapshot = createSnapshot
        PrevSnapshot.set(Full(snapshot))
        finish()
        redirectBack()

      case xs => {
        S.error(xs)
        if (ajaxForms_?) {
          SetHtml(FormGUID, renderHtml())
        } else {
          Noop
        }
      }
    }
  }

To answer your question: finish() doesn't return anything, so you cannot return errors. Errors have to be returned during validation. If no validation errors occur, then finish() and redirectBack() are called.

If anything happens during finish() (e.g. concurrent modification error from the database), you can try to work around that in redirectBack():

  protected def redirectBack(): JsCmd = {
    if (ajaxForms_?) {
      AjaxOnDone.get
    } else {
      S.seeOther(Referer.get)
    }
  }

If you use AJAX, then you can simply send JS commands, e.g. exchange an area of HTML and display a success message, or send a redirect. If you set AjaxOnDone to a JS no-op, then nothing happens. I.e. the user stays on the form. (Though I don't know if there are any negative side effects happening during the finish process such that it would not be a good idea to stay on the form ...) I.e. in the case of an error during finish() you can set AjaxOnDone to a noop.

For non-AJAX forms you would have to override redirectBack() or doFinish() to circumvent redirecting after errors in finish().

If you want to have more freedom in you form layout you should definitely take a look at https://github.com/pbrant/lift-liftscreen-css-binding. I'm using it for my LiftScreens and it works great.

Best regards
Soeren

Aditya Vishwakarma

unread,
Feb 16, 2012, 8:06:01 AM2/16/12
to lif...@googlegroups.com
Thanks for the detailed reponse. I think CSSLiftScreen is being worked on for 2.5 release. Will probably roll custom snippets till then.

Aditya Vishwakarma
Reply all
Reply to author
Forward
0 new messages