You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by laredotornado <la...@gmail.com> on 2009/12/16 23:26:49 UTC
How do I change the value of a selectOneMenu on the fly
Hi,
I'm using MyFaces 1.1.6 and Tomahawk 1.1.9. I have this selectOneMenu ...
<h:selectOneMenu required="true"
validator="#{historicalTour.validateTime}" styleClass="hourMenu"
id="historicalTour1st_Preference_Hour"
value="#{historicalTour.prefs[0].time}">
<f:selectItems value="#{historicalTour.timePrefItems}"/>
</h:selectOneMenu>
When another text field on the page changes value, I would like to
re-populate the select menu with new options. I have discovered I just
can't simply do that with Javascript, because when I submit the form I get a
"Value is not a valid option"
error. Any ideas how I can change my select menu options and keep JSF
happy?
Thanks, - Dave
--
View this message in context: http://old.nabble.com/How-do-I-change-the-value-of-a-selectOneMenu-on-the-fly-tp26819601p26819601.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: How do I change the value of a selectOneMenu on the fly
Posted by laredotornado <la...@gmail.com>.
Muchas gracias para tu ayuda! I have one last question. When the form
submits, I get all these validation errors, which makes sense, because
normally when I submit my form, I have to validate certain fields.
But in my case, when the value of that text box changes, I want to submit
the form (to re-populate another select menu) but I DON'T want to do
validation. Is there any way to skip the validation phase when the only
reason I want to reload the page is to re-populate the selectOneMenu?
Thanks, - Dave
Julián Osorio Amaya EuphoriaIT wrote:
>
> laredotornado escribió:
>> Could you show the method of the Javascript submit() function that you
>> are
>> talking about? I'm having a hard time imagining how what you list is
>> different than submitting the form.
>>
>> Thanks, - Dave
>>
>>
>>
>> Julián Osorio Amaya EuphoriaIT wrote:
>>
>>> laredotornado escribió:
>>>
>>>> Thanks, Julian. I have a follow-up question regarding your solution.
>>>> You
>>>> include an onchange Javascript handler where you submit the form, at
>>>> least,
>>>> I assume that's what submit() does. How do I submit the form, keep it
>>>> on
>>>> the same page, preserve the values that were already entered, and not
>>>> prompt
>>>> validation? Is it as simple as "this.form.submit();"?
>>>>
>>>> Thanks, - Dave
>>>>
>>>>
>>>>
>>>> Julián Osorio Amaya EuphoriaIT wrote:
>>>>
>>>>
>>>>> laredotornado escribió:
>>>>>
>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I'm using MyFaces 1.1.6 and Tomahawk 1.1.9. I have this
>>>>>> selectOneMenu
>>>>>> ...
>>>>>>
>>>>>> <h:selectOneMenu required="true"
>>>>>> validator="#{historicalTour.validateTime}" styleClass="hourMenu"
>>>>>> id="historicalTour1st_Preference_Hour"
>>>>>> value="#{historicalTour.prefs[0].time}">
>>>>>> <f:selectItems value="#{historicalTour.timePrefItems}"/>
>>>>>> </h:selectOneMenu>
>>>>>>
>>>>>> When another text field on the page changes value, I would like to
>>>>>> re-populate the select menu with new options. I have discovered I
>>>>>> just
>>>>>> can't simply do that with Javascript, because when I submit the form
>>>>>> I
>>>>>> get a
>>>>>>
>>>>>> "Value is not a valid option"
>>>>>>
>>>>>> error. Any ideas how I can change my select menu options and keep
>>>>>> JSF
>>>>>> happy?
>>>>>>
>>>>>> Thanks, - Dave
>>>>>>
>>>>>>
>>>>>>
>>>>> You can use a Value Change Listener in your text field like this
>>>>> <h:inputText valueChangeListener="#{BackingBean.methodName}"
>>>>> onchange="submit()" />
>>>>>
>>>>> in your backing bean
>>>>>
>>>>> public BackingBean implements ValueChangeListener {
>>>>> public void processValueChange(ValueChangeEvent valueChangeEvent)
>>>>> {
>>>>> }
>>>>>
>>>>> public void methodName(ValueChangeEvent vce) {
>>>>> //change your select menu options
>>>>> }
>>>>> }
>>>>>
>>>>> --
>>>>> <?xml version = '1.0' encoding = 'UTF-8'?>
>>>>> <firma>
>>>>> <nombre>Julian Osorio Amaya</nombre>
>>>>> </firma>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>> the function of the javascript event "onchange" is invoke the method in
>>> the valueChangeListener="#{BackingBean.yourMethod}"
>>> but it's different from the submit action on <h:commandButton
>>> action="#{BackingBean.submitForm}" />
>>>
>>> --
>>> <?xml version = '1.0' encoding = 'UTF-8'?>
>>> <firma>
>>> <nombre>Julian Osorio Amaya</nombre>
>>> </firma>
>>>
>>>
>>>
>>>
>>
>>
> there's no body for the submit() function.
> Do a little test adding this to one of your forms
> <h:inputText value="#{BackingBean.value}"
> valueChangeListener="#{BackingBean.method}" onchange="submit()" />
> Every time you change the value in the <h:inputText /> tag there's a
> submit that invokes the valueChangeListener's method
> but it's different from a "real" form submit invoked by <h:commandButton
> /> tag
>
> --
> <?xml version = '1.0' encoding = 'UTF-8'?>
> <firma>
> <nombre>Julian Osorio Amaya</nombre>
> </firma>
>
>
>
--
View this message in context: http://old.nabble.com/How-do-I-change-the-value-of-a-selectOneMenu-on-the-fly-tp26819601p26830365.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: How do I change the value of a selectOneMenu on the fly
Posted by Julián Osorio Amaya EuphoriaIT <jo...@euphoriait.com>.
laredotornado escribió:
> Could you show the method of the Javascript submit() function that you are
> talking about? I'm having a hard time imagining how what you list is
> different than submitting the form.
>
> Thanks, - Dave
>
>
>
> Julián Osorio Amaya EuphoriaIT wrote:
>
>> laredotornado escribió:
>>
>>> Thanks, Julian. I have a follow-up question regarding your solution.
>>> You
>>> include an onchange Javascript handler where you submit the form, at
>>> least,
>>> I assume that's what submit() does. How do I submit the form, keep it on
>>> the same page, preserve the values that were already entered, and not
>>> prompt
>>> validation? Is it as simple as "this.form.submit();"?
>>>
>>> Thanks, - Dave
>>>
>>>
>>>
>>> Julián Osorio Amaya EuphoriaIT wrote:
>>>
>>>
>>>> laredotornado escribió:
>>>>
>>>>
>>>>> Hi,
>>>>>
>>>>> I'm using MyFaces 1.1.6 and Tomahawk 1.1.9. I have this selectOneMenu
>>>>> ...
>>>>>
>>>>> <h:selectOneMenu required="true"
>>>>> validator="#{historicalTour.validateTime}" styleClass="hourMenu"
>>>>> id="historicalTour1st_Preference_Hour"
>>>>> value="#{historicalTour.prefs[0].time}">
>>>>> <f:selectItems value="#{historicalTour.timePrefItems}"/>
>>>>> </h:selectOneMenu>
>>>>>
>>>>> When another text field on the page changes value, I would like to
>>>>> re-populate the select menu with new options. I have discovered I just
>>>>> can't simply do that with Javascript, because when I submit the form I
>>>>> get a
>>>>>
>>>>> "Value is not a valid option"
>>>>>
>>>>> error. Any ideas how I can change my select menu options and keep JSF
>>>>> happy?
>>>>>
>>>>> Thanks, - Dave
>>>>>
>>>>>
>>>>>
>>>> You can use a Value Change Listener in your text field like this
>>>> <h:inputText valueChangeListener="#{BackingBean.methodName}"
>>>> onchange="submit()" />
>>>>
>>>> in your backing bean
>>>>
>>>> public BackingBean implements ValueChangeListener {
>>>> public void processValueChange(ValueChangeEvent valueChangeEvent) {
>>>> }
>>>>
>>>> public void methodName(ValueChangeEvent vce) {
>>>> //change your select menu options
>>>> }
>>>> }
>>>>
>>>> --
>>>> <?xml version = '1.0' encoding = 'UTF-8'?>
>>>> <firma>
>>>> <nombre>Julian Osorio Amaya</nombre>
>>>> </firma>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>> the function of the javascript event "onchange" is invoke the method in
>> the valueChangeListener="#{BackingBean.yourMethod}"
>> but it's different from the submit action on <h:commandButton
>> action="#{BackingBean.submitForm}" />
>>
>> --
>> <?xml version = '1.0' encoding = 'UTF-8'?>
>> <firma>
>> <nombre>Julian Osorio Amaya</nombre>
>> </firma>
>>
>>
>>
>>
>
>
there's no body for the submit() function.
Do a little test adding this to one of your forms
<h:inputText value="#{BackingBean.value}"
valueChangeListener="#{BackingBean.method}" onchange="submit()" />
Every time you change the value in the <h:inputText /> tag there's a
submit that invokes the valueChangeListener's method
but it's different from a "real" form submit invoked by <h:commandButton
/> tag
--
<?xml version = '1.0' encoding = 'UTF-8'?>
<firma>
<nombre>Julian Osorio Amaya</nombre>
</firma>
Re: How do I change the value of a selectOneMenu on the fly
Posted by laredotornado <la...@gmail.com>.
Could you show the method of the Javascript submit() function that you are
talking about? I'm having a hard time imagining how what you list is
different than submitting the form.
Thanks, - Dave
Julián Osorio Amaya EuphoriaIT wrote:
>
> laredotornado escribió:
>> Thanks, Julian. I have a follow-up question regarding your solution.
>> You
>> include an onchange Javascript handler where you submit the form, at
>> least,
>> I assume that's what submit() does. How do I submit the form, keep it on
>> the same page, preserve the values that were already entered, and not
>> prompt
>> validation? Is it as simple as "this.form.submit();"?
>>
>> Thanks, - Dave
>>
>>
>>
>> Julián Osorio Amaya EuphoriaIT wrote:
>>
>>> laredotornado escribió:
>>>
>>>> Hi,
>>>>
>>>> I'm using MyFaces 1.1.6 and Tomahawk 1.1.9. I have this selectOneMenu
>>>> ...
>>>>
>>>> <h:selectOneMenu required="true"
>>>> validator="#{historicalTour.validateTime}" styleClass="hourMenu"
>>>> id="historicalTour1st_Preference_Hour"
>>>> value="#{historicalTour.prefs[0].time}">
>>>> <f:selectItems value="#{historicalTour.timePrefItems}"/>
>>>> </h:selectOneMenu>
>>>>
>>>> When another text field on the page changes value, I would like to
>>>> re-populate the select menu with new options. I have discovered I just
>>>> can't simply do that with Javascript, because when I submit the form I
>>>> get a
>>>>
>>>> "Value is not a valid option"
>>>>
>>>> error. Any ideas how I can change my select menu options and keep JSF
>>>> happy?
>>>>
>>>> Thanks, - Dave
>>>>
>>>>
>>> You can use a Value Change Listener in your text field like this
>>> <h:inputText valueChangeListener="#{BackingBean.methodName}"
>>> onchange="submit()" />
>>>
>>> in your backing bean
>>>
>>> public BackingBean implements ValueChangeListener {
>>> public void processValueChange(ValueChangeEvent valueChangeEvent) {
>>> }
>>>
>>> public void methodName(ValueChangeEvent vce) {
>>> //change your select menu options
>>> }
>>> }
>>>
>>> --
>>> <?xml version = '1.0' encoding = 'UTF-8'?>
>>> <firma>
>>> <nombre>Julian Osorio Amaya</nombre>
>>> </firma>
>>>
>>>
>>>
>>>
>>
>>
> the function of the javascript event "onchange" is invoke the method in
> the valueChangeListener="#{BackingBean.yourMethod}"
> but it's different from the submit action on <h:commandButton
> action="#{BackingBean.submitForm}" />
>
> --
> <?xml version = '1.0' encoding = 'UTF-8'?>
> <firma>
> <nombre>Julian Osorio Amaya</nombre>
> </firma>
>
>
>
--
View this message in context: http://old.nabble.com/How-do-I-change-the-value-of-a-selectOneMenu-on-the-fly-tp26819601p26828813.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: How do I change the value of a selectOneMenu on the fly
Posted by Julián Osorio Amaya EuphoriaIT <jo...@euphoriait.com>.
laredotornado escribió:
> Thanks, Julian. I have a follow-up question regarding your solution. You
> include an onchange Javascript handler where you submit the form, at least,
> I assume that's what submit() does. How do I submit the form, keep it on
> the same page, preserve the values that were already entered, and not prompt
> validation? Is it as simple as "this.form.submit();"?
>
> Thanks, - Dave
>
>
>
> Julián Osorio Amaya EuphoriaIT wrote:
>
>> laredotornado escribió:
>>
>>> Hi,
>>>
>>> I'm using MyFaces 1.1.6 and Tomahawk 1.1.9. I have this selectOneMenu
>>> ...
>>>
>>> <h:selectOneMenu required="true"
>>> validator="#{historicalTour.validateTime}" styleClass="hourMenu"
>>> id="historicalTour1st_Preference_Hour"
>>> value="#{historicalTour.prefs[0].time}">
>>> <f:selectItems value="#{historicalTour.timePrefItems}"/>
>>> </h:selectOneMenu>
>>>
>>> When another text field on the page changes value, I would like to
>>> re-populate the select menu with new options. I have discovered I just
>>> can't simply do that with Javascript, because when I submit the form I
>>> get a
>>>
>>> "Value is not a valid option"
>>>
>>> error. Any ideas how I can change my select menu options and keep JSF
>>> happy?
>>>
>>> Thanks, - Dave
>>>
>>>
>> You can use a Value Change Listener in your text field like this
>> <h:inputText valueChangeListener="#{BackingBean.methodName}"
>> onchange="submit()" />
>>
>> in your backing bean
>>
>> public BackingBean implements ValueChangeListener {
>> public void processValueChange(ValueChangeEvent valueChangeEvent) {
>> }
>>
>> public void methodName(ValueChangeEvent vce) {
>> //change your select menu options
>> }
>> }
>>
>> --
>> <?xml version = '1.0' encoding = 'UTF-8'?>
>> <firma>
>> <nombre>Julian Osorio Amaya</nombre>
>> </firma>
>>
>>
>>
>>
>
>
the function of the javascript event "onchange" is invoke the method in
the valueChangeListener="#{BackingBean.yourMethod}"
but it's different from the submit action on <h:commandButton
action="#{BackingBean.submitForm}" />
--
<?xml version = '1.0' encoding = 'UTF-8'?>
<firma>
<nombre>Julian Osorio Amaya</nombre>
</firma>
Re: How do I change the value of a selectOneMenu on the fly
Posted by laredotornado <la...@gmail.com>.
Thanks, Julian. I have a follow-up question regarding your solution. You
include an onchange Javascript handler where you submit the form, at least,
I assume that's what submit() does. How do I submit the form, keep it on
the same page, preserve the values that were already entered, and not prompt
validation? Is it as simple as "this.form.submit();"?
Thanks, - Dave
Julián Osorio Amaya EuphoriaIT wrote:
>
> laredotornado escribió:
>> Hi,
>>
>> I'm using MyFaces 1.1.6 and Tomahawk 1.1.9. I have this selectOneMenu
>> ...
>>
>> <h:selectOneMenu required="true"
>> validator="#{historicalTour.validateTime}" styleClass="hourMenu"
>> id="historicalTour1st_Preference_Hour"
>> value="#{historicalTour.prefs[0].time}">
>> <f:selectItems value="#{historicalTour.timePrefItems}"/>
>> </h:selectOneMenu>
>>
>> When another text field on the page changes value, I would like to
>> re-populate the select menu with new options. I have discovered I just
>> can't simply do that with Javascript, because when I submit the form I
>> get a
>>
>> "Value is not a valid option"
>>
>> error. Any ideas how I can change my select menu options and keep JSF
>> happy?
>>
>> Thanks, - Dave
>>
> You can use a Value Change Listener in your text field like this
> <h:inputText valueChangeListener="#{BackingBean.methodName}"
> onchange="submit()" />
>
> in your backing bean
>
> public BackingBean implements ValueChangeListener {
> public void processValueChange(ValueChangeEvent valueChangeEvent) {
> }
>
> public void methodName(ValueChangeEvent vce) {
> //change your select menu options
> }
> }
>
> --
> <?xml version = '1.0' encoding = 'UTF-8'?>
> <firma>
> <nombre>Julian Osorio Amaya</nombre>
> </firma>
>
>
>
--
View this message in context: http://old.nabble.com/How-do-I-change-the-value-of-a-selectOneMenu-on-the-fly-tp26819601p26819977.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: How do I change the value of a selectOneMenu on the fly
Posted by Julián Osorio Amaya EuphoriaIT <jo...@euphoriait.com>.
laredotornado escribió:
> Hi,
>
> I'm using MyFaces 1.1.6 and Tomahawk 1.1.9. I have this selectOneMenu ...
>
> <h:selectOneMenu required="true"
> validator="#{historicalTour.validateTime}" styleClass="hourMenu"
> id="historicalTour1st_Preference_Hour"
> value="#{historicalTour.prefs[0].time}">
> <f:selectItems value="#{historicalTour.timePrefItems}"/>
> </h:selectOneMenu>
>
> When another text field on the page changes value, I would like to
> re-populate the select menu with new options. I have discovered I just
> can't simply do that with Javascript, because when I submit the form I get a
>
> "Value is not a valid option"
>
> error. Any ideas how I can change my select menu options and keep JSF
> happy?
>
> Thanks, - Dave
>
You can use a Value Change Listener in your text field like this
<h:inputText valueChangeListener="#{BackingBean.methodName}"
onchange="submit()" />
in your backing bean
public BackingBean implements ValueChangeListener {
public void processValueChange(ValueChangeEvent valueChangeEvent) {
}
public void methodName(ValueChangeEvent vce) {
//change your select menu options
}
}
--
<?xml version = '1.0' encoding = 'UTF-8'?>
<firma>
<nombre>Julian Osorio Amaya</nombre>
</firma>