[Lift] Re: Showing a Box or Redirecting?

2009-06-01 Thread Bryan.

Thanks, guys.  I've done something similar to what Marius provided.  I
thought about using an implicit, but I did not think it would be
immediately obvious for someone else to realize what was going on in
showA -- without the introduction of some implicit conversion
indicator in my IDE.

Thanks,
Bryan

On Jun 1, 12:10 am, David Pollak 
wrote:
> class SomeSnippet {
>   implicit def boxOpener(in: Box[NodeSeq]): NodeSeq = in openOr
> {S.error("Inactive"); S.redirectTo(S.referer openOr "/")}
>
>   def showA(xhtml: NodeSeq): NodeSeq =
>    for {
>      id <- S.param("id")
>      info <- session1.get(id)
>    } yield bind("foo", xhtml, "thing" -> info.x)
>
> }
>
> The implicit makes the Box[NodeSeq] turn into a NodeSeq or redirects the
> user.
>
> Thanks,
>
> David
>
>
>
> On Sat, May 30, 2009 at 6:12 PM, Bryan  wrote:
>
> > If Foo has 5 methods that I need to show in a Snippet (scattered
> > throughout the template), what's a good way to S.error("inactive");
> > S.redirectTo("/") whenever Box[Foo] cannot be opened because it is not
> > Full, without having to write a bunch of boiler plate code for each of
> > the show methods I have defined below.
>
> > class SomeSnippet {
> >  val foo: Box[Foo] = tryo(session1.get(S.param("id").getOrElse("")))
>
> >  def showA(xhtml: NodeSeq): NodeSeq = ...
> >  def showB(xhtml: NodeSeq): NodeSeq = ...
> >  def showC(xhtml: NodeSeq): NodeSeq = ...
> >  def showD(xhtml: NodeSeq): NodeSeq = ...
> >  def showE(xhtml: NodeSeq): NodeSeq = ...
> > }
>
> > Thanks,
> > Bryan
>
> --
> Lift, the simply functional web frameworkhttp://liftweb.net
> Beginning Scalahttp://www.apress.com/book/view/1430219890
> Follow me:http://twitter.com/dpp
> Git some:http://github.com/dpp
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---



[Lift] Re: Showing a Box or Redirecting?

2009-05-31 Thread David Pollak
class SomeSnippet {
  implicit def boxOpener(in: Box[NodeSeq]): NodeSeq = in openOr
{S.error("Inactive"); S.redirectTo(S.referer openOr "/")}

  def showA(xhtml: NodeSeq): NodeSeq =
   for {
 id <- S.param("id")
 info <- session1.get(id)
   } yield bind("foo", xhtml, "thing" -> info.x)
}

The implicit makes the Box[NodeSeq] turn into a NodeSeq or redirects the
user.

Thanks,

David

On Sat, May 30, 2009 at 6:12 PM, Bryan  wrote:

>
> If Foo has 5 methods that I need to show in a Snippet (scattered
> throughout the template), what's a good way to S.error("inactive");
> S.redirectTo("/") whenever Box[Foo] cannot be opened because it is not
> Full, without having to write a bunch of boiler plate code for each of
> the show methods I have defined below.
>
> class SomeSnippet {
>  val foo: Box[Foo] = tryo(session1.get(S.param("id").getOrElse("")))
>
>  def showA(xhtml: NodeSeq): NodeSeq = ...
>  def showB(xhtml: NodeSeq): NodeSeq = ...
>  def showC(xhtml: NodeSeq): NodeSeq = ...
>  def showD(xhtml: NodeSeq): NodeSeq = ...
>  def showE(xhtml: NodeSeq): NodeSeq = ...
> }
>
> Thanks,
> Bryan
> >
>


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

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---



[Lift] Re: Showing a Box or Redirecting?

2009-05-31 Thread marius d.

class SomeSnippet {
  val foo: Box[Foo] = tryo(session1.get(S.param("id").getOrElse
(""))) // But I think with this code you'll always get a Full Box due
to getOrElse ?

  def render(func: foo  => NodeSeq) = foo.map(l => func(l)) openOr
(your code in case foo is empty and potentially return NodeSeq.Empty)

  def showA(xhtml: NodeSeq): NodeSeq = render {
myFoo => ...
  }
  def showB(xhtml: NodeSeq): NodeSeq = render {
myFoo => ...
  }.
  def showC(xhtml: NodeSeq): NodeSeq = render {
myFoo => ...
  }
  def showD(xhtml: NodeSeq): NodeSeq = render {
myFoo => ...
  }
  def showE(xhtml: NodeSeq): NodeSeq = render {
myFoo => ...
  }

}

On May 31, 4:40 am, "Bryan."  wrote:
> I guess I should just have def showFoo(xhtml: NodeSeq) and use bind to
> render A, B, C, D, and E.
>
> --Bryan
>
> On May 30, 9:12 pm, Bryan  wrote:
>
> > If Foo has 5 methods that I need to show in a Snippet (scattered
> > throughout the template), what's a good way to S.error("inactive");
> > S.redirectTo("/") whenever Box[Foo] cannot be opened because it is not
> > Full, without having to write a bunch of boiler plate code for each of
> > the show methods I have defined below.
>
> > class SomeSnippet {
> >   val foo: Box[Foo] = tryo(session1.get(S.param("id").getOrElse("")))
>
> >   def showA(xhtml: NodeSeq): NodeSeq = ...
> >   def showB(xhtml: NodeSeq): NodeSeq = ...
> >   def showC(xhtml: NodeSeq): NodeSeq = ...
> >   def showD(xhtml: NodeSeq): NodeSeq = ...
> >   def showE(xhtml: NodeSeq): NodeSeq = ...
>
> > }
>
> > Thanks,
> > Bryan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---



[Lift] Re: Showing a Box or Redirecting?

2009-05-30 Thread Bryan.

I guess I should just have def showFoo(xhtml: NodeSeq) and use bind to
render A, B, C, D, and E.

--Bryan

On May 30, 9:12 pm, Bryan  wrote:
> If Foo has 5 methods that I need to show in a Snippet (scattered
> throughout the template), what's a good way to S.error("inactive");
> S.redirectTo("/") whenever Box[Foo] cannot be opened because it is not
> Full, without having to write a bunch of boiler plate code for each of
> the show methods I have defined below.
>
> class SomeSnippet {
>   val foo: Box[Foo] = tryo(session1.get(S.param("id").getOrElse("")))
>
>   def showA(xhtml: NodeSeq): NodeSeq = ...
>   def showB(xhtml: NodeSeq): NodeSeq = ...
>   def showC(xhtml: NodeSeq): NodeSeq = ...
>   def showD(xhtml: NodeSeq): NodeSeq = ...
>   def showE(xhtml: NodeSeq): NodeSeq = ...
>
> }
>
> Thanks,
> Bryan
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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
-~--~~~~--~~--~--~---