[Lift] Re: Box and bind

2009-09-08 Thread Naftoli Gugenheim

There should be implicits that allow you to bind to a Box of a NodeSeq, so you 
can bind to prodBox.map(_.toForm). Otherwise bind to 
prodBox.map(_.toForm).openOr(NodeSeq.Empty) etc.

-
José Maríajosemariar...@gmail.com wrote:


Hi.

Boxes are giving me a hard time.

Say you have a model of a Product.

If I've a snippet that retrieves a Product from the DB:

val product : Box[Product] = Product.find(2)

And now I want to bind product with bind(),  product is a Box and it
can be empty, how can I bind something that doesn't exists? You have
to return a NodeSeq in a snippet. What should my code must do?

Best regards.


--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread Ross Mellgren

Well it depends on precisely what you want. If you want your snippet  
to become empty if the product is not there, try:

productBox.map(product = {
   bind(product, ns, ...)
}).openOr(NodeSeq.Empty)

If you want only certain bind positions empty, do the same thing  
inside the bind:

bind(proudct, ns,
  field - productBox.map(p = Text(p.field.toString)).openOr 
(NodeSeq.Empty),
  ...)

map is of course just one of the (simpler) operations you can do with  
a Box, there's more complicated stuff if you need other variants.

-Ross

On Sep 8, 2009, at 3:06 PM, José María wrote:


 Hi.

 Boxes are giving me a hard time.

 Say you have a model of a Product.

 If I've a snippet that retrieves a Product from the DB:

 val product : Box[Product] = Product.find(2)

 And now I want to bind product with bind(),  product is a Box and it
 can be empty, how can I bind something that doesn't exists? You have
 to return a NodeSeq in a snippet. What should my code must do?

 Best regards.
 


--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread José María

That's my code:

val product = Product.find(id)


producto.map(product =
  bind(product, xhtml,
   url_enlace -- /product/ + product.id.toString ,
  )
   ).openOr(NodeSeq.Empty)
}

and I get this error:

[INFO] use java command with args in file forced : false
/usr/home/josemaria/src/lift/helloworld/src/main/scala/demo/helloworld/
snippet/Portada.scala:55: error: overloaded method value bind with
alternatives (String,net.liftweb.util.Box[(scala.xml.NodeSeq) =
scala.xml.NodeSeq],net.liftweb.util.Box[(scala.xml.PrefixedAttribute)
=
scala.xml.MetaData],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
scala.xml.NodeSeq and
(String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
scala.xml.NodeSeq cannot be applied to
(java.lang.String,scala.xml.NodeSeq,java.lang.String,java.lang.String,net.liftweb.util.Helpers.BindParam,net.liftweb.util.Helpers.BindParam)
  bind(producto, xhtml,
  ^
one error found



What's wrong?



On Sep 8, 7:13 pm, Ross Mellgren dri...@gmail.com wrote:
 Well it depends on precisely what you want. If you want your snippet  
 to become empty if the product is not there, try:

 productBox.map(product = {
    bind(product, ns, ...)

 }).openOr(NodeSeq.Empty)

 If you want only certain bind positions empty, do the same thing  
 inside the bind:

 bind(proudct, ns,
       field - productBox.map(p = Text(p.field.toString)).openOr
 (NodeSeq.Empty),
       ...)

 map is of course just one of the (simpler) operations you can do with  
 a Box, there's more complicated stuff if you need other variants.

 -Ross

 On Sep 8, 2009, at 3:06 PM, José María wrote:



  Hi.

  Boxes are giving me a hard time.

  Say you have a model of a Product.

  If I've a snippet that retrieves a Product from the DB:

  val product : Box[Product] = Product.find(2)

  And now I want to bind product with bind(),  product is a Box and it
  can be empty, how can I bind something that doesn't exists? You have
  to return a NodeSeq in a snippet. What should my code must do?

  Best regards.


--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread Ross Mellgren

Because the compiler interpret your expression as you expect. Instead  
of:

url_enlace - (/product/ + product.id.toString)

which is what you wanted, it got:

(url_enlace - /product/) + product.id.toString)

which it can do because it can take an arbitrary object:

(url_enlace - /product/): ABindParam
or (the other implicit -)
(url_enlace - /product/): Tuple2[String, String]

and convert them to strings. Of course, once it converts to string, it  
won't fit in bind()'s argument list and so it gave you the could not  
find overload error.

Honestly I'm a bit fuzzy on Scala's operator precedence behavior, I  
think if I recall you can't set precedence, it comes pre-set on all  
the standard operators like + / -, etc.

-Ross


On Sep 8, 2009, at 3:42 PM, José María wrote:


 It worked when I put the () around the bind param

 and the question is ... why?




 On Sep 8, 7:35 pm, Ross Mellgren dri...@gmail.com wrote:
 So that doesn't seem to be a box-related thing so much as a bind
 argument related thing, probably because you have a precedence
 problem... try:

 producto.map(product =
bind(product, xhtml,
 url_enlace - (/product/ + product.id.toString),
)
 ).openOr(NodeSeq.Empty)

 Also, FYI, you have val product = Product.find(id), but then map over
 producto. I presume either producto is coming from somewhere else  
 (and
 val product is being shadowed inside the map) or that you pasted not
 exactly what you're compiling.

 -Ross

 On Sep 8, 2009, at 3:25 PM, José María wrote:



 That's my code:

val product = Product.find(id)

producto.map(product =
  bind(product, xhtml,
   url_enlace -- /product/ + product.id.toString ,
  )
   ).openOr(NodeSeq.Empty)
}

 and I get this error:

 [INFO] use java command with args in file forced : false
 /usr/home/josemaria/src/lift/helloworld/src/main/scala/demo/
 helloworld/
 snippet/Portada.scala:55: error: overloaded method value bind with
 alternatives (String,net.liftweb.util.Box[(scala.xml.NodeSeq) =
 scala.xml.NodeSeq],net.liftweb.util.Box 
 [(scala.xml.PrefixedAttribute)
 =
 scala.xml.MetaData
 ],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
 scala.xml.NodeSeq and
 (String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
 scala.xml.NodeSeq cannot be applied to
 (java.lang.String
 ,scala.xml.NodeSeq
 ,java.lang.String
 ,java.lang.String
 ,net.liftweb.util.Helpers.BindParam
 ,net.liftweb.util.Helpers.BindParam)
  bind(producto, xhtml,
  ^
 one error found

 What's wrong?

 On Sep 8, 7:13 pm, Ross Mellgren dri...@gmail.com wrote:
 Well it depends on precisely what you want. If you want your  
 snippet
 to become empty if the product is not there, try:

 productBox.map(product = {
bind(product, ns, ...)

 }).openOr(NodeSeq.Empty)

 If you want only certain bind positions empty, do the same thing
 inside the bind:

 bind(proudct, ns,
   field - productBox.map(p = Text(p.field.toString)).openOr
 (NodeSeq.Empty),
   ...)

 map is of course just one of the (simpler) operations you can do  
 with
 a Box, there's more complicated stuff if you need other variants.

 -Ross

 On Sep 8, 2009, at 3:06 PM, José María wrote:

 Hi.

 Boxes are giving me a hard time.

 Say you have a model of a Product.

 If I've a snippet that retrieves a Product from the DB:

 val product : Box[Product] = Product.find(2)

 And now I want to bind product with bind(),  product is a Box
 and it
 can be empty, how can I bind something that doesn't exists? You  
 have
 to return a NodeSeq in a snippet. What should my code must do?

 Best regards.


 


--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread Naftoli Gugenheim

Operators starting with - and + have the same precendence so they are combined 
left to right. Thus you are concatenating a BindParam with a String, returning 
a String.

-
José Maríajosemariar...@gmail.com wrote:


It worked when I put the () around the bind param

and the question is ... why?




On Sep 8, 7:35 pm, Ross Mellgren dri...@gmail.com wrote:
 So that doesn't seem to be a box-related thing so much as a bind  
 argument related thing, probably because you have a precedence  
 problem... try:

 producto.map(product =
    bind(product, xhtml,
         url_enlace - (/product/ + product.id.toString),
        )
 ).openOr(NodeSeq.Empty)

 Also, FYI, you have val product = Product.find(id), but then map over  
 producto. I presume either producto is coming from somewhere else (and  
 val product is being shadowed inside the map) or that you pasted not  
 exactly what you're compiling.

 -Ross

 On Sep 8, 2009, at 3:25 PM, José María wrote:



  That's my code:

     val product = Product.find(id)

     producto.map(product =
       bind(product, xhtml,
            url_enlace -- /product/ + product.id.toString ,
           )
                ).openOr(NodeSeq.Empty)
     }

  and I get this error:

  [INFO] use java command with args in file forced : false
  /usr/home/josemaria/src/lift/helloworld/src/main/scala/demo/
  helloworld/
  snippet/Portada.scala:55: error: overloaded method value bind with
  alternatives (String,net.liftweb.util.Box[(scala.xml.NodeSeq) =
  scala.xml.NodeSeq],net.liftweb.util.Box[(scala.xml.PrefixedAttribute)
  =
  scala.xml.MetaData
  ],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq and
  (String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq cannot be applied to
  (java.lang.String
  ,scala.xml.NodeSeq
  ,java.lang.String
  ,java.lang.String
  ,net.liftweb.util.Helpers.BindParam
  ,net.liftweb.util.Helpers.BindParam)
       bind(producto, xhtml,
       ^
  one error found

  What's wrong?

  On Sep 8, 7:13 pm, Ross Mellgren dri...@gmail.com wrote:
  Well it depends on precisely what you want. If you want your snippet
  to become empty if the product is not there, try:

  productBox.map(product = {
     bind(product, ns, ...)

  }).openOr(NodeSeq.Empty)

  If you want only certain bind positions empty, do the same thing
  inside the bind:

  bind(proudct, ns,
        field - productBox.map(p = Text(p.field.toString)).openOr
  (NodeSeq.Empty),
        ...)

  map is of course just one of the (simpler) operations you can do with
  a Box, there's more complicated stuff if you need other variants.

  -Ross

  On Sep 8, 2009, at 3:06 PM, José María wrote:

  Hi.

  Boxes are giving me a hard time.

  Say you have a model of a Product.

  If I've a snippet that retrieves a Product from the DB:

  val product : Box[Product] = Product.find(2)

  And now I want to bind product with bind(),  product is a Box  
  and it
  can be empty, how can I bind something that doesn't exists? You have
  to return a NodeSeq in a snippet. What should my code must do?

  Best regards.




--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread Naftoli Gugenheim

Precedence is determined by the first character of an operator.

-
Ross Mellgrendri...@gmail.com wrote:


Because the compiler interpret your expression as you expect. Instead  
of:

url_enlace - (/product/ + product.id.toString)

which is what you wanted, it got:

(url_enlace - /product/) + product.id.toString)

which it can do because it can take an arbitrary object:

(url_enlace - /product/): ABindParam
or (the other implicit -)
(url_enlace - /product/): Tuple2[String, String]

and convert them to strings. Of course, once it converts to string, it  
won't fit in bind()'s argument list and so it gave you the could not  
find overload error.

Honestly I'm a bit fuzzy on Scala's operator precedence behavior, I  
think if I recall you can't set precedence, it comes pre-set on all  
the standard operators like + / -, etc.

-Ross


On Sep 8, 2009, at 3:42 PM, José María wrote:


 It worked when I put the () around the bind param

 and the question is ... why?




 On Sep 8, 7:35 pm, Ross Mellgren dri...@gmail.com wrote:
 So that doesn't seem to be a box-related thing so much as a bind
 argument related thing, probably because you have a precedence
 problem... try:

 producto.map(product =
bind(product, xhtml,
 url_enlace - (/product/ + product.id.toString),
)
 ).openOr(NodeSeq.Empty)

 Also, FYI, you have val product = Product.find(id), but then map over
 producto. I presume either producto is coming from somewhere else  
 (and
 val product is being shadowed inside the map) or that you pasted not
 exactly what you're compiling.

 -Ross

 On Sep 8, 2009, at 3:25 PM, José María wrote:



 That's my code:

val product = Product.find(id)

producto.map(product =
  bind(product, xhtml,
   url_enlace -- /product/ + product.id.toString ,
  )
   ).openOr(NodeSeq.Empty)
}

 and I get this error:

 [INFO] use java command with args in file forced : false
 /usr/home/josemaria/src/lift/helloworld/src/main/scala/demo/
 helloworld/
 snippet/Portada.scala:55: error: overloaded method value bind with
 alternatives (String,net.liftweb.util.Box[(scala.xml.NodeSeq) =
 scala.xml.NodeSeq],net.liftweb.util.Box 
 [(scala.xml.PrefixedAttribute)
 =
 scala.xml.MetaData
 ],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
 scala.xml.NodeSeq and
 (String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
 scala.xml.NodeSeq cannot be applied to
 (java.lang.String
 ,scala.xml.NodeSeq
 ,java.lang.String
 ,java.lang.String
 ,net.liftweb.util.Helpers.BindParam
 ,net.liftweb.util.Helpers.BindParam)
  bind(producto, xhtml,
  ^
 one error found

 What's wrong?

 On Sep 8, 7:13 pm, Ross Mellgren dri...@gmail.com wrote:
 Well it depends on precisely what you want. If you want your  
 snippet
 to become empty if the product is not there, try:

 productBox.map(product = {
bind(product, ns, ...)

 }).openOr(NodeSeq.Empty)

 If you want only certain bind positions empty, do the same thing
 inside the bind:

 bind(proudct, ns,
   field - productBox.map(p = Text(p.field.toString)).openOr
 (NodeSeq.Empty),
   ...)

 map is of course just one of the (simpler) operations you can do  
 with
 a Box, there's more complicated stuff if you need other variants.

 -Ross

 On Sep 8, 2009, at 3:06 PM, José María wrote:

 Hi.

 Boxes are giving me a hard time.

 Say you have a model of a Product.

 If I've a snippet that retrieves a Product from the DB:

 val product : Box[Product] = Product.find(2)

 And now I want to bind product with bind(),  product is a Box
 and it
 can be empty, how can I bind something that doesn't exists? You  
 have
 to return a NodeSeq in a snippet. What should my code must do?

 Best regards.


 




--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread Naftoli Gugenheim

Yup

-
José Maríajosemariar...@gmail.com wrote:


OMG

So, as - begins with - then it has the precedence of the operator
-



On Sep 8, 7:52 pm, Naftoli Gugenheim naftoli...@gmail.com wrote:
 Precedence is determined by the first character of an operator.

 -

 Ross Mellgrendri...@gmail.com wrote:

 Because the compiler interpret your expression as you expect. Instead  
 of:

 url_enlace - (/product/ + product.id.toString)

 which is what you wanted, it got:

 (url_enlace - /product/) + product.id.toString)

 which it can do because it can take an arbitrary object:

 (url_enlace - /product/): ABindParam
 or (the other implicit -)
 (url_enlace - /product/): Tuple2[String, String]

 and convert them to strings. Of course, once it converts to string, it  
 won't fit in bind()'s argument list and so it gave you the could not  
 find overload error.

 Honestly I'm a bit fuzzy on Scala's operator precedence behavior, I  
 think if I recall you can't set precedence, it comes pre-set on all  
 the standard operators like + / -, etc.

 -Ross

 On Sep 8, 2009, at 3:42 PM, José María wrote:



  It worked when I put the () around the bind param

  and the question is ... why?

  On Sep 8, 7:35 pm, Ross Mellgren dri...@gmail.com wrote:
  So that doesn't seem to be a box-related thing so much as a bind
  argument related thing, probably because you have a precedence
  problem... try:

  producto.map(product =
     bind(product, xhtml,
          url_enlace - (/product/ + product.id.toString),
         )
  ).openOr(NodeSeq.Empty)

  Also, FYI, you have val product = Product.find(id), but then map over
  producto. I presume either producto is coming from somewhere else  
  (and
  val product is being shadowed inside the map) or that you pasted not
  exactly what you're compiling.

  -Ross

  On Sep 8, 2009, at 3:25 PM, José María wrote:

  That's my code:

     val product = Product.find(id)

     producto.map(product =
       bind(product, xhtml,
            url_enlace -- /product/ + product.id.toString ,
           )
                ).openOr(NodeSeq.Empty)
     }

  and I get this error:

  [INFO] use java command with args in file forced : false
  /usr/home/josemaria/src/lift/helloworld/src/main/scala/demo/
  helloworld/
  snippet/Portada.scala:55: error: overloaded method value bind with
  alternatives (String,net.liftweb.util.Box[(scala.xml.NodeSeq) =
  scala.xml.NodeSeq],net.liftweb.util.Box
  [(scala.xml.PrefixedAttribute)
  =
  scala.xml.MetaData
  ],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq and
  (String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq cannot be applied to
  (java.lang.String
  ,scala.xml.NodeSeq
  ,java.lang.String
  ,java.lang.String
  ,net.liftweb.util.Helpers.BindParam
  ,net.liftweb.util.Helpers.BindParam)
       bind(producto, xhtml,
       ^
  one error found

  What's wrong?

  On Sep 8, 7:13 pm, Ross Mellgren dri...@gmail.com wrote:
  Well it depends on precisely what you want. If you want your  
  snippet
  to become empty if the product is not there, try:

  productBox.map(product = {
     bind(product, ns, ...)

  }).openOr(NodeSeq.Empty)

  If you want only certain bind positions empty, do the same thing
  inside the bind:

  bind(proudct, ns,
        field - productBox.map(p = Text(p.field.toString)).openOr
  (NodeSeq.Empty),
        ...)

  map is of course just one of the (simpler) operations you can do  
  with
  a Box, there's more complicated stuff if you need other variants.

  -Ross

  On Sep 8, 2009, at 3:06 PM, José María wrote:

  Hi.

  Boxes are giving me a hard time.

  Say you have a model of a Product.

  If I've a snippet that retrieves a Product from the DB:

  val product : Box[Product] = Product.find(2)

  And now I want to bind product with bind(),  product is a Box
  and it
  can be empty, how can I bind something that doesn't exists? You  
  have
  to return a NodeSeq in a snippet. What should my code must do?

  Best regards.




--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread José María

It worked when I put the () around the bind param

and the question is ... why?




On Sep 8, 7:35 pm, Ross Mellgren dri...@gmail.com wrote:
 So that doesn't seem to be a box-related thing so much as a bind  
 argument related thing, probably because you have a precedence  
 problem... try:

 producto.map(product =
    bind(product, xhtml,
         url_enlace - (/product/ + product.id.toString),
        )
 ).openOr(NodeSeq.Empty)

 Also, FYI, you have val product = Product.find(id), but then map over  
 producto. I presume either producto is coming from somewhere else (and  
 val product is being shadowed inside the map) or that you pasted not  
 exactly what you're compiling.

 -Ross

 On Sep 8, 2009, at 3:25 PM, José María wrote:



  That's my code:

     val product = Product.find(id)

     producto.map(product =
       bind(product, xhtml,
            url_enlace -- /product/ + product.id.toString ,
           )
                ).openOr(NodeSeq.Empty)
     }

  and I get this error:

  [INFO] use java command with args in file forced : false
  /usr/home/josemaria/src/lift/helloworld/src/main/scala/demo/
  helloworld/
  snippet/Portada.scala:55: error: overloaded method value bind with
  alternatives (String,net.liftweb.util.Box[(scala.xml.NodeSeq) =
  scala.xml.NodeSeq],net.liftweb.util.Box[(scala.xml.PrefixedAttribute)
  =
  scala.xml.MetaData
  ],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq and
  (String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq cannot be applied to
  (java.lang.String
  ,scala.xml.NodeSeq
  ,java.lang.String
  ,java.lang.String
  ,net.liftweb.util.Helpers.BindParam
  ,net.liftweb.util.Helpers.BindParam)
       bind(producto, xhtml,
       ^
  one error found

  What's wrong?

  On Sep 8, 7:13 pm, Ross Mellgren dri...@gmail.com wrote:
  Well it depends on precisely what you want. If you want your snippet
  to become empty if the product is not there, try:

  productBox.map(product = {
     bind(product, ns, ...)

  }).openOr(NodeSeq.Empty)

  If you want only certain bind positions empty, do the same thing
  inside the bind:

  bind(proudct, ns,
        field - productBox.map(p = Text(p.field.toString)).openOr
  (NodeSeq.Empty),
        ...)

  map is of course just one of the (simpler) operations you can do with
  a Box, there's more complicated stuff if you need other variants.

  -Ross

  On Sep 8, 2009, at 3:06 PM, José María wrote:

  Hi.

  Boxes are giving me a hard time.

  Say you have a model of a Product.

  If I've a snippet that retrieves a Product from the DB:

  val product : Box[Product] = Product.find(2)

  And now I want to bind product with bind(),  product is a Box  
  and it
  can be empty, how can I bind something that doesn't exists? You have
  to return a NodeSeq in a snippet. What should my code must do?

  Best regards.


--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread José María

I adapted the code but not the error, Producto is Product in Spanish.



On Sep 8, 7:35 pm, Ross Mellgren dri...@gmail.com wrote:
 So that doesn't seem to be a box-related thing so much as a bind  
 argument related thing, probably because you have a precedence  
 problem... try:

 producto.map(product =
    bind(product, xhtml,
         url_enlace - (/product/ + product.id.toString),
        )
 ).openOr(NodeSeq.Empty)

 Also, FYI, you have val product = Product.find(id), but then map over  
 producto. I presume either producto is coming from somewhere else (and  
 val product is being shadowed inside the map) or that you pasted not  
 exactly what you're compiling.

 -Ross

 On Sep 8, 2009, at 3:25 PM, José María wrote:



  That's my code:

     val product = Product.find(id)

     producto.map(product =
       bind(product, xhtml,
            url_enlace -- /product/ + product.id.toString ,
           )
                ).openOr(NodeSeq.Empty)
     }

  and I get this error:

  [INFO] use java command with args in file forced : false
  /usr/home/josemaria/src/lift/helloworld/src/main/scala/demo/
  helloworld/
  snippet/Portada.scala:55: error: overloaded method value bind with
  alternatives (String,net.liftweb.util.Box[(scala.xml.NodeSeq) =
  scala.xml.NodeSeq],net.liftweb.util.Box[(scala.xml.PrefixedAttribute)
  =
  scala.xml.MetaData
  ],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq and
  (String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq cannot be applied to
  (java.lang.String
  ,scala.xml.NodeSeq
  ,java.lang.String
  ,java.lang.String
  ,net.liftweb.util.Helpers.BindParam
  ,net.liftweb.util.Helpers.BindParam)
       bind(producto, xhtml,
       ^
  one error found

  What's wrong?

  On Sep 8, 7:13 pm, Ross Mellgren dri...@gmail.com wrote:
  Well it depends on precisely what you want. If you want your snippet
  to become empty if the product is not there, try:

  productBox.map(product = {
     bind(product, ns, ...)

  }).openOr(NodeSeq.Empty)

  If you want only certain bind positions empty, do the same thing
  inside the bind:

  bind(proudct, ns,
        field - productBox.map(p = Text(p.field.toString)).openOr
  (NodeSeq.Empty),
        ...)

  map is of course just one of the (simpler) operations you can do with
  a Box, there's more complicated stuff if you need other variants.

  -Ross

  On Sep 8, 2009, at 3:06 PM, José María wrote:

  Hi.

  Boxes are giving me a hard time.

  Say you have a model of a Product.

  If I've a snippet that retrieves a Product from the DB:

  val product : Box[Product] = Product.find(2)

  And now I want to bind product with bind(),  product is a Box  
  and it
  can be empty, how can I bind something that doesn't exists? You have
  to return a NodeSeq in a snippet. What should my code must do?

  Best regards.


--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread José María

OMG

So, as - begins with - then it has the precedence of the operator
-



On Sep 8, 7:52 pm, Naftoli Gugenheim naftoli...@gmail.com wrote:
 Precedence is determined by the first character of an operator.

 -

 Ross Mellgrendri...@gmail.com wrote:

 Because the compiler interpret your expression as you expect. Instead  
 of:

 url_enlace - (/product/ + product.id.toString)

 which is what you wanted, it got:

 (url_enlace - /product/) + product.id.toString)

 which it can do because it can take an arbitrary object:

 (url_enlace - /product/): ABindParam
 or (the other implicit -)
 (url_enlace - /product/): Tuple2[String, String]

 and convert them to strings. Of course, once it converts to string, it  
 won't fit in bind()'s argument list and so it gave you the could not  
 find overload error.

 Honestly I'm a bit fuzzy on Scala's operator precedence behavior, I  
 think if I recall you can't set precedence, it comes pre-set on all  
 the standard operators like + / -, etc.

 -Ross

 On Sep 8, 2009, at 3:42 PM, José María wrote:



  It worked when I put the () around the bind param

  and the question is ... why?

  On Sep 8, 7:35 pm, Ross Mellgren dri...@gmail.com wrote:
  So that doesn't seem to be a box-related thing so much as a bind
  argument related thing, probably because you have a precedence
  problem... try:

  producto.map(product =
     bind(product, xhtml,
          url_enlace - (/product/ + product.id.toString),
         )
  ).openOr(NodeSeq.Empty)

  Also, FYI, you have val product = Product.find(id), but then map over
  producto. I presume either producto is coming from somewhere else  
  (and
  val product is being shadowed inside the map) or that you pasted not
  exactly what you're compiling.

  -Ross

  On Sep 8, 2009, at 3:25 PM, José María wrote:

  That's my code:

     val product = Product.find(id)

     producto.map(product =
       bind(product, xhtml,
            url_enlace -- /product/ + product.id.toString ,
           )
                ).openOr(NodeSeq.Empty)
     }

  and I get this error:

  [INFO] use java command with args in file forced : false
  /usr/home/josemaria/src/lift/helloworld/src/main/scala/demo/
  helloworld/
  snippet/Portada.scala:55: error: overloaded method value bind with
  alternatives (String,net.liftweb.util.Box[(scala.xml.NodeSeq) =
  scala.xml.NodeSeq],net.liftweb.util.Box
  [(scala.xml.PrefixedAttribute)
  =
  scala.xml.MetaData
  ],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq and
  (String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
  scala.xml.NodeSeq cannot be applied to
  (java.lang.String
  ,scala.xml.NodeSeq
  ,java.lang.String
  ,java.lang.String
  ,net.liftweb.util.Helpers.BindParam
  ,net.liftweb.util.Helpers.BindParam)
       bind(producto, xhtml,
       ^
  one error found

  What's wrong?

  On Sep 8, 7:13 pm, Ross Mellgren dri...@gmail.com wrote:
  Well it depends on precisely what you want. If you want your  
  snippet
  to become empty if the product is not there, try:

  productBox.map(product = {
     bind(product, ns, ...)

  }).openOr(NodeSeq.Empty)

  If you want only certain bind positions empty, do the same thing
  inside the bind:

  bind(proudct, ns,
        field - productBox.map(p = Text(p.field.toString)).openOr
  (NodeSeq.Empty),
        ...)

  map is of course just one of the (simpler) operations you can do  
  with
  a Box, there's more complicated stuff if you need other variants.

  -Ross

  On Sep 8, 2009, at 3:06 PM, José María wrote:

  Hi.

  Boxes are giving me a hard time.

  Say you have a model of a Product.

  If I've a snippet that retrieves a Product from the DB:

  val product : Box[Product] = Product.find(2)

  And now I want to bind product with bind(),  product is a Box
  and it
  can be empty, how can I bind something that doesn't exists? You  
  have
  to return a NodeSeq in a snippet. What should my code must do?

  Best regards.


--~--~-~--~~~---~--~~
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: Box and bind

2009-09-08 Thread Ross Mellgren

So that doesn't seem to be a box-related thing so much as a bind  
argument related thing, probably because you have a precedence  
problem... try:

producto.map(product =
   bind(product, xhtml,
url_enlace - (/product/ + product.id.toString),
   )
).openOr(NodeSeq.Empty)

Also, FYI, you have val product = Product.find(id), but then map over  
producto. I presume either producto is coming from somewhere else (and  
val product is being shadowed inside the map) or that you pasted not  
exactly what you're compiling.

-Ross


On Sep 8, 2009, at 3:25 PM, José María wrote:


 That's my code:

val product = Product.find(id)


producto.map(product =
  bind(product, xhtml,
   url_enlace -- /product/ + product.id.toString ,
  )
   ).openOr(NodeSeq.Empty)
}

 and I get this error:

 [INFO] use java command with args in file forced : false
 /usr/home/josemaria/src/lift/helloworld/src/main/scala/demo/ 
 helloworld/
 snippet/Portada.scala:55: error: overloaded method value bind with
 alternatives (String,net.liftweb.util.Box[(scala.xml.NodeSeq) =
 scala.xml.NodeSeq],net.liftweb.util.Box[(scala.xml.PrefixedAttribute)
 =
 scala.xml.MetaData 
 ],scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
 scala.xml.NodeSeq and
 (String,scala.xml.NodeSeq,net.liftweb.util.Helpers.BindParam*)
 scala.xml.NodeSeq cannot be applied to
 (java.lang.String 
 ,scala.xml.NodeSeq 
 ,java.lang.String 
 ,java.lang.String 
 ,net.liftweb.util.Helpers.BindParam 
 ,net.liftweb.util.Helpers.BindParam)
  bind(producto, xhtml,
  ^
 one error found



 What's wrong?



 On Sep 8, 7:13 pm, Ross Mellgren dri...@gmail.com wrote:
 Well it depends on precisely what you want. If you want your snippet
 to become empty if the product is not there, try:

 productBox.map(product = {
bind(product, ns, ...)

 }).openOr(NodeSeq.Empty)

 If you want only certain bind positions empty, do the same thing
 inside the bind:

 bind(proudct, ns,
   field - productBox.map(p = Text(p.field.toString)).openOr
 (NodeSeq.Empty),
   ...)

 map is of course just one of the (simpler) operations you can do with
 a Box, there's more complicated stuff if you need other variants.

 -Ross

 On Sep 8, 2009, at 3:06 PM, José María wrote:



 Hi.

 Boxes are giving me a hard time.

 Say you have a model of a Product.

 If I've a snippet that retrieves a Product from the DB:

 val product : Box[Product] = Product.find(2)

 And now I want to bind product with bind(),  product is a Box  
 and it
 can be empty, how can I bind something that doesn't exists? You have
 to return a NodeSeq in a snippet. What should my code must do?

 Best regards.


 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---