Thanks Alecs, but as far as I can see, that does *not* work.
Let us say the loop on the page runs 5 times. Then the first time
MyFaces encounter the statement
<h:outputText value="#{myBean.myProperty}"/>
It will instantiate the bean using the default constructor prior to
invoking getMyProperty(). But on the 2nd, 3rd, 4th, and 5th run through
the loop the default constructor is not called because the bean is
already instantiated. Therefore I have created a setup method which I
would like to invoke at the start of each run through the loop - this
method retrieves the value of myProperty from a cache
Is there no way to accomplish this?
Randahl
Alecsandru Chirosca wrote:
Hi,
You can execute setup(); from your bean default constructur (inherited
from java.lang.Object).
Hope it helps.
BR,
Alecs
On Fri, 2005-06-17 at 12:03 +0200, Randahl Fink Isaksen wrote:
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
|