(这个问题已得到解答:How make commandButton not fully refresh page? How to use f:ajax?)
我在JSF中使用Ajax遇到了一些问题。我有返回字符串的方法,并且只想在单击按钮时打印此字符串。这个方法使用两个参数,我想用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>
但是问题仍然存在:在单击按钮之前就显示字符串。