myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Klug, Boris " <Boris.K...@debeka.de>
Subject Re: How can I avoid using the jsp:useBean tag?
Date Fri, 17 Jun 2005 11:31:22 GMT
Hello!

thats a problem in JSF EL: You cant call all methods of your managed beans. You
can only use getter for the bean properties which are special named methods.

First workaround is to implement a getter (lets call it getSetup()) which does
the setup for your bean. The getter should return an empty String and must be
called first.

Another problem is that you cant call getters/methods with parameters. A way to
do this is to implement your own implementation of a map and treat the key of
the map as a kind of function name or parameter.

E.g. you can give your bean a method like:

private MyMap result;

public Map getResult() {
 return  this.result;
}

In your jsf page:

  ... value="#{bean.result['functioname']}"

In the getter of your map (MyMap) you can now treat the key (String) as a
function name or parameter and you can return the result you want.

I know this all sounds a lot like hacking but I havent found another way to pass
parameters to managed beans to get dynamic output.


--
Boris Klug, Debeka, Koblenz



Zitat von Alecsandru Chirosca <alecsandru.chirosca@comtec.ro>:

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


Mime
View raw message