【发布时间】:2017-06-06 01:08:54
【问题描述】:
在 JSF 中使用 ajax 时遇到了一些问题。 事实上,我正在尝试我要做的事情很简单,但我无法弄清楚。 我有返回字符串的方法,并且我只想在单击按钮时打印此字符串。这个方法需要 2 个参数,我想用 2 个 inputBox 传递给该方法。 这是我到目前为止提供的代码,但它还没有完成,如果我做得很好,我不会:
<h:commandButton id="submit" value="Submit">
<f:ajax event="click" />
</h:commandButton>
<h:outputText id="result" value="#{cSVobjectCtrl.getJson(48.866667, 2.33333)}" />
这段代码的问题是我在点击按钮之前直接得到了字符串。我应该改变什么才能使这段代码按我想要的方式工作。
编辑 1:
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>JsonValue</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script>
var show = function(){
document.getElementById('result').style.display = 'block';
}
</script>
</h:head>
<h:form>
<h:commandButton id="submit" value="Submit" onclick="show();" >
<f:ajax event="click" render="result"/>
</h:commandButton>
<h:outputText id="result" value="#{cSVobjectCtrl.getJson(48.866667, 2.33333)}"
style="display:'none'"/>
</h:form>
</html>
但问题仍然存在。在我单击按钮之前会显示字符串。
【问题讨论】: