StatefulSnippet doesn't really want to remember its state.

Showing 1-5 of 5 messages
StatefulSnippet doesn't really want to remember its state. Vladislav Dorokhin 4/24/12 11:48 PM
Hi everyone. I cannot figure out what is wrong with code below. It just keeps printing  the initial values (through S.error). Can someone tell me what I am missing? Thanks in advance. Please disregard code duplication, I will get rid of it as soon as I get this code to work. 

class AnalyticsForm extends StatefulSnippet {
  private var timePeriod = ""
  private var statType: String = ""
  private var partners: List[String] = Nil

  def dispatch = {
    case _ => bindForm _
  }

  def processQuery() = {
    S.error(("Time period id: %s\n " +
      "Statistics type id: %s" +
      "Partners list of ids: %s" ).format(timePeriod, statType, partners))
  }

  def bindForm(xhtml: NodeSeq): NodeSeq = {

    val possiblePartners: List[(String, String)] = MarketingPartner.findAll(OrderBy(MarketingPartner.id, Ascending))
      .map(x => (x.id.toString, x.title.toString))
    val timePeriodOptions: List[(String, String)] = promotePairStringsFrom("time_period")
    val statTypeOptions: List[(String, String)] = promotePairStringsFrom("type")

    bind("entry", xhtml,
      "time_period" -> SHtml.select(timePeriodOptions, S.param("time_period"), timePeriod = _, "name" -> "time_period"),
      "type" -> SHtml.select(statTypeOptions, S.param("type"), statType = _, "name" -> "type"),
      "partner" -> SHtml.multiSelect(("-1", "All") :: possiblePartners, S.params("partner"), partners = _, "name" -> "partner"),
      "submit" -> SHtml.submit("Update", processQuery)
    )

  }
...
}

The part of index.html which makes use of the snippet: 

    <div>
        <lift:AnalyticsForm form="POST">
            <div class="span-4">
                <span><strong>Choose time period:</strong></span><br/>
                <entry:time_period/>
            </div>
            <div class="span-6">
                <span><strong>Statistics type</strong></span><br/>
                <entry:type/>
            </div>
            <div class="span-3">
                <span><strong>Partners</strong></span>
                <entry:partner/>
            </div>
            <div style="float:right"><entry:submit/></div>
        </lift:AnalyticsForm>
    </div>

Re: [Lift] StatefulSnippet doesn't really want to remember its state. fmpwizard 4/25/12 1:27 AM
Nothing sticks out as totally wrong there (but then again, it's 4 am here)

how about:

1- Change from bind to css transformation [1] (not necessary, but css
transformation is the way to go these days)
2- Change the SHtml.select for SHtml.text , just to make it simpler
3- If that still does not work, put together a sample app[2] and I'll
help you get it working


[1]http://simply.liftweb.net/index-7.10.html
[2]https://www.assembla.com/wiki/show/liftweb/Posting_example_code

Regards,

  Diego

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

--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

Re: [Lift] StatefulSnippet doesn't really want to remember its state. Vladislav Dorokhin 4/26/12 12:50 AM
Hi Diego, 

I found out what was. Explicit name setting prevented some internal plumbing from working. When I removed the parts of code marked red, everything started rolling as it was supposed to. Thank you!
unk...@googlegroups.com 5/2/12 5:28 AM <This message has been deleted.>
Re: [Lift] StatefulSnippet doesn't really want to remember its state. fmpwizard 5/2/12 7:47 AM
On Thu, Apr 26, 2012 at 3:50 AM, Vladislav Dorokhin <ado...@gmail.com> wrote:
> Hi Diego,
>
> I found out what was. Explicit name setting prevented some internal plumbing
> from working. When I removed the parts of code marked red, everything
> started rolling as it was supposed to. Thank you!

I'm glad everything is working now.

  Diego


>
>> bind("entry", xhtml,
>>       "time_period" -> SHtml.select(timePeriodOptions,
>> S.param("time_period"), timePeriod = _, "name" -> "time_period"),
>>       "type" -> SHtml.select(statTypeOptions, S.param("type"), statType =
>> _, "name" -> "type"),
>>       "partner" -> SHtml.multiSelect(("-1", "All") :: possiblePartners,
>> S.params("partner"), partners = _, "name" -> "partner"),
>>       "submit" -> SHtml.submit("Update", processQuery)
>> )
>
>