自定义 getEntityNameSelectList() 失败
编写一个简单的 JSF 应用程序时,我遇到了以下问题: 我的Entity.controller.EntityNameManager类包含一个方法getEntityNameSelectList(),我可以用它来填充ComboBox。 这有效并显示所有实体,因为检索实体的方法没有 where 子句。 该方法是自动创建的。
现在我想要第二个类似的方法,它根据会话范围中的变量过滤选项。 为此,我复制了原始方法,将其重命名为 getEntityNameSelectListByUser(User theUser) 并将查询数据库的方法更改为确实按 UserId 进行过滤的方法。
但是,当尝试在浏览器中加载页面时,我收到一条错误,指出控制器类没有“EntityNameSelectListByUser”属性。 我假设由于我的新方法需要一个参数,所以无法找到它。 有没有办法让它知道参数或 Sessionscope 用户 ID?
Writing a simple JSF application I've some across the following Problem:
My entities.controller.EntityNameManager class contains a method getEntityNameSelectList() which I can use to populate a ComboBox with. This works and shows all Entities, since the Method to retrieve the Entities does not have a where clause.
This Method was automatically created.
Now I want to have a second similar Method, that filters the options based on a variable in the sessionscope. To do this I copied the original Method, renamed it to getEntityNameSelectListByUser(User theUser) and changed the Method that queries the database to one that does indeed filter by UserId.
However, when trying to load the page in the browser, I get an error stating that the controller class does not have a "EntityNameSelectListByUser" property. I assume that since my new method expects a parameter it can't be found. Is there a way I can make it aware of the Parameter or the Sessionscope userid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
预计 JSR 245 的下一个维护版本将支持 EL 中的参数(公告此处; /" rel="nofollow noreferrer">此处)。
假设您不想等待 JEE6,您有多种方法可以克服此限制。 这些方法是根据 POJO 托管 bean 定义的,因此请根据需要调整它们以适应您的 EJB。
1.
在支持 bean 中进行会话查找和函数调用:
绑定示例:
2.
使用 EL 函数(在 TLD 中定义,映射到公共静态方法):
绑定示例:
3.
颠覆 Map 类以调用该函数(有点 hack,仅限于一个)参数):
绑定示例:
Support for parameters in EL is slated for the next maintenance release of JSR 245 (announcement here; implementation here).
Assuming you don't want to wait for JEE6, you have several ways to overcome this limitation. These approached are defined in terms of POJO managed beans, so adapt them to your EJBs as appropriate.
1.
Do the session lookup and function call in a backing bean:
Example binding:
2.
Use an EL function (defined in a TLD, mapped to a public static method):
Example binding:
3.
Subvert the Map class to call the function (a bit of a hack and limited to one parameter):
Example binding: