问题描述
目前,我正在使用Draw2D的库来绘制形状和图表的Web应用程序。在服务器端,我使用的Java(JSF)。
Currently, I am working on a web application that uses draw2d library to draw shapes and charts. On the server side I am using Java(JSF).
我可以说,95%这个应用只是纯粹的JavaScript。我希望能够从无需使用隐藏域发送Ajax请求我的JavaScript内,如< F:inputText的>
(可能使用jQuery的Ajax组件?)。
I can say that 95% of this application is just pure JavaScript. I like to be able to send Ajax requests from inside my JavaScript with no need of using hidden fields such as <f:inputText>
(perhaps using jQuery Ajax components?).
我试图通过添加不同的隐藏JFS组件和 jsf.ajax.request
,但是由于各种原因,他们也不是很可靠的破解解决这个有时候他们不发送Ajax请求。
I tried to hack around this by adding different hidden JFS component and jsf.ajax.request
, but for whatever reason they are not very reliable and sometimes they don't send the ajax request.
任何建议?此外,关于jQuery的,我不知道如何处理在服务器端的请求。
Any suggestion? Also, about jQuery, I am not sure how to process the request on the server side.
答:最后我用什么戴维建议。我pviously试$ P $使用jsFunction从这个链接,但我得到的错误。显然,问题是,这还没有实现在RichFaces的4。但是,如果你使用,戴夫提到它完美的作品。
Answer: I ended up using what Dave suggested. I previously tried to use jsFunction from this link, but I got error. Apparently, the problem is , which is not yet implemented in Richfaces 4. However, if you use , as dave mentioned it works perfectly.
还有一点,豆类并没有为我工作的戴维potsed。我不得不改变它,如下所示: @ManagedBean(NAME =jsFunctionBean)@SessionScoped公共类JsFunctionBean {
One more point, the beans didn't work for me as Dave potsed. I had to change it as follows: @ManagedBean(name = "jsFunctionBean")@SessionScopedpublic class JsFunctionBean {
/**
* Test String name
*/
private String name;
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
/**
* Test boolean
*/
private boolean test;
public boolean getTest() { return this.test; }
public void setTest(boolean test) { this.test = test; }
/**
* Action Method
*
* @return
*/
public String getActionMethod() {
return null;
}
public String actionMethod(){
this.test = true;
this.name = "Dave";
return null;
}
}
我不知道为什么是这样的情况,但如果我删除getActionMethod或actionMenthod我会得到错误!
I am not sure why this is the case, but if I remove getActionMethod or actionMenthod I would get error!
推荐答案
如果你是为第三方库RichFaces的A4J:jsFunction提供了一个JavaScript函数调用服务器端方法的能力,以及通过能力串行化为JSON回回调函数的对象:
If you are up for a third party library Richfaces a4j:jsFunction offers the ability to invoke a server side method with a javascript function as well as the ability to pass a object serialized as json back to a callback function:
<h:form id="form1" prependId="false">
<a4j:jsFunction
name="submitApplication"
action="#{jsFunctionBean.actionMethod}"
data="#{jsFunctionBean}"
oncomplete="processData(event.data)"
immediate="true">
</a4j:jsFunction>
<script type="text/javascript">
//example callback function
function processData(data) {
alert(data.test);
alert(data.name);
}
//call the ajax method from javascript
submitApplication();
</script>
</h:form>
和你的Bean:
@ManagedBean(name = "jsFunctionBean")
@SessionScoped
public class JsFunctionBean {
/**
* Test String name
*/
private String name;
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
/**
* Test boolean
*/
private boolean test;
public boolean getTest() { return this.test; }
public void setTest(boolean test) { this.test = test; }
/**
* Action Method
*
* @return
*/
public String getActionMethod() {
this.test = true;
this.name = "Dave";
return null;
}
}
这篇关于发送Ajax请求使用JavaScript JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!