In my faces-config I have defined a bean called myBean and I have a trivial statement like this in my jspx file:

<h:outputText value="#{myBean.myProperty}"/>

However this statement is placed inside a loop and at the start of each iteration I need to call a method called myBean.setup() before I try to get any properties. Because I have not found any better way, I am doing the following at the start of each iteration:

    <jsp:useBean
        id="myBean"
        class="dk.rockit.x.y.z.MyBean"
        scope="request"
    />
    <jsp:scriptlet>myBean.setup();</jsp:scriptlet>

I dislike this approach for several reasons:
  1. Above I bind my bean to a variable directly in the jspx page - if the class name changes I need to manually find all the useBean tags in all my files and change them. Of course I would prefer to simply define the beans in faces-config.xml - that way I would only have one file to edit when a class name changed.
  2. It does not feel very JSF-like I think - I was hoping for something more along the lines of a tag that looked like <f:invoke method="myBean.setup()"/>
  3. In general I think the less the code scriptlets the better.
Has anyone come up with a way to get arround the jsp:useBean tag? Apart from defining your own x:invoke tag like above ;-)


Randahl
 

Reply via email to