Это моя страница 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-компонента action, которыйрасширяет другой класс, который, в свою очередь, реализует 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 для вызова метода компонента действия для выполнения какой-либо операции, а функция возвращает разрешение потоковой передачи (StreamingResolution ("text / html", новый StringReader (результат));) .Получив ответ, я захотел обновить таблицу, не обновляя страницу.Однако для этого мне нужно получить объект ( объект комментария) из ответа, а не текста (или может быть массивом строк, которые могут содержать значения объекта)
Любая помощь будет оценена.Спасибо