I can answer b) -- S.param("image").flatMap(asLong)

asLong comes from BasicTypesHelpers.

-Ross

On Jan 4, 2010, at 4:42 PM, Jim Wise wrote:

>
> So, in my endless retweaking of this code, getting better (and  
> learning
> more lift) on each pass, I've got a rewrite rule like this
>
>       case RewriteRequest(ParsePath("image" :: image :: Nil, _, _,  
> _), _, _) =>
>         RewriteResponse("viewImage" :: Nil, Map("image" -> image))
>
> which is (eventually) handled by a snippet like this:
>
>  def doShowOne(in: NodeSeq): NodeSeq =
>    S.param("image").map(_.toLong) match {
>      case Full(selected) =>
>        ImageInfo.findByKey(selected) match {
>          case Full(i) =>
>            bind(...)
>          case _ =>
>            S.error("No such image!")
>        }
>      case _ =>
>        S.redirectTo("/images")
>    }
>
> Which works well if the referenced path component is the id of an
> existing image, or of a nonexistent image -- and throws an exception  
> if
> the last path component can't be parsed as a long.
>
> I can catch the exception, of course, but I kinda feel there must be a
> cleaner way to do this -- either by not matching in the rewriting PF  
> if
> the positional paramter "image" is not parseable as a long, or by  
> making
> this another layer of casing in the snippet.
>
> So, two questions:
>
>  a.) is there an idiom for this?
>
>  b.) is there a good way to test if a String (or better, a Box 
> [String])
>  is convertable toLong without a try/catch?
>
> Thanks again,
> -- 
>                               Jim Wise
>                               jw...@draga.com

--

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


Reply via email to