users@woodstock.java.net

Re: Asynchronously submit and refresh. How to?

From: Arnaud Brand <arnaud.brand_at_free.fr>
Date: Mon, 19 May 2008 18:15:45 +0200
Hi Stefan,

Instead using
dd1.submit("form1:cal1,form1:txt1");
dd2.refresh("form1:dd1");
I would rather try
dd2.refresh("form1:dd1,form1:cal1,form1:txt1");
This should submit dd1, cal1 and txt1, trigger your event listener and refresh dd2.

2 reasons for that :
- if your bean "Bean" is scoped at the request level your second call (dd2.refresh) will have "lost" the values from your first call (dd1.submit).
- it might be that dd2.refresh is called before dd1.submit actually returns (because submit is asynchronous), so may be your dd2 values are set in the bean after having already been read by dd2.refresh.

I hope that helps. Have a nice evening,
Arnaud

Stefan Bley a écrit :
Hi woodstock users,

I'd like to put new elements in a dropdown when another dropdown's selection
has changed.
Which elements are put inside is dependent on the values of a calendar and a
text field.

I tried this:

<webuijsf:script>
function handleDd1Change() {
                                var dd1 =
document.getElementById('form1:dd1');
                                var dd2 =
document.getElementById('form1:dd2');
                                var cal1 =
document.getElementById('form1:cal1');
                                var txt1 =
document.getElementById("form1:txt1");

                                dd1.submit("form1:cal1,form1:txt1");
                                dd2.refresh("form1:dd1");
                            }
</webuijsf:script>

<webuijsf:dropDown id="dd1" items="#{Bean.dd1DefaultOptions.options}"
onChange="setTimeout('handleDd1Change();',0)" selected="#{Bean.dd1Value}"
valueChangeListenerExpression="#{Bean.dd1_processValueChange}" />
<webuijsf:dropDown id="dd2" items="#{Bean.dd2DefaultOptions.options}"
selected="#{Bean.dd2Value}" />
<webuijsf:calendar id="cal1" selectedDate="#{Bean.cal1Value}" />
<webuijsf:textField id="txt1" text="#{Bean.txt1Value}" />

In the bean I have:

public void dd1_processValueChange(ValueChangeEvent event) {
        setNewValuesForDd2(event.getNewValue(), getCal1Value(),
getTxt1Value());
    }

However, the values of getCal1Value() and getTxt1Value() are both null! I
thought when I put their component id's in dd1's submit method, the backing
bean's values are updated. Do I miss something?

Thanks for help, Stefan