PDA

View Full Version : rich text editor displaying back from database



tool
07-13-2006, 08:29 AM
RICH TEXT EDITOR
http://www.dynamicdrive.com/dynamicindex16/richtexteditor/index.htm


hello i just tried the RTE and it's really a nice script and it works great for me except for one thing:

if i type and format some text and then save it into a longtext field in my database everything works, but when i open again the page with the editor and the text is retrieved from the DB, the html tags are not translated back into bold or anything else.
i see <STRONG> and the other tags.
i know this is how the editor works but shouldn't these tags be translated back when retrieving back saved text? what am i doing wrong?
thanks in advance,
tool

jr_yeo
07-17-2006, 07:25 AM
could u post a link to ur problematic page? :p

tool
07-17-2006, 10:54 AM
actually i cannot give the link because it is inside a reserved area for (that)system administrators.
i can paste the code of the jsp hoping it helps:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ include file="/inc/init.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>

<script language="JavaScript" type="text/javascript" src="richtext_compressed.js"></script>
<script language='JavaScript' src="/gest_ag_ut/JS/agenzie.js"></script>


<title>Note per <c:out value='${requestScope.codice}'/></title>
<meta http-equiv="Expires" content="-1" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />

</head>


<body bgcolor="#E5EDBA">

<table width="100%" align="center">
<tr><td>

<form name="form_editnote" action="/gest_ag_ut/Note" method="POST" onsubmit="return submitForm();">

<script language="JavaScript" type="text/javascript">
function submitForm() {
//make sure hidden and iframe values are in sync before submitting form
//to sync only 1 rte, use updateRTE(rte)
//to sync all rtes, use updateRTEs
updateRTE('note');
//updateRTEs();
//alert("note = " + document.RTEDemo.rte1.value);

//change the following line to true to submit form
return true;
}

//Usage: initRTE(imagesPath, includesPath, cssFile)
initRTE("images/", "", "rte.css");
//
</script>
<input type="hidden" name="richiesta" value="salva">
<input type="hidden" name="codice" value="<c:out value='${requestScope.codice}'/>">

<script language="JavaScript" type="text/javascript">
//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
writeRichText('note', '<c:out value="${requestScope.note}"/>', 400, 450, true, false);
</script>
<input type="submit" name="submit" value="Salva">
</table>
<script language="JavaScript" type="text/javascript">

</script>
</form>

<c:if test="${requestScope.esito=='ERRORE'}">
<c:out value='${requestScope.esito}'/>:&nbsp;<c:out value='${requestScope.errore}'/>
</c:if>

<c:if test="${requestScope.esito=='ok'}">
<script language="JavaScript">
window.close();
</script>
</c:if>

</td></tr>
</table>

</body>
</html>

and in the jsp's directory i put insert_table.htm, palette.htm, blank.htm, rte.css, richtext_compressed.js .

thanks again,
tool

tool
07-18-2006, 07:43 AM
i found the reason.
in the database hello is correctly stored as <STRONG>hello</STRONG> and it's retrieved back in the right way until it is passed to the browser (IE 6),
than the browser (or maybe javascript?!... wait wait, i think it's the JSTL library that do that!) do some urlencode so that < and > become &lt; and gt; .
that is why it is not translated.
how could i prevent that?

thanks!
tool

tool
07-18-2006, 08:05 AM
again i finally did it.
there's a non-required attribute in the <c: out> tag of JSTL which is called escapeXml.
it's default value is true, it is enought to specify it to false and the trick is done!

thanks dudes!

jr_yeo
07-18-2006, 11:33 AM
thanks dudes!

ur welcome, dude :D