You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Lisa <ap...@purpleblade.net> on 2007/02/13 07:20:32 UTC
selectList - how to pass a parameter to backing bean method from
XHTML?
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
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8939143
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: selectList - how to pass a parameter to backing bean method from
XHTML?
Posted by Simon Kitching <si...@rhe.co.nz>.
I really think this f:param thing is completely irrelevant to the
original issue.
f:param allows an arbitrary http request parameter to be attached to a
postback triggered by an h:commandButton or h:commandLink.
As far as I am aware, the f:param tag does *nothing* when attached to
any other component.
And anyway Lisa needs to know *when the h:selectOneMenu is rendered for
the very first time* what block of reference data to draw the
select-item labels from, ie when no postback has occurred at all.
BTW, I've removed the "[solved]" from this email's subject.
Regards,
Simon
Lisa wrote:
> Where/ how is "map" defined?
>
> thanks
>
>
> L
>
>
>
> krg9263 wrote:
>>
>> Not sure if this will work with
>>
>> <h:selectOneMenu
>>
>> but you could try it this way. I have done this with a commandLink.
>>
>> <h:commandLink id="manufacturer_x"
>> action="go_Test" actionListener="#{testList.execute}">
>> <f:param name="queryTableParam" value="ALL" />
>> </h:commandLink>
>>
>> Inside bean.
>>
>> public void execute(ActionEvent event) {
>> queryTable = (String) map.get("queryTableParam");
>> //then call whatever you need to do
>> this.go();
>>
>>
>
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Lisa <ap...@purpleblade.net>.
Where/ how is "map" defined?
thanks
L
krg9263 wrote:
>
>
> Not sure if this will work with
>
> <h:selectOneMenu
>
> but you could try it this way. I have done this with a commandLink.
>
> <h:commandLink id="manufacturer_x"
> action="go_Test" actionListener="#{testList.execute}">
> <f:param name="queryTableParam" value="ALL" />
> </h:commandLink>
>
> Inside bean.
>
> public void execute(ActionEvent event) {
> queryTable = (String) map.get("queryTableParam");
> //then call whatever you need to do
> this.go();
>
> }
>
>
>
>
>
> Lisa wrote:
>> I tried the following but could not get it to work:
>>
>>
>> <h:selectOneMenu id="areaCode" value="#{areaCodeBean.areaCode}">
>> <f:selectItems value="#{areaCodeBean.selectList}"/>
>> <f:param name="codeType" value="US.AREA_CODES" />
>> </h:selectOneMenu>
>>
>> And in the BB to retrieve the codeType I have the following method that
>> is
>> called:
>>
>> private String getCodeType()
>> {
>> String codeType = (String)FacesContext.getCurrentInstance()
>>
>> .getExternalContext().getRequestParameterMap().get("codeType");
>>
>>
>> return codeType;
>> }
>>
>> ---
>> When I look at the value for "codeType" it is always null. getCodeType
>> is
>> called by
>>
>> public List<SelectItem> getSelectList() {
>> // query from types table here and pass codeType (call to
>> getCodeType()
>> which uses faces context
>> // to get a param set in the XHTML.
>> }
>>
>>
>>
>>
>>
>>
>> sahil wrote:
>>
>>> you can use the <f:param> tag to pass a parameter in jsf.
>>>
>>> although I havent tried it in jsf, but i use it in jboss-seam. I think
>>> it
>>> will work.
>>>
>>>
>>> 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
>>>>
>>>>
>>>
>>
>>
>
>
>
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8954785
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Kevin Gutch <kg...@protechemail.com>.
Not sure if this will work with
<h:selectOneMenu
but you could try it this way. I have done this with a commandLink.
<h:commandLink id="manufacturer_x"
action="go_Test" actionListener="#{testList.execute}">
<f:param name="queryTableParam" value="ALL" />
</h:commandLink>
Inside bean.
public void execute(ActionEvent event) {
queryTable = (String) map.get("queryTableParam");
//then call whatever you need to do
this.go();
}
Lisa wrote:
> I tried the following but could not get it to work:
>
>
> <h:selectOneMenu id="areaCode" value="#{areaCodeBean.areaCode}">
> <f:selectItems value="#{areaCodeBean.selectList}"/>
> <f:param name="codeType" value="US.AREA_CODES" />
> </h:selectOneMenu>
>
> And in the BB to retrieve the codeType I have the following method that is
> called:
>
> private String getCodeType()
> {
> String codeType = (String)FacesContext.getCurrentInstance()
>
> .getExternalContext().getRequestParameterMap().get("codeType");
>
>
> return codeType;
> }
>
> ---
> When I look at the value for "codeType" it is always null. getCodeType is
> called by
>
> public List<SelectItem> getSelectList() {
> // query from types table here and pass codeType (call to getCodeType()
> which uses faces context
> // to get a param set in the XHTML.
> }
>
>
>
>
>
>
> sahil wrote:
>
>> you can use the <f:param> tag to pass a parameter in jsf.
>>
>> although I havent tried it in jsf, but i use it in jboss-seam. I think it
>> will work.
>>
>>
>> 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
>>>
>>>
>>
>
>
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Lisa <ap...@purpleblade.net>.
I tried the following but could not get it to work:
<h:selectOneMenu id="areaCode" value="#{areaCodeBean.areaCode}">
<f:selectItems value="#{areaCodeBean.selectList}"/>
<f:param name="codeType" value="US.AREA_CODES" />
</h:selectOneMenu>
And in the BB to retrieve the codeType I have the following method that is
called:
private String getCodeType()
{
String codeType = (String)FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap().get("codeType");
return codeType;
}
---
When I look at the value for "codeType" it is always null. getCodeType is
called by
public List<SelectItem> getSelectList() {
// query from types table here and pass codeType (call to getCodeType()
which uses faces context
// to get a param set in the XHTML.
}
sahil wrote:
>
> you can use the <f:param> tag to pass a parameter in jsf.
>
> although I havent tried it in jsf, but i use it in jboss-seam. I think it
> will work.
>
>
> 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
>>
>
>
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8953454
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by sahil <as...@gmail.com>.
you can use the <f:param> tag to pass a parameter in jsf.
although I havent tried it in jsf, but i use it in jboss-seam. I think it
will work.
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
>
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8945328
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Lisa <ap...@purpleblade.net>.
I tried the following but could not get it to work:
<h:selectOneMenu id="areaCode" value="#{areaCodeBean.areaCode}">
<f:selectItems value="#{areaCodeBean.selectList}"/>
<f:param name="codeType" value="US.AREA_CODES" />
</h:selectOneMenu>
And in the BB to retrieve the codeType I have the following method that is
called:
private String getCodeType()
{
String codeType = (String)FacesContext.getCurrentInstance()
.getExternalContext().getRequestParameterMap().get("codeType");
return codeType;
}
---
When I look at the value for "codeType" it is always null. getCodeType is
called by
public List<SelectItem> getSelectList() {
// query from types table here and pass codeType (call to getCodeType()
which uses faces context
// to get a param set in the XHTML.
}
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
>>>
>>
>
>
>
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8953541
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Jeff Bischoff <jb...@klkurz.com>.
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
>>>>>>>
>>>>>
>>>
>>>
>>
>
>
>
>
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Simon Kitching <si...@rhe.co.nz>.
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
>>>>>>
>>>>
>>
>>
>
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Lisa <ap...@purpleblade.net>.
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
>>>>>
>>>
>>>
>>
>
>
>
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8954761
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Simon Kitching <si...@rhe.co.nz>.
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
>>>>
>>
>>
>
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Lisa <ap...@purpleblade.net>.
This is super helpful and will look into it. Ideally what I am looking for
is to pass a parameter along with each <h:selectOneListBox> (bound?)
Thanks
L
fastbob wrote:
>
> Lisa,
> Something I found helpful for passing parameters to beans from JSF is the
> following link: http://balusc.xs4all.nl/srv/dev-jep-com.html
> http://balusc.xs4all.nl/srv/dev-jep-com.html
>
> fastbob
>
>
> 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
>>>>>
>>>>
>>>
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8991742
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by fastbob <fa...@gmail.com>.
Lisa,
Something I found helpful for passing parameters to beans from JSF is the
following link: http://balusc.xs4all.nl/srv/dev-jep-com.html
http://balusc.xs4all.nl/srv/dev-jep-com.html
fastbob
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
>>>>
>>>
>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8971128
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Lisa <ap...@purpleblade.net>.
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
>>>
>>
>
>
>
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8953310
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Simon Kitching <si...@rhe.co.nz>.
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
>>
>
Re: [Solved] selectList - how to pass a parameter to backing bean
method from XHTML?
Posted by Lisa <ap...@purpleblade.net>.
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
>
--
View this message in context: http://www.nabble.com/selectList---how-to-pass-a-parameter-to-backing-bean-method-from-XHTML--tf3218841.html#a8952115
Sent from the MyFaces - Users mailing list archive at Nabble.com.