[Lift] dealing with http parameters

3 views
Skip to first unread message

Lukasz Kuczera

unread,
Apr 25, 2010, 2:41:09 AM4/25/10
to Lift
Hi Folks. How do you deal with something like:

val price:BigDecimal = try { S.param("price").map(BigDecimal(_))
openOr -1 }
catch { case e: NumberFormatException => -1 }

val tax = try { S.param("tax").map(_.toInt) openOr -1 }
catch { case e: NumberFormatException => -1 }

I would like to get rid of those nasty exceptions.

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

Marius

unread,
Apr 25, 2010, 5:25:08 AM4/25/10
to Lift
You could try MetaRecord.fromReq .. it will populate your Record based
on the request parameters. You could also apply validators etc.

or something like:

val price:BigDecimal = tryo { S.param("price").map(BigDecimal(_)) }
openOr -1

Marius

David Pollak

unread,
Apr 25, 2010, 8:46:14 AM4/25/10
to lif...@googlegroups.com
You might also want to take a look at Helpers.asInt, asLong, etc.

And for you extractor fans in the audience:

case "api" :: "thing" :: Helpers.AsInt(id) :: _ => ...

Thanks,

David
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

Marius

unread,
Apr 25, 2010, 11:05:06 AM4/25/10
to Lift
The extractors are wicked cool ;)

On Apr 25, 3:46 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com >
> > .
> > > For more options, visit this group athttp://
> > groups.google.com/group/liftweb?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Lift" group.
> > To post to this group, send email to lif...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > liftweb+u...@googlegroups.com<liftweb%2Bunsu...@googlegroups.com >
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/liftweb?hl=en.
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890
> Follow me:http://twitter.com/dpp
> Surf the harmonics
>
> --
> You received this message because you are subscribed to the Google Groups "Lift" group.
> To post to this group, send email to lif...@googlegroups.com.
> To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.

Lukasz Kuczera

unread,
Apr 25, 2010, 3:39:22 PM4/25/10
to Lift
Thanks Guys, will tryo your stuff ;)

Timothy Perrett

unread,
Apr 25, 2010, 6:02:55 PM4/25/10
to lif...@googlegroups.com
Yeah this is pretty sweet!
Reply all
Reply to author
Forward
0 new messages