简体   繁体   English

复合组件的ManagedBean

[英]ManagedBean for a composite component

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). 对于EL来说很复杂的计算(实际上不是很复杂,但是我无法通过EL进行计算)。 Can I create a ManagedBean specifically for that composite component? 我可以专门为该复合组件创建ManagedBean吗? 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. 实际上,这关乎是否是一种好习惯,我想在诉诸于组件专用托管bean之前,我应该尝试许多方法。 If I can, how can the component invoke the managed bean logic before being rendered. 如果可以,该组件如何在呈现之前调用托管bean逻辑。 Say it has to calculate height and width of an inner div based on some attribute. 假设它必须根据某些属性计算内部div的高度和宽度。 Is that even possible? 那有可能吗? I want to encapsulate all the complexity of carrying out such calculations etc in the component. 我想将执行此类计算等的所有复杂性封装在组件中。

you can insert your logic into the getter (or setter for that matter) of your variable. 您可以将逻辑插入变量的getter(或setter)中。

To write your on component seems a bit much just to perform a calculation. 仅仅为了执行计算,编写您的on组件似乎有点多。

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 B.在渲染之前调用的操作或变量的实际获取器中使用这些参数

public int getCalculatedAttribute() {
    return width*height-100;
}

another approach will be calling a method on any phase before the page is rendered. 另一种方法是在呈现页面之前的任何阶段调用方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM