简体   繁体   中英

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). 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.

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

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

another approach will be calling a method on any phase before the page is rendered.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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