Disable Enter to submit a form
Add the script
onKeyPress="return event.keyCode!=13"
in the BODY of the HTML document for all the web page,
OR
1. Disable in the form the submit.
<nested:form action="docMgmt" onsubmit="return false;" styleId="my_form"/>
2. Creta a function that submit a from in your js script.
function submitFrm(objId){
var theform = document.getElementById(objId);
theform.submit();
return true;
}
3. call the above function from the submit button...
<nested:submit onclick="submitFrm('my_form');">Submit!!</nested:submit>
See the original view:
http://kreotekdev.wordpress.com/2007/11/16/disabling-the-enter-key-on-forms-using-javascript/
onKeyPress="return event.keyCode!=13"
in the BODY of the HTML document for all the web page,
OR
1. Disable in the form the submit.
<nested:form action="docMgmt" onsubmit="return false;" styleId="my_form"/>
2. Creta a function that submit a from in your js script.
function submitFrm(objId){
var theform = document.getElementById(objId);
theform.submit();
return true;
}
3. call the above function from the submit button...
<nested:submit onclick="submitFrm('my_form');">Submit!!</nested:submit>
See the original view:
http://kreotekdev.wordpress.com/2007/11/16/disabling-the-enter-key-on-forms-using-javascript/
AJAX AutoSuggest with Parameters in Greeks
Usage of the following control:
http://www.brandspankingnew.net/archive/2006/08/ajax_auto-suggest_auto-complete.html
Some changes in Javascript bsn.AutoSuggest_2.1.3_comp.js in order to support Greek language.
Replace twice the
encodeURIComponent(this.sInp)
with
encodeURI(encodeURI(this.sInp))
Read the greek parameters using in a java bean the following code:
try {
request.setCharacterEncoding("UTF-8");
nm = request.getParameter("nm");
nm = java.net.URLDecoder.decode (nm, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
http://www.brandspankingnew.net/archive/2006/08/ajax_auto-suggest_auto-complete.html
Some changes in Javascript bsn.AutoSuggest_2.1.3_comp.js in order to support Greek language.
Replace twice the
encodeURIComponent(this.sInp)
with
encodeURI(encodeURI(this.sInp))
Read the greek parameters using in a java bean the following code:
try {
request.setCharacterEncoding("UTF-8");
nm = request.getParameter("nm");
nm = java.net.URLDecoder.decode (nm, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Struts 1.x + Ajax + Greek Language (UTF-8)
In order to support UTF-8 (greek characters) in the parameters of a URI with AJAX, you have to do the following steps:
1. In the AJAX .js file, the function that requests data from the server...
function getDataFrom(str){
str = trim(str);
if ( str.length==0 ) {
document.getElementById(your_id).value = "";
return;
}
// 1. Create the XmlHttp Object
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert ("Your browser does not support AJAX!");
return;
}
var url="your_struts_url_action.do?do=a&nm=" + str;
// SOS - Call twice the encoding function...
url = encodeURI (url);
url = encodeURI (url);
// 2. Event handler when readystate changes....
xmlHttp.onreadystatechange=your_function;
// 3. Request info from the db
xmlHttp.open("GET",url,true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
xmlHttp.send(null);
}
Step 2: In the Action that you call from the AJAX function above, read the parameter and decode it:
try {
request.setCharacterEncoding("UTF-8");
name = request.getParameter("nm");
name = java.net.URLDecoder.decode ( sYphresia, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
1. In the AJAX .js file, the function that requests data from the server...
function getDataFrom(str){
str = trim(str);
if ( str.length==0 ) {
document.getElementById(your_id).value = "";
return;
}
// 1. Create the XmlHttp Object
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert ("Your browser does not support AJAX!");
return;
}
var url="your_struts_url_action.do?do=a&nm=" + str;
// SOS - Call twice the encoding function...
url = encodeURI (url);
url = encodeURI (url);
// 2. Event handler when readystate changes....
xmlHttp.onreadystatechange=your_function;
// 3. Request info from the db
xmlHttp.open("GET",url,true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
xmlHttp.send(null);
}
Step 2: In the Action that you call from the AJAX function above, read the parameter and decode it:
try {
request.setCharacterEncoding("UTF-8");
name = request.getParameter("nm");
name = java.net.URLDecoder.decode ( sYphresia, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mySQL - UTF-8 for JSP and Tomcat
How to display UTF-8 characters in Tomcat using MySQL as the data source!
1. Make sure your MySQL database is using the UTF-8 character set.
2.Tell the JDBC connector that it has to talk to the database using UTF-8.
To do this add useUnicode=true&characterEncoding=UTF-8 to the connection URL in the JDBC configuration. Your connection URL will look something like this: jdbc:mysql://localhost:3306/mydatabase?useUnicode=true&characterEncoding=UTF-8.
3. Make sure the browser knows that what it's receiving is actually UTF-8.
In your JSP files add <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>at the top.
In your Servlets, make sure the right HTTP headers are sent back to the client by adding the line response.setContentType("text/html;charset=UTF-8");.
Of course, you'll have to use another MIME type than text/html if you're not going to display HTML.
4. Tell Java that you're using UTF-8 by configuring the Java options.
Add the parameter -Dfile.encoding=UTF-8 to your Java options, either in the catalina.bat file or by clicking on the Java tab in the Monitor Tomcat program.
5. if you're using Struts to handle web forms - is to make sure all input from the client is converted to UTF-8.
This is done with a little bit of coding and a configuration change
http://www.vegard.net/archives/bg000815.php
1. Make sure your MySQL database is using the UTF-8 character set.
2.Tell the JDBC connector that it has to talk to the database using UTF-8.
To do this add useUnicode=true&characterEncoding=UTF-8 to the connection URL in the JDBC configuration. Your connection URL will look something like this: jdbc:mysql://localhost:3306/mydatabase?useUnicode=true&characterEncoding=UTF-8.
3. Make sure the browser knows that what it's receiving is actually UTF-8.
In your JSP files add <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>at the top.
In your Servlets, make sure the right HTTP headers are sent back to the client by adding the line response.setContentType("text/html;charset=UTF-8");.
Of course, you'll have to use another MIME type than text/html if you're not going to display HTML.
4. Tell Java that you're using UTF-8 by configuring the Java options.
Add the parameter -Dfile.encoding=UTF-8 to your Java options, either in the catalina.bat file or by clicking on the Java tab in the Monitor Tomcat program.
5. if you're using Struts to handle web forms - is to make sure all input from the client is converted to UTF-8.
This is done with a little bit of coding and a configuration change
http://www.vegard.net/archives/bg000815.php
Format dates and numbers
public String FD(String strDate){
// Converts a date from 1900-01-01 to 01-01-1900 and vice versa ....
if ( strDate != null ) {
String newDate[];
String strNewDate = "";
int indx =0;
newDate = strDate.split("-",3);
for (indx = 2; indx >=0; indx-- )
strNewDate = strNewDate + newDate[indx] + "-";
return(strNewDate.substring(0, strNewDate.length() - 1));
}
else
return ("");
}
public String FC(String strMoney){
// Converts a string from 00000000,00 to 00.000.000.000,00
if ( strMoney != null ) {
BigDecimal amount = new BigDecimal(strMoney);
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
String res = nf.format(amount);
return( res );
}
else
return ("");
}
// Converts a date from 1900-01-01 to 01-01-1900 and vice versa ....
if ( strDate != null ) {
String newDate[];
String strNewDate = "";
int indx =0;
newDate = strDate.split("-",3);
for (indx = 2; indx >=0; indx-- )
strNewDate = strNewDate + newDate[indx] + "-";
return(strNewDate.substring(0, strNewDate.length() - 1));
}
else
return ("");
}
public String FC(String strMoney){
// Converts a string from 00000000,00 to 00.000.000.000,00
if ( strMoney != null ) {
BigDecimal amount = new BigDecimal(strMoney);
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
String res = nf.format(amount);
return( res );
}
else
return ("");
}
Subscribe to:
Posts (Atom)