如何在 play 2.0 中使用动作作为其他动作的参数
How to use action as parameter for other action in play 2.0
我在模板中有以下功能:
@activeLink(currentPath:String) = @{
if(request.path.equals(currentPath)) {
"active"
}
}
(来自:Play Framework: How do I change active class on route change)
现在我想这样称呼它:
@activeLink(@routes.Application.index().url)
但我收到以下错误:
play.sbt.PlayExceptions$CompilationException: Compilation error[illegal start of simple expression]
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na]
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler.apply(PlayReload.scala:49) ~[na:na]
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler.apply(PlayReload.scala:44) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na]
at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44) ~[na:na]
at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40) ~[na:na]
at play.sbt.run.PlayReload$$anonfun$compile.apply(PlayReload.scala:17) ~[na:na]
at play.sbt.run.PlayReload$$anonfun$compile.apply(PlayReload.scala:17) ~[na:na]
at scala.util.Either$LeftProjection.map(Either.scala:377) ~[scala-library-2.10.5.jar:na]
at play.sbt.run.PlayReload$.compile(PlayReload.scala:17) ~[na:na]
at play.sbt.run.PlayRun$$anonfun$playRunTask$$anonfun$apply$$anonfun$apply$$anonfun.apply(PlayRun.scala:61) ~[na:na]
at play.sbt.run.PlayRun$$anonfun$playRunTask$$anonfun$apply$$anonfun$apply$$anonfun.apply(PlayRun.scala:61) ~[na:na]
at play.runsupport.Reloader$$anonfun$reload.apply(Reloader.scala:323) ~[na:na]
at play.runsupport.Reloader$$anon.run(Reloader.scala:43) ~[na:na]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_60]
at play.runsupport.Reloader$.play$runsupport$Reloader$$withReloaderContextClassLoader(Reloader.scala:39) ~[na:na]
at play.runsupport.Reloader.reload(Reloader.scala:321) ~[na:na]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:113) ~[play-server_2.10-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:111) ~[play-server_2.10-2.4.6.jar:2.4.6]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24) ~[scala-library-2.10.5.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.10.5.jar:na]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) ~[akka-actor_2.10-2.3.13.jar:na]
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) ~[akka-actor_2.10-2.3.13.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) ~[scala-library-2.10.5.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) ~[scala-library-2.10.5.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) ~[scala-library-2.10.5.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) ~[scala-library-2.10.5.jar:na]
将 url 传递给模板内的函数的正确方法是什么?
已使用 Play 2.4.6 和 Java 8 进行测试。
参数必须不带 '@' 尝试传递 @activeLink(routes.Application.index().url)
我在模板中有以下功能:
@activeLink(currentPath:String) = @{
if(request.path.equals(currentPath)) {
"active"
}
}
(来自:Play Framework: How do I change active class on route change)
现在我想这样称呼它:
@activeLink(@routes.Application.index().url)
但我收到以下错误:
play.sbt.PlayExceptions$CompilationException: Compilation error[illegal start of simple expression]
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at play.sbt.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na]
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler.apply(PlayReload.scala:49) ~[na:na]
at play.sbt.run.PlayReload$$anonfun$taskFailureHandler.apply(PlayReload.scala:44) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na]
at play.sbt.run.PlayReload$.taskFailureHandler(PlayReload.scala:44) ~[na:na]
at play.sbt.run.PlayReload$.compileFailure(PlayReload.scala:40) ~[na:na]
at play.sbt.run.PlayReload$$anonfun$compile.apply(PlayReload.scala:17) ~[na:na]
at play.sbt.run.PlayReload$$anonfun$compile.apply(PlayReload.scala:17) ~[na:na]
at scala.util.Either$LeftProjection.map(Either.scala:377) ~[scala-library-2.10.5.jar:na]
at play.sbt.run.PlayReload$.compile(PlayReload.scala:17) ~[na:na]
at play.sbt.run.PlayRun$$anonfun$playRunTask$$anonfun$apply$$anonfun$apply$$anonfun.apply(PlayRun.scala:61) ~[na:na]
at play.sbt.run.PlayRun$$anonfun$playRunTask$$anonfun$apply$$anonfun$apply$$anonfun.apply(PlayRun.scala:61) ~[na:na]
at play.runsupport.Reloader$$anonfun$reload.apply(Reloader.scala:323) ~[na:na]
at play.runsupport.Reloader$$anon.run(Reloader.scala:43) ~[na:na]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_60]
at play.runsupport.Reloader$.play$runsupport$Reloader$$withReloaderContextClassLoader(Reloader.scala:39) ~[na:na]
at play.runsupport.Reloader.reload(Reloader.scala:321) ~[na:na]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:113) ~[play-server_2.10-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:111) ~[play-server_2.10-2.4.6.jar:2.4.6]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24) ~[scala-library-2.10.5.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.10.5.jar:na]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40) ~[akka-actor_2.10-2.3.13.jar:na]
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:397) ~[akka-actor_2.10-2.3.13.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) ~[scala-library-2.10.5.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) ~[scala-library-2.10.5.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) ~[scala-library-2.10.5.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) ~[scala-library-2.10.5.jar:na]
将 url 传递给模板内的函数的正确方法是什么?
已使用 Play 2.4.6 和 Java 8 进行测试。
参数必须不带 '@' 尝试传递 @activeLink(routes.Application.index().url)