开发者

Javascript with JSF

I'm using th开发者_JAVA百科e Google Maps API to get a users location on the client side...I want to then send this to the server side to do some processing and populate a select box (with local addresses).

Whats the best way of doing this? Prefereably I would like to press a button and populate the box using ajax.

Thanks!


Here is an example of how to pass a Javascript value (your user location) to the bean with Ajax.

The location will be stored in the <h:inputHidden> field. The execute attribute of <f:ajax> specifies the value(s) that will be sent to the server to process.

<h:form id="formname">
    <h:inputHidden value="#{indexBean.value}" id="hvalue" />
    <h:commandButton value="action" onclick="getLocation();" action="#{indexBean.doSome}">
        <f:ajax execute="hvalue" render="output" />
    </h:commandButton>
    <h:outputText value="#{indexBean.output}" id="output" />
</h:form>

Before the Ajax request is sent the onclick attribute of the <h:commandButton> specifies the Javascript function to execute. Your Javascript function should set the value in your hidden field.

function getLocation() {        
    document.getElementById("formname:hvalue").value = "TEST";                       
}

The render attribue of <f:ajax> specifies what to update on the client side. In this case its an <h:outputText> in your case it will be your <h:selectOneMenu>.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜