首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Stripes、Javascript和Ajax

使用Stripes、Javascript和Ajax
EN

Stack Overflow用户
提问于 2012-02-17 15:29:16
回答 1查看 3.2K关注 0票数 0

这是我的jsp页面(它是另一个jsp页面的模式页),它包含一个表、一个表单、一个javascript和ajax。

代码语言:javascript
复制
<%@ 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。

代码语言:javascript
复制
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?

当单击submit按钮时,我使用ajax调用action bean的方法来执行一些操作,并且函数返回流分辨率(StreamingResolution("text/html",,新的StringReader(结果);)。得到响应后,我想刷新表而不刷新页面。但是,为了做到这一点,我必须从响应中获取一个对象(,一个注释对象),而不是文本(或者可能是一个字符串数组,其中可能包含对象的值)。

任何帮助都将不胜感激。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-17 15:41:49

使用JavaScriptResolution或(更好的IMHO),

StreamingResolution

  • use

  • 将您的评论对象转换为JSON字符串(使用大量可用的免费JSON编码器),

  • 将该JSON字符串作为浏览器中的原生JSON函数(如果您针对最近的浏览器)或包含JSON解析函数的JS库返回,以将JSON字符串转换为JavaScript对象。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9330970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档