I think Simon hit the nail on the head for you, Lisa. You should really give this a shot.

Simon Kitching wrote:
Then write a custom class that implements the Map interface (probably by subclassing AbstractMap). Override the get method to do your database lookup, using the key string that is passed to the get method as a parameter.

Lisa wrote:
Actually the data to build the select list is stored in a database. We have
a function that when passed a column value (the code type) will return a
List<SelectItem>.  So the only thing I need to accomplish is to get this
String (the codeType) to the method from the XHTML (do not want to put in
the backing bean).

thanks

L




Simon Kitching-3 wrote:
Ok, I see what you are trying to do.

I believe what you want to be able to specify that a particular f:selectItems tag gets its data from one part of your reference data and a different f:selectItems tag gets its data from a different part of your reference data without having to write custom methods to access the various reference data parts.

If this is the case then f:param is definitely not what you are looking
for.

JSF el expressions support properties that are of type Map. So if
   #{carBean.refdata}
is an object of type Map then
   #{carBean.refdata.vehicleTypes}
will call
   carBean.getRefdata().get("vehicleTypes");

In other words, if you store your reference data into a real map, or alternately write a custom class that implements the Map interface, then you should be able to do what you want.

If this isn't sufficient for you for some reason then you *can* persuade MyFaces to allow functions in EL expressions. However the code will be MyFaces-specific. In short, you need to write a class that implements javax.servlet.jsp.el.FunctionMapper, then subclass org.apache.myfaces.el.ValueBindingImpl to register an instance of your custom FunctionMapper. Much better to avoid that if you can.

Regards,

Simon

Lisa wrote:
We need to build a pulldowns (select list boxes) on the front end (select lists, check boxes etc) and do not want to write a getter for each one. We
simply want a generic method that we call throughout the application
called
"getList(String s).

String s is a key into a types table that, when used for the query will
return everything needed in the list.

I thought this would be the simplest approach instead of having to write
a
method that sets a string and passes it to a function that builds
List<SelectItem>.

It would be better to simply have the String s in the XHTML, that calls 1
method (used throughout the app) that will build and return the
List<SelectItem> based on the string (param) in the XHTML.

at first look it seems like <f:param> would work but I can not seem to
get
this to work to pass any params to my backing bean.


L



Simon Kitching-3 wrote:
I don't think you're going to be able to do this; it isn't natural JSF style. JSF el expressions don't support parameters.

You should look at other approaches to resolve whatever your problem is.

Regards,

Simon

Lisa wrote:
I looked at the docs on this tag <f:param> but there were no examples
on
how
to pass a String param to the getters in the value="#{bean.getMethod}"

I want to pass a string to getMethod(String s) listed above.  If you
have
any specific examples on how to do this, it would be greatly
appreciated.


L



Lisa wrote:
I want to build a SelectItem list by calling a method in my backing
bean,
but I want to be able to pass the backing bean a String (from the
XHTML).


---
This is what I currently have:

    <h:selectOneListbox
            rendered="#{carBean.listMode}"
            id="idSelectVehicleType"
            value="#{carBean.vehicleType}"
            size="1">

        <f:selectItems id="idCarBeanTypeList"
value="#{carBean.vehicleTypeList}"/>
    </h:selectOneListbox>

where vehicleTypeList is a method in CarBean.getVehicleTypeList()

---
So I want to change the method signature to accept a String like so:

  CarBean.getVehicleTypeList(String s)

and in the XHTML pass String s to CarBean.getVehicleTypeList(String
s).

Is this possible?
  value="#{carBean.vehicleTypeList("myString")}"


thanks


Lisa











Reply via email to