You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by monkeyden <mo...@gmail.com> on 2006/10/30 20:16:16 UTC

Submitting using SelectOneRadio

Im using this wiki example to submit a form from a radio button:

http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 
http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 

The submit itself is working flawlessly and everything described in the
example is fine.  I was wondering how I could also get the value of the
selected radio button passed to the listener method as well.  I happen to be
using JBoss Seam components as the business layer, but the main question is,
how can I get the radio's value to submit as well?  I've implemented it as
such:

The listener method:
@RequestParameter private String selectedState;

public String getSelectedState() {
    return selectedState;
}
public void setSelectedState(String selectedState) {
    this.selectedState = selectedState;
}

public String locationsByState(){
    availableLocations = new ArrayList<SelectItem>();
    loadLocations();
    for(int i=0;i<staticLocations.size();i++){
        SelectItem current = staticLocations.get(i);
        if(current.getDescription().trim().equals(selectedState)){
            availableLocations.add(current);
        }
    }
    return display();        
}

The View.  radioSubmit is generating the JS event as in the example:
<h:selectOneRadio value="#{editProfileAction.selectedState}"
onmouseup="radioSubmit('hiddenLink');" styleClass="bodyCopy"
immediate="true">
    <f:selectItem itemLabel="MA" itemValue="MA"/>
    <f:selectItem itemLabel="ME" itemValue="ME"/>
    <f:selectItem itemLabel="NH" itemValue="NH"/>
    <f:selectItem itemLabel="RI" itemValue="RI"/>
    <f:selectItem itemLabel="VT" itemValue="VT"/>
</h:selectOneRadio>

<t:commandLink id="hiddenLink" forceId="true" style="display:none;
visibility: hidden;" action="#{editProfileAction.locationsByState}">
</t:commandLink>

Thanks for any suggestions
-- 
View this message in context: http://www.nabble.com/Submitting-using-SelectOneRadio-tf2541475.html#a7080992
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Submitting using SelectOneRadio

Posted by Jeff Bischoff <jb...@klkurz.com>.
 > how can I get the radio's value to submit as well?

Use a valueChangeListener. Since the component is "immediate", you will 
need to explicitly call the setter method for the property.

E.G.

public void updateState(ValueChangeEvent event) {
	String newState = (String) event.getNewValue();
	data.setCurrentState(newState);
}

You should also check out the wiki specifically on this topic: [1],
as well as the new submitOnEvent component [2].

[1] http://wiki.apache.org/myfaces/SubmitPageOnValueChange
[2] http://wiki.apache.org/myfaces/SubmitOnEvent

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

monkeyden wrote:
> Im using this wiki example to submit a form from a radio button:
> 
> http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 
> http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 
> 
> The submit itself is working flawlessly and everything described in the
> example is fine.  I was wondering how I could also get the value of the
> selected radio button passed to the listener method as well.  I happen to be
> using JBoss Seam components as the business layer, but the main question is,
> how can I get the radio's value to submit as well?  I've implemented it as
> such:
> 
> The listener method:
> @RequestParameter private String selectedState;
> 
> public String getSelectedState() {
>     return selectedState;
> }
> public void setSelectedState(String selectedState) {
>     this.selectedState = selectedState;
> }
> 
> public String locationsByState(){
>     availableLocations = new ArrayList<SelectItem>();
>     loadLocations();
>     for(int i=0;i<staticLocations.size();i++){
>         SelectItem current = staticLocations.get(i);
>         if(current.getDescription().trim().equals(selectedState)){
>             availableLocations.add(current);
>         }
>     }
>     return display();        
> }
> 
> The View.  radioSubmit is generating the JS event as in the example:
> <h:selectOneRadio value="#{editProfileAction.selectedState}"
> onmouseup="radioSubmit('hiddenLink');" styleClass="bodyCopy"
> immediate="true">
>     <f:selectItem itemLabel="MA" itemValue="MA"/>
>     <f:selectItem itemLabel="ME" itemValue="ME"/>
>     <f:selectItem itemLabel="NH" itemValue="NH"/>
>     <f:selectItem itemLabel="RI" itemValue="RI"/>
>     <f:selectItem itemLabel="VT" itemValue="VT"/>
> </h:selectOneRadio>
> 
> <t:commandLink id="hiddenLink" forceId="true" style="display:none;
> visibility: hidden;" action="#{editProfileAction.locationsByState}">
> </t:commandLink>
> 
> Thanks for any suggestions



Re: Submitting using SelectOneRadio

Posted by monkeyden <mo...@gmail.com>.
Jeff,
It's all set.  Gavin figured out that it was a bug in my version of Seam. 
Thanks for responding.

Jeff Bischoff wrote:
> 
> Make sure you are using the following import:
> ----
> import javax.faces.event.ValueChangeEvent;
> ----
> 
> As well as the following method signature:
> ----
> public void myMethod(ValueChangeEvent event) {...}
> ----
> 
> And call it like:
> ----
> valueChangeListener="#{myBean.myMethod}"
> ----
> 
> That's about all there is to it. :)
> 
> Regards,
> 
> Jeff Bischoff
> Kenneth L Kurz & Associates, Inc.
> 
> monkeyden wrote:
>> Can someone point me to some resource that describes how JSF handles the
>> valueChangeListener atttribute?  
>> 
>> In my code, I have added it to a <h:selectOneRadio> and implemented the
>> method in my backing bean as myMethod(ValueChangeEvent evt).  When I have
>> the param, it gives a NoSuchMethodException but when I take the param out
>> it
>> calls it just fine.  Tells me that JSF is not expecting the parameter.
>> 
>> It's my understanding that JSF creates the ValueChangeEvent and passes it
>> to
>> the specified method.  Is this true?
>> 
>> 
>> 
>> monkeyden wrote:
>>> Im using this wiki example to submit a form from a radio button:
>>>
>>>  http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 
>>> http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 
>>>
>>> The submit itself is working flawlessly and everything described in the
>>> example is fine.  I was wondering how I could also get the value of the
>>> selected radio button passed to the listener method as well.  I happen
>>> to
>>> be using JBoss Seam components as the business layer, but the main
>>> question is, how can I get the radio's value to submit as well?  I've
>>> implemented it as such:
>>>
>>> The listener method:
>>> @RequestParameter private String selectedState;
>>>
>>> public String getSelectedState() {
>>>     return selectedState;
>>> }
>>> public void setSelectedState(String selectedState) {
>>>     this.selectedState = selectedState;
>>> }
>>>
>>> public String locationsByState(){
>>>     availableLocations = new ArrayList<SelectItem>();
>>>     loadLocations();
>>>     for(int i=0;i<staticLocations.size();i++){
>>>         SelectItem current = staticLocations.get(i);
>>>         if(current.getDescription().trim().equals(selectedState)){
>>>             availableLocations.add(current);
>>>         }
>>>     }
>>>     return display();        
>>> }
>>>
>>> The View.  radioSubmit is generating the JS event as in the example:
>>> <h:selectOneRadio value="#{editProfileAction.selectedState}"
>>> onmouseup="radioSubmit('hiddenLink');" styleClass="bodyCopy"
>>> immediate="true">
>>>     <f:selectItem itemLabel="MA" itemValue="MA"/>
>>>     <f:selectItem itemLabel="ME" itemValue="ME"/>
>>>     <f:selectItem itemLabel="NH" itemValue="NH"/>
>>>     <f:selectItem itemLabel="RI" itemValue="RI"/>
>>>     <f:selectItem itemLabel="VT" itemValue="VT"/>
>>> </h:selectOneRadio>
>>>
>>> <t:commandLink id="hiddenLink" forceId="true" style="display:none;
>>> visibility: hidden;" action="#{editProfileAction.locationsByState}">
>>> </t:commandLink>
>>>
>>> Thanks for any suggestions
>>>
>> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Submitting-using-SelectOneRadio-tf2541475.html#a7099990
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Submitting using SelectOneRadio

Posted by Jeff Bischoff <jb...@klkurz.com>.
Make sure you are using the following import:
----
import javax.faces.event.ValueChangeEvent;
----

As well as the following method signature:
----
public void myMethod(ValueChangeEvent event) {...}
----

And call it like:
----
valueChangeListener="#{myBean.myMethod}"
----

That's about all there is to it. :)

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

monkeyden wrote:
> Can someone point me to some resource that describes how JSF handles the
> valueChangeListener atttribute?  
> 
> In my code, I have added it to a <h:selectOneRadio> and implemented the
> method in my backing bean as myMethod(ValueChangeEvent evt).  When I have
> the param, it gives a NoSuchMethodException but when I take the param out it
> calls it just fine.  Tells me that JSF is not expecting the parameter.
> 
> It's my understanding that JSF creates the ValueChangeEvent and passes it to
> the specified method.  Is this true?
> 
> 
> 
> monkeyden wrote:
>> Im using this wiki example to submit a form from a radio button:
>>
>>  http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 
>> http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 
>>
>> The submit itself is working flawlessly and everything described in the
>> example is fine.  I was wondering how I could also get the value of the
>> selected radio button passed to the listener method as well.  I happen to
>> be using JBoss Seam components as the business layer, but the main
>> question is, how can I get the radio's value to submit as well?  I've
>> implemented it as such:
>>
>> The listener method:
>> @RequestParameter private String selectedState;
>>
>> public String getSelectedState() {
>>     return selectedState;
>> }
>> public void setSelectedState(String selectedState) {
>>     this.selectedState = selectedState;
>> }
>>
>> public String locationsByState(){
>>     availableLocations = new ArrayList<SelectItem>();
>>     loadLocations();
>>     for(int i=0;i<staticLocations.size();i++){
>>         SelectItem current = staticLocations.get(i);
>>         if(current.getDescription().trim().equals(selectedState)){
>>             availableLocations.add(current);
>>         }
>>     }
>>     return display();        
>> }
>>
>> The View.  radioSubmit is generating the JS event as in the example:
>> <h:selectOneRadio value="#{editProfileAction.selectedState}"
>> onmouseup="radioSubmit('hiddenLink');" styleClass="bodyCopy"
>> immediate="true">
>>     <f:selectItem itemLabel="MA" itemValue="MA"/>
>>     <f:selectItem itemLabel="ME" itemValue="ME"/>
>>     <f:selectItem itemLabel="NH" itemValue="NH"/>
>>     <f:selectItem itemLabel="RI" itemValue="RI"/>
>>     <f:selectItem itemLabel="VT" itemValue="VT"/>
>> </h:selectOneRadio>
>>
>> <t:commandLink id="hiddenLink" forceId="true" style="display:none;
>> visibility: hidden;" action="#{editProfileAction.locationsByState}">
>> </t:commandLink>
>>
>> Thanks for any suggestions
>>
> 



Re: Submitting using SelectOneRadio

Posted by monkeyden <mo...@gmail.com>.
Can someone point me to some resource that describes how JSF handles the
valueChangeListener atttribute?  

In my code, I have added it to a <h:selectOneRadio> and implemented the
method in my backing bean as myMethod(ValueChangeEvent evt).  When I have
the param, it gives a NoSuchMethodException but when I take the param out it
calls it just fine.  Tells me that JSF is not expecting the parameter.

It's my understanding that JSF creates the ValueChangeEvent and passes it to
the specified method.  Is this true?



monkeyden wrote:
> 
> Im using this wiki example to submit a form from a radio button:
> 
>  http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 
> http://wiki.apache.org/myfaces/JavascriptWithJavaServerFaces 
> 
> The submit itself is working flawlessly and everything described in the
> example is fine.  I was wondering how I could also get the value of the
> selected radio button passed to the listener method as well.  I happen to
> be using JBoss Seam components as the business layer, but the main
> question is, how can I get the radio's value to submit as well?  I've
> implemented it as such:
> 
> The listener method:
> @RequestParameter private String selectedState;
> 
> public String getSelectedState() {
>     return selectedState;
> }
> public void setSelectedState(String selectedState) {
>     this.selectedState = selectedState;
> }
> 
> public String locationsByState(){
>     availableLocations = new ArrayList<SelectItem>();
>     loadLocations();
>     for(int i=0;i<staticLocations.size();i++){
>         SelectItem current = staticLocations.get(i);
>         if(current.getDescription().trim().equals(selectedState)){
>             availableLocations.add(current);
>         }
>     }
>     return display();        
> }
> 
> The View.  radioSubmit is generating the JS event as in the example:
> <h:selectOneRadio value="#{editProfileAction.selectedState}"
> onmouseup="radioSubmit('hiddenLink');" styleClass="bodyCopy"
> immediate="true">
>     <f:selectItem itemLabel="MA" itemValue="MA"/>
>     <f:selectItem itemLabel="ME" itemValue="ME"/>
>     <f:selectItem itemLabel="NH" itemValue="NH"/>
>     <f:selectItem itemLabel="RI" itemValue="RI"/>
>     <f:selectItem itemLabel="VT" itemValue="VT"/>
> </h:selectOneRadio>
> 
> <t:commandLink id="hiddenLink" forceId="true" style="display:none;
> visibility: hidden;" action="#{editProfileAction.locationsByState}">
> </t:commandLink>
> 
> Thanks for any suggestions
> 

-- 
View this message in context: http://www.nabble.com/Submitting-using-SelectOneRadio-tf2541475.html#a7099044
Sent from the MyFaces - Users mailing list archive at Nabble.com.