复合组件的 ManagedBean
我正在开发一个复合组件,它必须进行一些计算才能使布局正常工作。对于 EL 来说过于复杂的计算(实际上并不复杂,但我无法通过 EL 执行它们)。 我可以专门为该复合组件创建一个 ManagedBean 吗?这实际上是关于这是否是好的实践,我想我应该在求助于组件专用托管bean 之前尝试多种方法。 如果可以的话,组件如何在渲染之前调用托管 bean 逻辑。假设它必须根据某些属性计算内部 div 的高度和宽度。这可能吗?我想将执行此类计算等的所有复杂性封装在组件中。
I'm developing a composite component that has to do some calculations for the layout to work properly. Calculations that are to complex for the EL (not actually complex but I can't perform them through EL).
Can I create a ManagedBean specifically for that composite component? It's actually about whether that's good practice or not, I guess I should try many approaches before resorting to a component dedicated managedbean.
If I can, how can the component invoke the managed bean logic before being rendered. Say it has to calculate height and width of an inner div based on some attribute. Is that even possible? I want to encapsulate all the complexity of carrying out such calculations etc in the component.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将逻辑插入到变量的 getter(或 setter)中。
编写 on 组件似乎只是为了执行计算有点多。
A.如果需要页面参数来计算,则从页面传递。
B. 在渲染之前调用的操作或变量的实际 getter 中使用这些参数,
另一种方法将在页面渲染之前的任何阶段调用方法。
you can insert your logic into the getter (or setter for that matter) of your variable.
To write your on component seems a bit much just to perform a calculation.
A. if you need parameters form the page to calculate, pass then from the page.
B. use those parameters in either an action invoked before rendering or in the actual getter of the variable
another approach will be calling a method on any phase before the page is rendered.