Hi All,
need a urgent help on Ajax.
I am using Ajax,Spring,
Struts for my project.
I need help in two place :--
1. I am displaying a link which contains first 20 character of a comment and this first 20 character will end with "...." to show that this link contains more information.
After clicking on that link user can view full comment.
I want to append "...." after that 20 character using Ajax display tag.
2.I have an add comment page which will add some comment to database after clicking a save button. Maximum comment size will be 4000 character . But If I enter more then 2000 character then my form is not submiting and it is not showing any error.It simply dies there no action is performed there.
Please help in solving this problem.
Below is the code of my addComment.jsp.
<%@ include file="/common/taglibs.jsp"%>
<script language="javascript" type="text/javascript">
focusOnTextArea=function(){
document.getElementById('commentDesc').focus();
}
// --------------------------------------------------------------
// Save functions
// --------------------------------------------------------------
validateSave = function()
{
var valid = true;
var module = $F('module');
var commentDesc= $F('commentDesc');
if (module == "0")
{
alert("Please Select module.");
valid = false;
return valid;
}else {
focusOnTextArea();
}
if (commentDesc == "")
{
alert("Please Enter Comment.");
document.getElementById('commentDesc').focus();
return false;
}
if(commentDesc.length >= 4000){
alert("Comment should be less than 4000 characters.");
document.getElementById('commentDesc').focus();
valid = false;
}
return valid;
};
preSave = function()
{
var keepGoing = validateSave();
alert("Return Value===" +keepGoing);
if (keepGoing)
{
var method = $('method');
method.value='save';
var params = $('ajax');
params.value = Form.serialize('commentForm');
}
return keepGoing;
};
postSave = function()
{
var params = $('ajax');
params.value="";
};
errorSave = function()
{
alert("error");
};
// --------------------------------------------------------------
// Reset functions
// --------------------------------------------------------------
preReset = function()
{
var method = $('method');
method.value='reset';
};
postReset = function()
{
};
errorReset = function()
{
};
</script>
<div id="ajaxCommentForm">
<table class="componentContent">
<html:form styleId="commentForm" method="POST" action="/addCommentAction">
<html:hidden styleId="method" property="method"/>
<input id="ajax" type="hidden" value=""/>
<c:if test='${not empty commentForm.message}'>
<script>setTimeout("Effect.DropOut('savedMsg')", 2500);</script>
<div id="savedMsg" class="successMsg">${commentForm.message}</div>
</c:if>
<tr>
<td class="label">Module:</td>
<td>
<html:select styleId="module" name="commentForm" property="moduleId" onchange="focusOnTextArea()">
<html
ption value="0">--Please Select--</html
ption>
<c:forEach var="module" items="${dataList}">
<html
ption value="${module.moduleId}">
<c
ut value="${module.moduleName}"/>
</html
ption>
</c:forEach>
</html:select>
</td>
</tr>
<tr>
<td class="label" valign="top">Comment:</td>
<td colspan="3">
<html:textarea property="commentDesc" rows="6" cols="50" />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<table class="componentContent">
<tr>
<td align="right"><input id="saveButton" type="button" value="Save" class="button"/></td>
<td align="left"><input id="resetButton" type="button" value="Reset" class="button"/></td>
</tr>
</table>
</td>
</tr>
</html:form>
</table>
</div>
<ajax:htmlContent
baseUrl="addCommentAction.do"
source="resetButton"
target="ajaxCommentForm"
parameters="method={method}"
preFunction="preReset"
postFunction="postReset"
errorFunction="errorReset"/>
<ajax:htmlContent
baseUrl="addCommentAction.do"
source="saveButton"
target="ajaxCommentForm"
parameters="form={ajax},method={method},commentDesc={commentDesc}"
preFunction="preSave"
postFunction="postSave"
errorFunction="errorSave"/>