使用 Stripes、Javascript 和 Ajax
这是我的 jsp 页面(这是另一个 jsp 页面的模式页面),其中包含一个表、一个表单、一个 javascript 和 ajax 。
<%@ include file="/WEB-INF/includes/taglibs.jsp" %>
<script type="text/javascript"
src="${pageContext.request.contextPath}/ajax/prototype.js"></script>
<script type="text/javascript" xml:space="preserve">
function invoke(form, event, container) {
var params = Form.serialize(form, {submit:event});
new Ajax.Updater(container, form.action, {method:'post', parameters:params});
}
</script>
<display:table name="actionBean.currentAidApplicantYear.comments" id="result" class="maui">
<display:column property="lastUpdatedBy" title="Last Updated By" sortable="true"/>
<display:column property="lastUpdatedTimestamp" title="Last Updated Date"
format="{0,date,MM/dd/yyyy HH:mm}" sortable="true"/>
<display:column property="comment" title="Memo"/>
</display:table>
<div class="actionBar" style="margin-top: 20px; text-align: center;">
<stripes:form beanclass="${actionBean.class}" id="addMemoForm" method="POST">
<tags:labelAndValue label="Comment" name="comment" >
<stripes:textarea id="commentTextArea" name="comment.comment" cols="75"/>
</tags:labelAndValue>
<stripes:submit name="saveCommentAjax" value="Add Memo"
onclick="invoke(this.form, this.name, 'result');"/>
<stripes:hidden name="id" />
</stripes:form>
</div>
这是动作 bean 的一部分,它扩展了另一个类,该类又实现了 ActionBean、ValidationErrorHandler
Public class CommentsTab extends AbstractAidApplicantTab {
private AidApplicantYearComment comment;
public AidApplicantYearComment getComment() {
return comment;
}
public void setComment(AidApplicantYearComment comment) {
this.comment = comment;
}
public Resolution saveCommentAjax(){
String result = String.valueOf(comment.getComment());
comment.save();//build up the comment object
//by this time the comment object will save the string comment, user who updates it and a //time stamp. Those are the three variables that are displayed on the jsp table.
return new StreamingResolution("text/html",new StringReader(result));}
//here instead of returning just a string “result” I prefer to return a comment object or //the three values I wanted to display on a table. How can I do that?
当单击提交按钮时,我使用 ajax 调用动作 bean 的方法来执行一些操作,并且该函数返回流解析( StreamingResolution("text/html",new StringReader(result));)。收到响应后,我想刷新表格而不刷新页面。但是,为了做到这一点,我必须从响应中获取一个对象(注释对象),而不是文本(或者可能是可能包含对象值的字符串数组)
任何帮助将不胜感激。谢谢
This is my jsp page (which is a modal page to another jsp page ) which contains a table, a form, a javascript and ajax .
<%@ include file="/WEB-INF/includes/taglibs.jsp" %>
<script type="text/javascript"
src="${pageContext.request.contextPath}/ajax/prototype.js"></script>
<script type="text/javascript" xml:space="preserve">
function invoke(form, event, container) {
var params = Form.serialize(form, {submit:event});
new Ajax.Updater(container, form.action, {method:'post', parameters:params});
}
</script>
<display:table name="actionBean.currentAidApplicantYear.comments" id="result" class="maui">
<display:column property="lastUpdatedBy" title="Last Updated By" sortable="true"/>
<display:column property="lastUpdatedTimestamp" title="Last Updated Date"
format="{0,date,MM/dd/yyyy HH:mm}" sortable="true"/>
<display:column property="comment" title="Memo"/>
</display:table>
<div class="actionBar" style="margin-top: 20px; text-align: center;">
<stripes:form beanclass="${actionBean.class}" id="addMemoForm" method="POST">
<tags:labelAndValue label="Comment" name="comment" >
<stripes:textarea id="commentTextArea" name="comment.comment" cols="75"/>
</tags:labelAndValue>
<stripes:submit name="saveCommentAjax" value="Add Memo"
onclick="invoke(this.form, this.name, 'result');"/>
<stripes:hidden name="id" />
</stripes:form>
</div>
And this is part of the action bean which extends another class which in turn implements ActionBean, ValidationErrorHandler
Public class CommentsTab extends AbstractAidApplicantTab {
private AidApplicantYearComment comment;
public AidApplicantYearComment getComment() {
return comment;
}
public void setComment(AidApplicantYearComment comment) {
this.comment = comment;
}
public Resolution saveCommentAjax(){
String result = String.valueOf(comment.getComment());
comment.save();//build up the comment object
//by this time the comment object will save the string comment, user who updates it and a //time stamp. Those are the three variables that are displayed on the jsp table.
return new StreamingResolution("text/html",new StringReader(result));}
//here instead of returning just a string “result” I prefer to return a comment object or //the three values I wanted to display on a table. How can I do that?
When the submit button is clicked I use an ajax to call an action bean’s method to do some operation and the function returns a streaming resolution (StreamingResolution("text/html",new StringReader(result));). Once I get the response I wanted to refresh the table without refreshing the page. However, in order to do that I have to get an object (a comment object) from the response not a text (or may be an array of Strings which might contain the values of the object)
Any help would be appreciated. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
JavaScriptResolution
< /a>,或者(更好的恕我直言),Use a
JavaScriptResolution
, or (better IMHO),