Search code examples
jsfrichfacesfacelets

JSP useBean equivalent in JSF


Is there any way can declare a bean in just like JSP UseBean in JSF?

for example if i have nested objected inside a VO, I don't want to call to many get methods again and again

For Example i have ManagedBean(MB) hold VO. VO hold (CVO), CVO Hold CVO1. if want methods of CVO. i need to write MB.VO.CVO.CVO1.method1, MB.VO.CVO.CVO1.method2. is there any simple approach to this like i define CVO1 and use it as CVO1.method1 and CVO1.method2?


Solution

  • If you are using JSTL, you can use the <c:set> component:

    <c:set var="temp" value="#{myBean.someObject}"/>
    ...
    <!-- Exemple of usage: -->
    <h:outputText value="#{temp.someProperty}"/>