passing paramater to a getter method via JSF
I would like to pass a parameter to my getter method in the backing bean.The code I am using is below:
<h:selectOneMenu id="dateTimeMaskMenu">
<f:selectItems value="#{userBean.list}" />
<f:param value="DateMask" />// is this valid?
// I wud like to pass the String value "DateMask"
// to the method getList(String value) of my backing bean
</h:selectOneMenu>
so in other words my getList() method gives me the list depending on the value I pass it. How do I acheive this? Do I need to set somethings in the managed-beans.xml fime as well? or just pasing parameters thru JSF is good enuf? Also how do I access it in my Bean?
[867 byte] By [
msanyala] at [2007-10-3 2:24:39]

Use f:attribute instead.Also see: http://balusc.xs4all.nl/srv/dev-jep-com.html
Thanks BalusC. one more question...I am getting this exception:javax.faces.el.PropertyNotFoundException: Error setting property 'myValue' in bean of type...do I have to set <managed-property> in the managed-beans.xml file as well?
Addpublic void setMyValue(String value) {this.value = value;}or so .. to your backing bean.
I do have the setMyValue() method....here is what i hv in my JSP,. I feel it might be a JSF problem. I am setting the binding in the wrong place mebbe:
<h:selectOneMenu id="dateTimeMaskMenu" >
<f:selectItems value="#{userBean.list}" binding="#{userBean.myValue}"/>
<f:attribute name="listName" value="DateMask" />
</h:selectOneMenu>
the error i am getting now is: javax.faces.el.EvaluationException: java.lang.IllegalArgumentException: argument type mismatch
How are you setting the selectItems? You have both the binding and the value defined for f:selecttItems. Can you please paste the backing bean code also...
I just followed what I read at Balusc's website: http://balusc.xs4all.nl/srv/dev-jep-com.html
so basically this is what I have for my JSP and BEAN:
JSP
=================
<h:selectOneMenu id="dateTimeMaskMenu" >
<f:selectItems value="#{userBean.list}" binding="#{userBean.myValue}"/>
<f:attribute name="listName" value="DateMask" />
</h:selectOneMenu>
JAVA BEAN
=======================
private HtmlOutputText myValue;
public HtmlOutputText getmyValue() {
return myValue;
}
public void setMyValue(HtmlOutputText myValue) {
this.myValue = myValue;
}
public SelectItem[] getValueList() {
String value = (String)myValue.getAttributes().get("listName");
//bla bla bla....this is a long method, but I am getting
//the attribute value and casting it to a string in this method
Message was edited by:
msanyal
Basically your getMyValue and setMyValue methods are incorrect.getMyValue should return the UISelectItems and setMyValue must have argument as UISelectItems. Since your binding is for f:selectItems.
Thanks Kiran!
for debugging purposes I am doing:
public SelectItem[] getValueList() {
String value = (String)myValue.getAttributes().get("listName");
System.out.println("VALUE:" + value);
and I am getting the output as: VALUE: null
and thr error code as:
Exception Details: java.lang.IllegalArgumentException
Conversion Error setting value ''{0}'' for ''{1}''.
Possible Source of Error:
Class Name: com.sun.faces.util.Util
File Name: Util.java
Method Name: getSelectItems
Line Number: 630
why is that?
BTW I did fix them all to UISelectItems
ok..I figured it out...what I was doing in the JSP was wrong: here is the corrected version...I have put the binding inside the <h:selectOneMenu and now it works, ofcourse which means I had to change my bean now to have getters and setters of UISelectOne
><h:selectOneMenu id="dateTimeMaskMenu" binding="#{userBean.myValue}">
<f:attribute name="listName" value="DateMask" />
<f:selectItems value="#{userBean.list}" />
</h:selectOneMenu>
Thanks u guys for all the help :)