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

dwr a ajax 提交,ajax – Does Java offer a timestamp??…..DWR – Stack OverflowImusingDWR,whichimfairlynewto…IusingajaxtosubmitacommenttothepageandIgotrequesttoseeIficanshowatmestampwhenthecommentissubmitted:Inanutshell—Thebeanhasavaria…

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

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)”>

Add

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.net/150671.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • DropDownList的常用属性和事件「建议收藏」

    DropDownList的常用属性和事件「建议收藏」SelectedItem属性设置或获取下拉菜单的选中项,该属性的类型为System.Web.UI.WebControls.ListItem.所有列表控件(ListControl)中的项都是该类型,它

    2022年7月2日
    28
  • mysql opkg源_opkg包管理工具常用命令[通俗易懂]

    mysql opkg源_opkg包管理工具常用命令[通俗易懂]Opkg是一个轻量快速的套件管理系统,目前已成为Opensource界嵌入式系统标准。常用于路由、交换机等嵌入式设备中,用来管理软件包的安装升级与下载。常用命令opkgupdate更新可以获取的软件包列表opkgupgrade对已经安装的软件包升级opkglist获取软件列表opkginstall安装指定的软件包opkgremove卸载已经安装的指定的软件包安装要安装软件…

    2022年6月8日
    33
  • 网上英语学习资源大整理

    网上英语学习资源大整理 翻译http://www.bilinguist.com/汉英论坛,高手云集[url]http://www.chinatranslate.net/[/url]中国翻译网,号称全国最大的翻译专业网站[url]http://gb.transea.com/[/url]机器即时翻译,适合整体翻译网站及段落,但不够准确。适合一般人[url]http://www.si-chi…

    2025年7月24日
    3
  • 根据bak还原数据库,备份集中的数据库与现有数据库“XXX”数据库不同

    根据bak还原数据库,备份集中的数据库与现有数据库“XXX”数据库不同在做数据库相关的日常工作中,还原与备份数据库会经常遇到,有时候同样的sql2008备份的数据库,从别人那边备份的数据库文件,在自己的电脑上还原会出现:的错误。解决方法有两种:第一种:右键数据库点击还原数据库,填上需要还原的数据库名,就可以直接还原了。第二种:在新建的数据库上还原数据库时,选好备份文件后,勾选上覆盖现有数据库即可。原文地址:https://blog.csdn.net/sushena/…

    2022年5月10日
    42
  • 系列(jupyter自动保存失败)

    JetBrains系列(IDEA、DataGrip、PyCharm)–快速离线安装插件:解决在线安装失败的问题(以Translation为案例)

    2022年4月14日
    69
  • vue的安装和使用_路由器怎么安装图解

    vue的安装和使用_路由器怎么安装图解前言Vue(读音/vjuː/,类似于view)是一套用于构建前后端分离的框架。刚开始是由国内优秀选手尤雨溪开发出来的,目前是全球“最”流行的前端框架。使用vue开发网页很简单,并且技术生态环境完善

    2022年8月7日
    8

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号