You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Todd Nine <to...@gmail.com> on 2006/12/22 19:04:23 UTC

Noob help for actionEvent

Hi all,
  I'm still learning JSF, so please be patient with me.  I have a form that
must accept both local (US and Canada) address and international address.  I
have a country drop down list and once the focus changes (leave the box), I
want to run a method that will change the values of some fields.
Specifically, I want to change the telephone input fields to free format,
and the state/province from a drop down to free form.  I'm a little confused
about what I need to do in order to show/hide fields dynamically via JSF
without writing my own javascript, as well as just populating the list.  I
have the following form snippet.

    <h:form>

        <h:panelGrid columns="2" border="1">

            <h:outputText value="Address 1:"></h:outputText>
            <h:inputText value="#{address.address1}"
required="true"></h:inputText>


            <h:outputText value="Address 2:"></h:outputText>
            <h:inputText value="#{address.address2}"></h:inputText>

            <h:outputText value="City:"></h:outputText>
            <h:inputText value="#{address.city}"></h:inputText>

            <h:outputText value="Country:" ></h:outputText>
            <h:selectOneListbox value="#{address.country}"
valueChangeListener="#{address.checkCountry}></h:selectOneListbox>

            <h:outputText value="State:"></h:outputText>
            <h:inputText value="#{address.state}"></h:inputText>

            <h:outputText value="State/Province:"></h:outputText>
            <h:inputText value="#{address.stateIntl}"></h:inputText>

...

The country property is the one I want set and evaluated when they exit the
select.  I have the a list of country items  of the following type

private List<SelectItem> countries;

What do I use to set the "options" in the selectOneListbox? I can't seem to
find it in the docs.  Also, when my method "checkCountry" is fired, how do I
hide my "state" label and input box and show my "State/Province" label and
input box?

Thanks for the help.

Todd

Re: Noob help for actionEvent

Posted by Mike Kienenberger <mk...@gmail.com>.
Todd,

If you are doing this with server-side processing (which I doubt is
what you really want), it'd be a matter of setting the boolean value
of the "rendered" attribute -- false means don't show or process it
and true means show and process it.  You would make the
selectOneListbox automatically submit the containing form when the
value was changed.  I've used this approach in the past when each
potential selection in the UISelectOne component would produce a
different set of results on the page.

However, you probably want to be doing this client-side so that
changing the form doesn't require a round trip to the server since
your situation is pretty straight-forward.   You'd do this with
javascript, probably by doing something along these lines:

document.getElementById('yourForm:stateSelector').style.visibility='hidden';
document.getElementById('yourForm:stateIntlSelector').style.visibility='visible';

I'm a javascript novice, though, so there are likely to be better ways
to write the javascript.


On 12/22/06, Todd Nine <to...@gmail.com> wrote:
> Hi all,
>   I'm still learning JSF, so please be patient with me.  I have a form that
> must accept both local (US and Canada) address and international address.  I
> have a country drop down list and once the focus changes (leave the box), I
> want to run a method that will change the values of some fields.
> Specifically, I want to change the telephone input fields to free format,
> and the state/province from a drop down to free form.  I'm a little confused
> about what I need to do in order to show/hide fields dynamically via JSF
> without writing my own javascript, as well as just populating the list.  I
> have the following form snippet.
>
>     <h:form>
>
>         <h:panelGrid columns="2" border="1">
>
>             <h:outputText value="Address 1:"></h:outputText>
>             <h:inputText value="#{ address.address1}"
> required="true"></h:inputText>
>
>
>             <h:outputText value="Address 2:"></h:outputText>
>             <h:inputText value="#{address.address2 }"></h:inputText>
>
>             <h:outputText value="City:"></h:outputText>
>             <h:inputText value="#{address.city}"></h:inputText>
>
>             <h:outputText value="Country:" ></h:outputText>
>             <h:selectOneListbox value="#{address.country}"
> valueChangeListener="#{address.checkCountry}></h:selectOneListbox>
>
>             <h:outputText value="State:"></h:outputText>
>             <h:inputText value="#{address.state}"></h:inputText>
>
>             <h:outputText
> value="State/Province:"></h:outputText>
>              <h:inputText value="#{address.stateIntl}"></h:inputText>
>
> ...
>
> The country property is the one I want set and evaluated when they exit the
> select.  I have the a list of country items  of the following type
>
> private List<SelectItem> countries;
>
> What do I use to set the "options" in the selectOneListbox? I can't seem to
> find it in the docs.  Also, when my method "checkCountry" is fired, how do I
> hide my "state" label and input box and show my "State/Province" label and
> input box?
>
> Thanks for the help.
>
> Todd
>
>
>