Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow setting defalut value via params

  • Loading branch information...
commit 5b12bb5aa0d3d4d4d11614e13e97283a05750eef 1 parent 57b1999
@dpp dpp authored
Showing with 24 additions and 1 deletion.
  1. +24 −1 web/webkit/src/main/scala/net/liftweb/sitemap/Loc.scala
View
25 web/webkit/src/main/scala/net/liftweb/sitemap/Loc.scala
@@ -63,8 +63,20 @@ trait Loc[T] {
def calcHref(in: T): String = link.createPath(in)
def defaultValue: Box[T]
+
+ /**
+ * The value of the Loc based on params (either Loc.Value or Loc.CalcValue)
+ */
+ def paramValue: Box[T] = calcValue.flatMap(f => f()) or staticValue
+
+ private lazy val staticValue: Box[T] = params.collect{case Loc.Value(v: T) => v}.headOption
+
+ private lazy val calcValue: Box[() => Box[T]] = params.collect{case Loc.CalcValue(f: Function0[Box[T]]) => f}.headOption
- def currentValue: Box[T] = overrideValue or requestValue.is or defaultValue
+ /**
+ * The current value of the cell: overrideValue or requestValue.is or defaultValue oe paramValue
+ */
+ def currentValue: Box[T] = overrideValue or requestValue.is or defaultValue or paramValue
def childValues: List[T] = Nil
@@ -526,6 +538,17 @@ object Loc {
* the groups can be specified and recalled at the top level
*/
case class LocGroup(group: String*) extends AnyLocParam
+
+ /**
+ * Calculate the value for the Loc. This is useful for parameterized
+ * menus. It allows you to calculate the value of the Loc.
+ */
+ case class CalcValue[T](func: () => Box[T]) extends LocParam[T]
+
+ /**
+ * The value of Loc
+ */
+ case class Value[T](value: T) extends LocParam[T]
/**
* An extension point for adding arbitrary lazy values to a Loc.
Please sign in to comment.
Something went wrong with that request. Please try again.