Help me understand a dynamic selectbox

58 views
Skip to first unread message

Tyler Eaves

unread,
Jun 5, 2012, 1:25:44 PM6/5/12
to lif...@googlegroups.com
So, I have an array of objects, that I want to use to populate a select box.

The object is a simple class, just a holder for it's construction params, called Desk.

Here is my snippet code, which doesn't work. I've tried selectObj and selectElem. Code refuses to compile, saying something about missing parameters or some 5 page long error about a missing implicit, Settable, or something. 


object LoadMediaWidget {

  

  private object theUpload extends RequestVar[Box[FileParamHolder]](Empty)

  private object grayscale extends RequestVar(false);

  private object desk extends RequestVar[Box[Desk]](Empty);

  

  val desks : List[Desk] = List(new Desk("PhotosGDR","/IntelliTune/Input/NewsDB_PhotosGDR", "photowirenews","/PhotosGDR/data","%"));

  

  def render(xhtml: NodeSeq) : NodeSeq = {

    if (S.get_?) bind("ul",chooseTemplate("choose","get",xhtml), 

        "file_upload" -> fileUpload(ul => theUpload(Full(ul))),

        "grayscale" -> SHtml.checkboxElem(grayscale),

        "desk" -> SHtml.selectElem(desks,desk)

    )

    else xhtml

  }

}

Diego Medina

unread,
Jun 5, 2012, 11:26:39 PM6/5/12
to lif...@googlegroups.com
Hi,

So you are using the "old style" binding. It may be a better idea to
go for the "new way" which is CSS Transformation[1]
Now, what do you mean by dynamic?

If you could put together a sample application [2], I can try to make
it do what you want (once I figure out what you are asking :) )


[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

Tyler Eaves

unread,
Jun 6, 2012, 9:29:56 AM6/6/12
to lif...@googlegroups.com
Dynamic in the sense that the list will be filtered per visitor. Basically, one val of the class instance is a reg.exp that will be matched against the requet's IP address - the idea is you get different options based on which subnet of our internal network you're on.  That I can handle...I just need to figure out how to bind it so the selectbox gets populated, and the result ends up in my requestvar.

As far as syntax - I'm still very much learning - trying to follow the format from the lift demo app source code.

Diego Medina

unread,
Jun 6, 2012, 9:43:37 AM6/6/12
to lif...@googlegroups.com
Alright, so, the simplest way to have a select drop down on a page is
something lime this:


class MySnippet {
def render = {

val options= Seq(
("desk1", "My nice name1 heere"),
("desk2", "My nice name2 heere"),
("desk3", "My nice name3 heere")
)

"#mySelectElement" #> SHtml.select(options, Full("desk2"), (s) =>
println("You selected " + s) )
}

}


and your html looks like:


<div data-lift="MySnippet" >
<span id="mySelectElement"></span>
</div>


note that I'm using a span instead of a proper select html element,
this is because by using:

"#mySelectElement" #> SHtml.select(options, Full("desk2"), (s) =>
println("You selected " + s) )

Lift replaces the whole element for the "right thing"

Let me know if that is clear or not.

About the demo site, I have it on my list of things to do, to upgrade
the sample code to use the CSS selector, instead of the bind method,
so I would recommend you loopk at this free book:
http://simply.liftweb.net/
which has more updated information.
The wiki is also a good place to find info
http://www.assembla.com/spaces/liftweb/wiki

Regards,

Diego

Tyler Eaves

unread,
Jun 6, 2012, 10:44:08 AM6/6/12
to lif...@googlegroups.com
Ok, so that got me pointed in the right direction, and I have something sort of working.

I tried to convert to CSS binding selections, but how can I use this with the choose construct?

Would I be better of using a seperate snippet for the processing logic?

How would that interact with my requestvars that are bound to my form controls?

Current code here:

Diego Medina

unread,
Jun 6, 2012, 11:03:30 AM6/6/12
to lif...@googlegroups.com
On Wed, Jun 6, 2012 at 10:44 AM, Tyler Eaves <tyl...@gmail.com> wrote:
> Ok, so that got me pointed in the right direction, and I have something sort
> of working.

nice!


>
> I tried to convert to CSS binding selections, but how can I use this with
> the choose construct?


which choose construct?

>
> Would I be better of using a seperate snippet for the processing logic?

you can keep it in the same class or move it to a different class.

>
> How would that interact with my requestvars that are bound to my form
> controls?

You can access the same RequestVar from different snippets, in fact,
to pass info from one snippet to another you normally use RequestVars,
but your code has them inside the object LoadMediaWidget

change your code so that LoadMediaWidget is a class, then move the
requestVars outside the class and remove the private label on them.

Regards,

Diego

Antonio Salazar Cardozo

unread,
Jun 7, 2012, 12:18:47 AM6/7/12
to lif...@googlegroups.com
For choose, you may want to look at the ^^ and ^* replacement rules listed at http://simply.liftweb.net/index-7.10.html#toc-Section-7.10 .
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages