Here's what I came up with. It seems to work. I don't know how well it will appear inlined in a posting. Let if you want it delivered in another fashion.
diff --git a/lift/src/main/scala/net/liftweb/http/SHtml.scala b/lift/ src/main/scala/net/liftweb/http/SHtml.scala index 22c4832..58e6069 100644 --- a/lift/src/main/scala/net/liftweb/http/SHtml.scala +++ b/lift/src/main/scala/net/liftweb/http/SHtml.scala @@ -430,13 +430,28 @@ object SHtml { private[http] def secureOptions[T](options: Seq[(T, String)], default: Box[T], onSubmit: T => Unit): (Seq [(String, String)], Box[String], AFuncHolder) = { val secure = options.map{case (obj, txt) => (obj, randomString (20), txt)} - val defaultNonce = default.flatMap(d => secure.find(_._1 == d).map (_._2)) + val defaultNonce = default.map(secureDefaultNonce(secure, _)) val nonces = secure.map{case (obj, nonce, txt) => (nonce, txt)} def process(nonce: String): Unit = secure.find(_._2 == nonce).map(x => onSubmit(x._1)) (nonces, defaultNonce, SFuncHolder(process)) } + private[http] def secureOptions[T](options: Seq[(T, String)], default: Seq[T], + onSubmit: T => Any): (Seq [(String, String)], Seq[String], LFuncHolder) = { + val secure = options.map{case (obj, txt) => (obj, randomString (20), txt)} + val defaultNonce = default.map(secureDefaultNonce(secure, _)) + val nonces = secure.map{case (obj, nonce, txt) => (nonce, txt)} + def process(nonces: List[String]): Any = + nonces.map(nonce => secure.find(_._2 == nonce).map(x => onSubmit (x._1))) + (nonces, defaultNonce, LFuncHolder(process)) + } + + private def secureDefaultNonce[T](secureOptions: Seq[(T, String, String)], default: T): String = { + secureOptions.find(_._1 == default).get._2 + } + + /** * Create a select box based on the list with a default value and the function to be executed on * form submission @@ -518,6 +533,22 @@ object SHtml { func: List[String] => Any, attrs: (String, String) *): Elem = multiSelect_*(opts, deflt, LFuncHolder(func), attrs :_*) + /** + * Create a select box based on the list with a default value and the function + * to be executed on form submission + * + * @param options -- a list of value and text pairs (value, text to display) + * @param default -- the default value (or Empty if no default value) + * @param onSubmit -- the function to execute on form submission + */ + def multiSelectObj[T](options: Seq[(T, String)], default: Seq[T], + onSubmit: T => Unit, attrs: (String, String)*): Elem = { + val (nonces, defaultNonce, secureOnSubmit) = + secureOptions(options, default, onSubmit) + + multiSelect_*(nonces, defaultNonce, secureOnSubmit, attrs:_*) + } + def multiSelect_*(opts: Seq[(String, String)], deflt: Seq[String], func: AFuncHolder, attrs: (String, String)*): Elem = --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---