[Lift] Screen-specific function before nextScreen in Wizard

84 views
Skip to first unread message

Jones

unread,
Oct 25, 2012, 11:52:08 AM10/25/12
to lif...@googlegroups.com
Hello,

I am using persistence in a Wizard, and I am editing a specific entity "Entity1" in a screen "Screen1". Before going to "Screen2", I would like to call "Entity1.save()" (I am using Mapper). But postFinish() and finish() both are executed at the end of the main wizard. How can I bind a function to the end of a chosen screen?

Thanks in advance, 
Jones

David Pollak

unread,
Oct 25, 2012, 11:56:40 AM10/25/12
to lif...@googlegroups.com
THere's a finish() method on each screen as well.

--
--
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
 
 
 



--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net


Jones

unread,
Oct 25, 2012, 12:45:25 PM10/25/12
to lif...@googlegroups.com
Yes, there is. But from my observations, I believe it is not called before the end of the wizard, is it? What if I want to save something in the database between Screen1 and Screen2? 

Thanks for your help, 
Jones

Jones

unread,
Oct 27, 2012, 8:50:53 AM10/27/12
to lif...@googlegroups.com
Hello, 

sorry to come back on this, but I still cannot find a solution. Here is my code:

object addEntryWizard extends Wizard {
  object complete extends WizardVar(false)
  val prodScreen = new Screen {
    object prod extends WizardVar(Product.find(1) openOr Product.create)
    addFields(() => prod.name)
    val customers = Customer.findAll.map(_.name.is) // TODO: more intelligent autocomplete...                                                                                          
 
    val customer_field = new Field {
      type ValueType = String
      override def name = "Customer"
      override implicit def manifest = buildIt[String]
      override def default = ""
      override def toForm: Box[NodeSeq] = AutoComplete("", (current:String, limit:Int) => customers.filter(_.toLowerCase.startsWith(current.toLowerCase)), x => println("done" + x))
    }
    override def nextScreen = {
      Customer.find(By(Customer.name, "test")) match {
        case Empty => println("empty")
        case Full(_) => println("full")
      }
      customerScreen
    }
    override def finish() {
    }
  }

 The idea here is that before going to the next screen ("customerScreen"), I would like to check if what the user has entered in the form is already existing in the database or not. If it is not, then the user needs to enter it and therefore the screen "customerScreen" will be required. But if it already exists in the database, I don't want to go to this screen.

How can I achieve this? I cannot find a function that is executed after the user has clicked on next but before the next screen...

Sorry for the inconvenience and thanks for your help!
Jones

Jones

unread,
Oct 28, 2012, 9:32:57 AM10/28/12
to lif...@googlegroups.com
Okay, two things here. First of all, I still cannot find a function that is called when "Next" is pressed. 

Second, I realized that I could access a field in "override def nextScreen". Say I had an Int field called "age", I could do:
 
override def nextScreen = if (age.is < 18) parentsScreen else petScreen

But in my example my customer_field customized field cannot be accessed with customer_field.is. Probably because of the autocomplete widget? Does anybody know how I could deal with this? 

Thanks for your help!
Jones

PS: moreover, even if I set "override def editable_? = false", my fields always are editable...

Jones

unread,
Oct 28, 2012, 10:13:08 AM10/28/12
to lif...@googlegroups.com
I read the implementation of wizard and eventually found some elements. 

One can override those functions: transitionIntoFrom(from: Box[Screen]), transitionOutOfTo(to: Box[Screen]), localSetup(). 

When "Next" is pressed, localSetup() of the next screen is called first, then transitionOutOfTo, then transitionIntoFrom. 

Sorry for the inconvenience then, I missed it in the API documentation (if we don't "open" the full description of the transitionX functions, they only speak about notifications and it was not clear to me).

I still could not lock a field (editable_? = false is simply ignored) and my integration of Autocomplete doesn't work with the screens.

Anyway, sorry for those unanswered e-mails.

Jones

unread,
Oct 28, 2012, 12:03:20 PM10/28/12
to lif...@googlegroups.com
I read the implementation of wizard and eventually found some elements. 

One can override those functions: transitionIntoFrom(from: Box[Screen]), transitionOutOfTo(to: Box[Screen]), localSetup(). 

When "Next" is pressed, localSetup() of the next screen is called first, then transitionOutOfTo, then transitionIntoFrom. 

Sorry for the inconvenience then, I missed it in the API documentation (if we don't "open" the full description of the transitionX functions, they only speak about notifications and it was not clear to me).

I still could not lock a field (editable_? = false is simply ignored) and my integration of Autocomplete doesn't work with the screens (it is simply ignored by the wizard actually). 

Anyway, sorry for all those questions


On Sun, Oct 28, 2012 at 2:32 PM, Jones <mistic....@gmail.com> wrote:

David Pollak

unread,
Oct 29, 2012, 2:27:17 PM10/29/12
to lif...@googlegroups.com
The following methods on the Screens can be overridden to detect entry/exit from a screen:


    /**
     * A notification that we are transitioning into
     * this screen.  Override this method to perform
     * some screen-specific actions
     *
     * @param from the screen we're coming from
     */
    def transitionIntoFrom(from: Box[Screen]) {
    }

    /**
     * A notification that we are transitioning out of
     * this screen.  Override this method to perform
     * some screen-specific actions
     *
     * @param to the screen we're transitioning to
     */
    def transitionOutOfTo(to: Box[Screen]) {
Reply all
Reply to author
Forward
0 new messages