前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >dwr a ajax 提交,ajax – Does Java offer a timestamp??…..DWR – Stack Overflow

dwr a ajax 提交,ajax – Does Java offer a timestamp??…..DWR – Stack Overflow

作者头像
全栈程序员站长
发布2022-06-28 12:38:33
4040
发布2022-06-28 12:38:33
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

Im using DWR, which im fairly new to…I using ajax to submit a comment to the page and I got request to see If i can show a tmestamp when the comment is submitted:

In a nutshell—The bean has a variable called auditable…which doesnt get populated with a timestamp until it hits the database. Thats fine. My question…can I pass something to auditable on the fly with ajax that is a sort of “timestamp” to pass back to the page????

Thanx in advance!!!!

heres the code:

JSP

You have ${const[‘COMMENT_MAX_LENGTH’] – fn:length(commentForm.comment)} characters left.

οnkeypress=”characterCounter(‘commentsCounter’,${const[‘COMMENT_MAX_LENGTH’]}, this)”

οnkeydοwn=”characterCounter(‘commentsCounter’,${const[‘COMMENT_MAX_LENGTH’]}, this)”

οnkeyup=”characterCounter(‘commentsCounter’,${const[‘COMMENT_MAX_LENGTH’]}, this)”>

DWR JAVASCRIPT:

function addComment()

{

$(“#commentErrors”).css(“visibility”, “hidden”);

var obj = {comment:null};

WhatIfDataAction.addComment(dwr.util.getValues(obj),

{

callback:addCommentCallback,

timeout:60000,

exceptionHandler:function(msg, e)

{

alert(“Error submitting form. ” + msg);

}

}

);

}

function addCommentCallback( comment )

{

if (comment.messages.length > 0)

{

//Convert the error messages into an HTML string.

var html = “”;

for (var i = 0; i < comment.messages.length; i++)

{

html += “

” + comment.messages[i] + “”;

}

$(“#commentErrors”).html(html);

$(“#commentErrors”).css(“visibility”, “visible”);

}

else

{

// Build HTML for new row.

var html = “

” + comment.comment + “” +

” + comment.id + “” +

“; // three empty TDs for the three actuals fields

$(“#commentRow”).before(html);

WHATIFDATAACTION.JAVA:

public CommentForm addComment(Map properties) throws Exception

{

CommentForm form = new CommentForm(properties);

if (form.validate(this))

{

CommentBean bean = form.toBean();

EntryBean entry = WhatifCache.fetchEntryFromCache(getSession());

entry.addComment(bean);

form.setId(bean.getId());

bean = form.toBean();

}

return form;

}

And finally…commentBean:

public final class CommentBean

extends AbstractBean

implements Auditable,

BeanCache.CacheableBean

{

private long id;

private long entryId;

private String comment;

private AuditableBean auditable;

/** Description character max length, matches size of description field in db **/

public static final Integer COMMENT_MAX_LENGTH = 250;

public CommentBean()

{

}

@Override

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException

{

id = in.readLong();

entryId = in.readLong();

comment = in.readUTF();

auditable = (AuditableBean)in.readObject();

}

@Override

public void writeExternal(ObjectOutput out) throws IOException

{

out.writeLong(id);

out.writeLong(entryId);

out.writeUTF((comment == null) ? “” : comment);

out.writeObject( auditable );

}

@Override

public void readSQL(SQLInput in, String typeName) throws SQLException

{

id = in.readLong();

entryId = in.readLong();

comment = in.readString();

auditable = (AuditableBean)in.readObject();

}

@Override

public void writeSQL(SQLOutput out) throws SQLException

{

out.writeLong(id);

out.writeLong(entryId);

out.writeString(comment);

out.writeObject( auditable );

}

public long getId()

{

return id;

}

public void setId(long id)

{

this.id = id;

}

public long getEntryId()

{

return entryId;

}

public void setEntryId(long entryId)

{

this.entryId = entryId;

}

public String getComment()

{

return comment;

}

public void setComment(String comment)

{

this.comment = comment;

}

public AuditableBean getAuditable()

{

return auditable;

}

public void setAuditable(AuditableBean bean)

{

auditable = bean;

}

public boolean isActive()

{

return true;

}

public String getKey()

{

return “”+id;

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/150671.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档