【问题标题】:how to prepopulate h:inputText in jsf如何在 jsf 中预填充 h:inputText
【发布时间】:2012-07-25 06:27:51
【问题描述】:

我有两个输入文本,我想用城市和国家/地区的地理位置数据预填充它们。 这是我想用来获取位置的 api

      <script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>

  <script language="Javascript"> 
    document.write(geoplugin_city(), geoplugin_countryName()); 
  </script>

JSF:

<h:inputText id="city" style="width:100%;"  value="#{m.city}"></h:inputText>

<h:inputText id="city" style="width:100%;"  value="#{m.country}"></h:inputText>

【问题讨论】:

    标签: java javascript jsf ip-geolocation


    【解决方案1】:

    第一个:你给inputText 提供了相同的 ID,将第二个更改为 country

    试试这样的

    document.getElementById("yourFormId:city").value = geoplugin_city();
    document.getElementById("yourFormId:country").value = geoplugin_countryName();
    

    【讨论】:

      【解决方案2】:

      那么为什么不创建JavaScript 函数,它将城市和国家名称设置为您的ID(我想您将拥有城市和国家ID,现在inputText 具有相同的ID)。并且只在页面加载时调用它,根据question有两种方法。

      【讨论】:

        猜你喜欢
        • 2011-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-07
        • 2011-04-11
        • 1970-01-01
        • 1970-01-01
        • 2011-02-24
        相关资源
        最近更新 更多