Grails:从流范围检索 bean
在我的 Grails 应用程序中,我有一个 bean 存储在动态生成的密钥下的流作用域中。 在 GSP 中我想检索 bean。 假设 bean 的键是字符串形式的当前日期(尽管事实并非如此)。
如果在我的 GSP 中我使用类似的东西
${new Date().getDateString()}
,那么这将呈现当前日期,但我想要做的是使用此键从流范围中检索 bean。
谢谢, 大学教师
In my Grails app, I have a bean stored in flow scope under a key that is dynamically generated. In a GSP I want to retrieve the bean. Assume that the key of the bean is the current Date as a String (though it's not really).
If in my GSP I use something like
${new Date().getDateString()}
then this will render the current date, but what I want to do is retrieve the bean from flow scope with this key.
Thanks,
Don
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你会如何按照你所说的方式做到这一点。 正如您所说,大多数情况下,保存键的任何变量都会被转换为字符串并显示。 在 WebFlow 期间,会话范围以下的所有内容都会被扁平化(包括请求和流范围),并且不会通过范围名称进行引用。
是否有理由必须将它们直接放入 Flow 范围中? 如果您将一个名为“storedBeans”或类似名称的映射放入流范围中,并使用这些生成的键将您的 bean 放入映射中,它仍然对您有用吗? 然后类似:
应该返回您感兴趣的bean。
I'm not sure how you'd do this exactly the way you state it. As you state, most times whatever variable held the key would just be converted to a string and displayed. During a WebFlow, everything below the session scope is flattened (including the request and flow scopes) and not referred to by scope-name.
Is there a reason they have to be put in the Flow scope directly? Would it still work for you if you put a Map in the flow scope called "storedBeans" or some such, and put your beans in the map using those generated keys? Then something like:
should return the bean your interested in.