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

Attachment: pgpMvTKeojjrI.pgp
Description: PGP signature

Reply via email to