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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • interrupt interrupted_interrupt的用法

    interrupt interrupted_interrupt的用法(一).关于interrupt()    interrupt()并不直接中断线程,而是设定一个中断标识,然后由程序进行中断检查,确定是否中断。    1.sleep()&interrupt()    线程A正在使用sleep()暂停着:Thread.sleep(100000);    如果要取消他的等待状态,可以在正在执行的线程里(比如这里是B)调用a.interr

    2025年7月16日
    0
  • PHP开发APP接口实现–基本篇

    PHP开发APP接口实现–基本篇

    2021年11月7日
    50
  • STM32延时函数的四种方法

    STM32延时函数的四种方法目录1、普通延时2、定时器中断3、查询定时器4、汇编指令单片机编程过程中经常用到延时函数,最常用的莫过于微秒级延时delay_us()和毫秒级delay_ms()。本文基于STM32F207介绍4种不同方式实现的延时函数。1、普通延时这种延时方式应该是大家在51单片机时候,接触最早的延时函数。这个比较简单,让单片机做一些无关紧要的工作来打发时间,经常用循环来实现,在某些编译器下,代码会被优化,导致精度较低,用于一般的延时,对精度不敏感的应用场景中。//微秒级的延时void

    2022年5月5日
    54
  • linux怎么编写shell脚本_简单的shell脚本代码

    linux怎么编写shell脚本_简单的shell脚本代码用springboot框架做的项目,将第三方包全部打在jar里面,通过shell脚本启动和停止服务,常用的shell脚本模板如下:#!/bin/bashJAVA_OPTIONS_INITIAL=-Xms128MJAVA_OPTIONS_MAX=-Xmx512M_JAR_KEYWORDS=monitor-alarm-task-1.0-SNAPSHOT.jarAPP_NAME=monitor-al…

    2022年10月4日
    0
  • zoj1456[通俗易懂]

    zoj1456[通俗易懂]zoj1456

    2022年7月14日
    14
  • html滚动字幕制作教程,dreamweaver教程:怎么制作网页滚动字幕[通俗易懂]

    html滚动字幕制作教程,dreamweaver教程:怎么制作网页滚动字幕[通俗易懂]滚动字幕在FrontPage的组件里有,但是FrontPage这个软件只能支持单行文字,一出现多行文字它就无能为力了,而且它只能支持一行滚动!(如果出现只能滚动一行的情况,解决办法是把这段代码嵌入到JavaScript的document.write里面,请看下面例的详细说明)Dreamweaver也只能用编写HTML代码的方法。所以强烈建议用记事本打开网页源代码来编辑。1.建立第一个滚动字幕。代码…

    2022年6月9日
    35

发表回复

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

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