0

I have a page with a selectOneMenu and I was wondering if there is any way that I can update a content in another div without a page refresh. I am trying this right now and this doesnt work. I know that I can do onChange="submit()", but that refreshes the page, I dont want the page to refresh Also, would this be possible with hx:behavior and/or ajaxRefreshSubmit? If yes can someone show me a simple example to achieve that. Thanks for the help

<hx:selectOneMenu value="#{bean.myValue}"
    valueChangeListener="#{controller.valueChangeMethod}">
    <f:selectItems value="#{bean.values}" />
</hx:selectOneMenu>

<div id="divToBeUpdated">
#{bean.displayValue}
</div>

1 Answer 1

2

you could use ajax for above purpose. here is sample code

<h:form id="welcome">
<h:selectOneMenu id="countrydropdown" value="#{pracBB.mycountry}" >
 <f:selectItem itemLabel="India" itemValue="ind"/>
<f:selectItem itemLabel="usa" itemValue="usa"/>
<a4j:support event="onchange"  action="#{pracBB.changeData}" reRender="welcome">        </a4j:support>
 </h:selectOneMenu>



<h:outputText value="#{pracBB.dynamicString}"/>
</h:form>

Backing bean code private String mycountry;

private String dynamicString="default";


public void changeData()

{



    if(mycountry.equalsIgnoreCase("usa"))
    {
        dynamicString="you have selected usa";  
    }

    else
    {
        dynamicString="you have selected india";

    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.