You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Stephen Osella <so...@austin.rr.com> on 2006/11/02 23:43:42 UTC

How can you update other UI components on change of another UI component (non-ajax)?

I need to change a setting on one or more UI components (e.g., menus) based 
on the user selecting a different value on another menu.  I have these menu 
UI components in a form that does not contain an command buttons or links. 
Here is an example:

<form>

<h:selectOneMenu id="var1Menu" value="#{SessionBean.var1}" 
onchange="submit( );" 
valueChangeListener="#{SessionBean.var1ValueChangeListener}">
    <f:selectItems value="#{SessionBean.var1Items}" />
</h:selectOneMenu>

<h:selectOneMenu id="var2Menu" value="#{SessionBean.var2}" 
onchange="submit( );" 
valueChangeListener="#{SessionBean.var2ValueChangeListener}">
    <f:selectItems value="#{SessionBean.var2Items}" />
</h:selectOneMenu>

</form>


For instance, in the "var1ValueChangeListener" I am changing the Bean's var2 
field which governs the value (selected item) of the other menu in the form. 
However, that menu is not changing the selected item in a consistent (and 
very confusing) way.

Is this even possible?  It should be right?  Do I need a command button or 
link in the form?  I am not using AJAX as of yet.  I am going to work on 
that when I get this working.

What am I doing wrong?

Thanks! 


Re: Download location for sandbox JAR and Example Source Files?

Posted by Wdiaz <wd...@unipamplona.edu.co>.
Stephen Osella escribió:
> Do you know the location for downloading the sandbox JAR and example 
> source files?
>
> Thanks for the tip about the sandbox.  The s:pprPanelGroup looks like 
> what I need.
>
http://people.apache.org/builds/myfaces/nightly/

-- 
Cordialmente

William Diaz Pabón
Coordinador Técnico de Desarrollo
Vicerrectoría de Gestión y Desarrollo Tecnológico
Universidad de Pamplona


Download location for sandbox JAR and Example Source Files?

Posted by Stephen Osella <so...@austin.rr.com>.
Do you know the location for downloading the sandbox JAR and example source 
files?

Thanks for the tip about the sandbox.  The s:pprPanelGroup looks like what I 
need. 


Re: How can you update other UI components on change of another UI component (non-ajax)?

Posted by Gerald Müllan <bi...@gmail.com>.
Hi,

in case of the selectOneMenu there is a very nice solution in sandbox,
which works perfectly.

Have a look at the examples-page:

http://example.irian.at/example-sandbox-20061103/ajaxChildComboBox.jsf

regards,

Gerald

On 11/3/06, Stephen Osella <so...@austin.rr.com> wrote:
>
>
> One thing I noticed is that the backing bean's value method for var2 (whose
> value is set in var1ValueChangeListener) is not being called when
> re-rendering the page.  That is, to set the selected item of the
> SessionBean.var2Items() .  I have tried this with and without
> immediate="true".
>
> How should you do this?  I think it should be very simple.
>
>
> <form>
>
> <h:selectOneMenu id="var1Menu" value="#{SessionBean.var1}"
> onchange="submit( );"
> valueChangeListener="#{SessionBean.var1ValueChangeListener
> }">
>     <f:selectItems value="#{SessionBean.var1Items}" />
> </h:selectOneMenu>
>
> <h:selectOneMenu id="var2Menu" value="#{SessionBean.var2}"
> onchange="submit( );"
> valueChangeListener="#{SessionBean.var2ValueChangeListener}">
>     <f:selectItems value="#{SessionBean.var2Items}" />
> </h:selectOneMenu>
>
> </form>
>


-- 
http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: How can you update other UI components on change of another UI component (non-ajax)?

Posted by Stephen Osella <so...@austin.rr.com>.
One thing I noticed is that the backing bean's value method for var2 (whose value is set in var1ValueChangeListener) is not being called when re-rendering the page.  That is, to set the selected item of the SessionBean.var2Items() .  I have tried this with and without immediate="true".

How should you do this?  I think it should be very simple.


<form>

<h:selectOneMenu id="var1Menu" value="#{SessionBean.var1}"
onchange="submit( );"
valueChangeListener="#{SessionBean.var1ValueChangeListener }">
    <f:selectItems value="#{SessionBean.var1Items}" />
</h:selectOneMenu>

<h:selectOneMenu id="var2Menu" value="#{SessionBean.var2}"
onchange="submit( );" 
valueChangeListener="#{SessionBean.var2ValueChangeListener}">
    <f:selectItems value="#{SessionBean.var2Items}" />
</h:selectOneMenu>

</form>

Re: How can you update other UI components on change of another UI component (non-ajax)?

Posted by Stephen Osella <so...@austin.rr.com>.
Cagatay,

Here is the ValueChangeListener:

public void var1ValueChangeListener(ValueChangeEvent e)
{
    FacesContext context = FacesContext.getCurrentInstance();
    this.var1 = (Integer) e.getNewValue();
    valueChanged();
    context.renderResponse();
}


In the valueChanged() method is where I set the other menu item values based 
on var1 (for example). 


Re: How can you update other UI components on change of another UI component (non-ajax)?

Posted by Cagatay Civici <ca...@gmail.com>.
Yes, it's possible.

Can you post your var1ValueChangeListener, value change listeners are a bit
tricky at first.

Also are there any validation errors?

Cagatay

On 11/3/06, Stephen Osella <so...@austin.rr.com> wrote:
>
> I need to change a setting on one or more UI components (e.g., menus)
> based
> on the user selecting a different value on another menu.  I have these
> menu
> UI components in a form that does not contain an command buttons or links.
> Here is an example:
>
> <form>
>
> <h:selectOneMenu id="var1Menu" value="#{SessionBean.var1}"
> onchange="submit( );"
> valueChangeListener="#{SessionBean.var1ValueChangeListener}">
>     <f:selectItems value="#{SessionBean.var1Items}" />
> </h:selectOneMenu>
>
> <h:selectOneMenu id="var2Menu" value="#{SessionBean.var2}"
> onchange="submit( );"
> valueChangeListener="#{SessionBean.var2ValueChangeListener}">
>     <f:selectItems value="#{SessionBean.var2Items}" />
> </h:selectOneMenu>
>
> </form>
>
>
> For instance, in the "var1ValueChangeListener" I am changing the Bean's
> var2
> field which governs the value (selected item) of the other menu in the
> form.
> However, that menu is not changing the selected item in a consistent (and
> very confusing) way.
>
> Is this even possible?  It should be right?  Do I need a command button or
> link in the form?  I am not using AJAX as of yet.  I am going to work on
> that when I get this working.
>
> What am I doing wrong?
>
> Thanks!
>
>