lift:testCond - 它是如何工作的?
我在电梯示例中发现了这一点:
<lift:TestCond.loggedout>
<lift:embed what="/templates/_login_panel"/>
</lift:TestCond.loggedout>
How do I tweak this lift tag if I want to test any other condition? Is this some kind of <c:if/>
tag in JSP or the idea is somewhere else?i discovered this in lift examples:
<lift:TestCond.loggedout> <lift:embed what="/templates/_login_panel"/> </lift:TestCond.loggedout>
How do I tweak this lift tag if I want to test any other condition? Is this some kind of <c:if/>
tag in JSP or the idea is somewhere else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
lift:TestCond
指的是代码片段object TestCond
仅提供loggedIn
和loggedOut
方法。 Lift 中没有通用的
可用,因为它会模糊代码和标记之间的界限。如果您想要不同的行为,您需要自己实现此类测试并在代码中明确它们。但它真的很简单。通过查看源代码,您可以了解如何根据您的需求进行自定义。
loggedIn
的代码非常简单,例如,您可以实现不同的行为
,允许更高级的
或类似的操作。但这实际上取决于您的用例,所以我认为不可能在 Lift 中使其通用。
lift:TestCond
refers to the snippetobject TestCond
which only provides theloggedIn
andloggedOut
methods. There is no general<c:if/>
available in Lift because it would blur the boundaries between code and markup.If you want different behaviour, you’ll need to implement such tests yourself and make them explicit in your code. But its really simple. By looking at the source code, you can get an idea of how to customise this to your needs.
The code for
loggedIn
is as simple asSo, for example, you could implement a different behaviour which allows for
or, more advanced
or something similar. But this really depends on your use case, so I think it’s not possible to make this generic in Lift.
作为旁注,我编写了一个小实用程序来为我执行此任务:
然后您可以在 DispatchSnippet 中使用它,例如:
您可以决定是否要编写
testCond[Type]( ...)
或testCond(...)
。在第二种情况下,您必须指定函数的类型。例如testCond(S.param("s"), _, (_: String).nonEmpty)
。As a side-note I have written a small utility which performs this task for me:
Then you can use it like the following in a DispatchSnippet for instance:
You can decide whether or not you want to write
testCond[Type](...)
ortestCond(...)
. In the second case you will have to specify the type of the function. E.g.testCond(S.param("s"), _, (_: String).nonEmpty)
.