StatefulSnippet doesn't really want to remember its state.

43 views
Skip to first unread message

Vladislav Dorokhin

unread,
Apr 25, 2012, 2:48:57 AM4/25/12
to lif...@googlegroups.com
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>

Diego Medina

unread,
Apr 25, 2012, 4:27:34 AM4/25/12
to lif...@googlegroups.com
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

Vladislav Dorokhin

unread,
Apr 26, 2012, 3:50:21 AM4/26/12
to lif...@googlegroups.com
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!
Message has been deleted

Diego Medina

unread,
May 2, 2012, 10:47:49 AM5/2/12
to lif...@googlegroups.com
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)
>> )
>
>
Reply all
Reply to author
Forward
0 new messages