|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.paneris.jal.model.HTMLUtil
public final class HTMLUtil
Output format (HTML) dependant formatters.
Constructor Summary | |
---|---|
HTMLUtil()
|
Method Summary | |
---|---|
static java.lang.String |
escape(java.lang.String s,
ExtendedHash h)
|
static java.lang.String |
escapeHTML(java.lang.String htm)
Do basic escaping of html text |
static java.lang.String |
escapeJavascript(java.lang.String s)
|
static java.lang.String |
getDropDown(DDField ddf,
java.lang.String db,
java.lang.String allName)
Return a drop down list (select tag) from a DDField where the options are given by the possible values of that Field. |
static java.lang.String |
getDropDown(DDField ddf,
java.lang.String db,
java.lang.String fieldname,
boolean mandatory,
java.lang.String allValue,
java.lang.String allName)
|
static java.lang.String |
getDropDown(java.sql.ResultSet rs,
java.lang.String name)
|
static java.lang.String |
getDropDown(java.sql.ResultSet rs,
java.lang.String name,
boolean unique)
|
static java.lang.String |
getDropDown(java.sql.ResultSet rs,
java.lang.String name,
boolean unique,
java.lang.String allName)
|
static java.lang.String |
getDropDown(java.sql.ResultSet rs,
java.lang.String name,
boolean unique,
java.lang.String allName,
java.lang.String selectValue)
Return a drop down list (HTML select tag) where the options are the rows of a ResultSet. |
static java.lang.String |
getDropDown(java.sql.ResultSet rs,
java.lang.String name,
boolean unique,
java.lang.String allValue,
java.lang.String allName,
java.lang.String selectValue)
|
static java.lang.String |
getDropDown(java.lang.String db,
java.lang.String sqlString,
java.lang.String name)
Return a drop down list (HTML select tag) where the options are defined by the records returned by an SQL query. |
static java.lang.String |
getDropDown(java.lang.String db,
java.lang.String sqlString,
java.lang.String name,
boolean unique)
|
static java.lang.String |
getDropDown(java.lang.String db,
java.lang.String sqlString,
java.lang.String name,
boolean unique,
java.lang.String allName)
|
static java.lang.String |
getDropDown(java.lang.String db,
java.lang.String sqlString,
java.lang.String name,
boolean unique,
java.lang.String allName,
java.lang.String selectValue)
|
static java.lang.String |
getDropDown(java.lang.String db,
java.lang.String sqlString,
java.lang.String name,
boolean unique,
java.lang.String allName,
java.lang.String allValue,
java.lang.String selectValue)
|
static java.lang.String |
getHiddenValue(DDField ddf,
java.lang.String db,
java.text.SimpleDateFormat dateFormatter,
java.text.SimpleDateFormat datetimeFormatter,
java.lang.String postfix)
Formats a DDField to be displayed on a html page as a hidden field |
static java.lang.String |
getInputValue(DDField ddf,
java.lang.String db,
java.text.SimpleDateFormat dateFormatter,
java.text.SimpleDateFormat datetimeFormatter,
java.lang.String allValue,
java.lang.String postfix)
Formats a DDField to be displayed on a html page as in input box of the correct type |
static java.lang.String |
getJSValidation(DDField ddf,
java.lang.String fieldname,
java.lang.String displayname,
boolean mand)
Returns a JavaScript tag which will validate the field using JS (remember to include the relevant functions to handle the validation request in your template). |
static java.lang.String |
getLinkedSelect(DDField ddf,
java.lang.String db,
java.lang.String allName)
|
static java.lang.String |
getLinkedSelect(DDField ddf,
java.lang.String db,
java.lang.String fieldname,
boolean mandatory,
boolean unique,
java.lang.String allName)
Return a drop down list (select tag) from a DDField where the options are given by the possible values of that Field. |
static java.lang.String |
getLinkedSelect(DDField ddf,
java.lang.String db,
java.lang.String fieldname,
boolean mandatory,
boolean unique,
java.lang.String allValue,
java.lang.String allName)
|
static java.lang.String |
getLinkedSelect(java.sql.ResultSet rs,
java.lang.String name,
boolean unique,
java.lang.String allName,
java.lang.String selectValue)
Return a drop down list (HTML select tag) where the options are the rows of a ResultSet. |
static java.lang.String |
getLinkedSelect(java.sql.ResultSet rs,
java.lang.String name,
boolean unique,
java.lang.String allValue,
java.lang.String allName,
java.lang.String selectValue)
|
static java.lang.String |
getLinkedSelect(java.lang.String db,
java.lang.String sqlString,
java.lang.String name)
|
static java.lang.String |
getLinkedSelect(java.lang.String db,
java.lang.String sqlString,
java.lang.String name,
boolean unique)
|
static java.lang.String |
getLinkedSelect(java.lang.String db,
java.lang.String sqlString,
java.lang.String name,
boolean unique,
java.lang.String allName)
Return a drop down list (HTML select tag) where the options are defined by the records returned by an SQL query. |
static java.lang.String |
getLinkedSelect(java.lang.String db,
java.lang.String sqlString,
java.lang.String name,
boolean unique,
java.lang.String allValue,
java.lang.String allName,
java.lang.String selectValue)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HTMLUtil()
Method Detail |
---|
public static java.lang.String escapeHTML(java.lang.String htm)
htm
- a String to escape
public static java.lang.String escapeJavascript(java.lang.String s)
public static java.lang.String escape(java.lang.String s, ExtendedHash h)
public static java.lang.String getLinkedSelect(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allName, java.lang.String selectValue) throws java.lang.Exception
Each row of the ResultSet should have only one value Each row becomes an HTML option tag
Unique only puts an element into the select box if it's value is not already
Takes a selectvalue so that the correct option can be chosen
You can also add an extra option using allName and allValue
rs
- a list of value pairsname
- the name of the input box to copy tounique
- make sure that each entry has a different valueallValue
- the value of first option on selectallName
- the name of first value on selectselectValue
- the entry to be selected by default
java.lang.Exception
public static java.lang.String getLinkedSelect(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allValue, java.lang.String allName, java.lang.String selectValue) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getLinkedSelect(DDField ddf, java.lang.String db, java.lang.String fieldname, boolean mandatory, boolean unique, java.lang.String allName) throws java.lang.Exception
You can add another option using allName and allValue so long as mandatory is not set
The current value of the DDField is used to decide which option is selected by default
dd
- a DDField which we want to create a select box for
This may be a field in a lookup tabledb
- name of the database to queryfieldname
- the name of the field (and the select tag)
This may be the name of the field containing the lookupmandatory
- if 'false' then a default extra option ("None") is
added, unless allName is setunique
- ensure that each entry has a different valueallValue
- the value of first option on selectallName
- the name of first value on select
java.lang.Exception
public static java.lang.String getLinkedSelect(DDField ddf, java.lang.String db, java.lang.String allName) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getLinkedSelect(DDField ddf, java.lang.String db, java.lang.String fieldname, boolean mandatory, boolean unique, java.lang.String allValue, java.lang.String allName) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getLinkedSelect(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allName) throws java.lang.Exception
Unique only puts an element into the select box if it's value is not already
db
- name of the database to querysqlString
- the SQL query to evaluatename
- the name of the select tagunique
- make sure that each entry has a different valueallValue
- the value of first option on selectallName
- the name of first value on selectselectValue
- the value which should be selected
java.lang.Exception
public static java.lang.String getLinkedSelect(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getLinkedSelect(java.lang.String db, java.lang.String sqlString, java.lang.String name) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getLinkedSelect(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allValue, java.lang.String allName, java.lang.String selectValue) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allName, java.lang.String selectValue) throws java.lang.Exception
It is assumed that each row of the ResultSet has at least 2 fields in it - the first is used as the value of the option, the 2nd is the displayed value. Each row becomes a HTML option tag
Unique only puts an element into the select box if it's value is not already
Takes a selectvalue so that the correct option can be chosen
You can also add an extra option using allName and allValue
rs
- a list of value/display pairsname
- the name of the select tagunique
- make sure that each entry has a different valueallValue
- the value of first option on selectallName
- the name of first value on selectselectValue
- a String indicating the entry to be selected by default
java.lang.Exception
public static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allName) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name, boolean unique) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getDropDown(java.sql.ResultSet rs, java.lang.String name, boolean unique, java.lang.String allValue, java.lang.String allName, java.lang.String selectValue) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name) throws java.lang.Exception
It is assumed that the query returns a ResultSet in which each row has at least 2 fields in it - the first is used as the value of the option, the 2nd is the displayed value. Each row becomes a HTML option tag
Unique only puts an element into the select box if it's value is not already
db
- name of the database to querysqlString
- the SQL query to evaluatename
- the name of the select tagunique
- ensure that each entry has a different valueallValue
- the value of first option on selectallName
- the name of first value on selectselectValue
- The String to be selected by default
java.lang.Exception
public static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allName) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allName, java.lang.String selectValue) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getDropDown(java.lang.String db, java.lang.String sqlString, java.lang.String name, boolean unique, java.lang.String allName, java.lang.String allValue, java.lang.String selectValue) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getDropDown(DDField ddf, java.lang.String db, java.lang.String allName) throws java.lang.Exception
This field should be a field linked (in the datadictionary) to another table. The contents of (each record of) that table are used to create the select box. Also, the field could be a boolean field.
You can add another option using allName and allValue if mandatory is not set
The current value of the DDField is used to decide which option is selected by default
ddf
- a DDField which we want to create a select box for
This is a field in a lookup tabledb
- name of the database to queryfieldname
- the name of the field (and the select tag)
This is the name of the field containing the lookupmandatory
- if 'false' then a default extra option ("None") is
added, unless allName is setallValue
- the value of first option on selectallName
- the name of first value on select
java.lang.Exception
public static java.lang.String getDropDown(DDField ddf, java.lang.String db, java.lang.String fieldname, boolean mandatory, java.lang.String allValue, java.lang.String allName) throws java.lang.Exception
java.lang.Exception
public static java.lang.String getInputValue(DDField ddf, java.lang.String db, java.text.SimpleDateFormat dateFormatter, java.text.SimpleDateFormat datetimeFormatter, java.lang.String allValue, java.lang.String postfix) throws java.lang.Exception
ddf
- a DDField which we want to create an input box fordb
- name of the database to querydateFormatter
- format for datesdateTimeFormatter
- format for date and times
java.lang.Exception
public static java.lang.String getHiddenValue(DDField ddf, java.lang.String db, java.text.SimpleDateFormat dateFormatter, java.text.SimpleDateFormat datetimeFormatter, java.lang.String postfix) throws java.lang.Exception
ddf
- The DDField to create an input box fordb
- name of the database to querydateFormatter
- format for datesdateTimeFormatter
- format for date and times
java.lang.Exception
public static java.lang.String getJSValidation(DDField ddf, java.lang.String fieldname, java.lang.String displayname, boolean mand)
Presently the returned String should look like:
The first 2 arguments are strings which contain the name of the input field and what to call it. These should be the params fieldname and displayname for this function, but remember to wrap quotes around them!
The third argument should be 0 if mand is false, 1 otherwise (actually, javascript treats anything other than 0, "0", false and the null object as true).
The fourth argument is a regular expression which any value entered into the HTML form must match against for validation to succeed. Note that this needs to have quotes wrapped around it. Since this ends up as a JavaScript string, we also need to escape special characters with '\', including '\' itself (hence the '\\w' in the example above - we want the expression to contain the 2 characters '\w', not CTRL-w. If you put brackets into your expression then JavaScript will allow you to access them through the global (to each window) variable RegExp as RegExp.$1 ... RegExp.$9. You can leave this out if you only want to check if a a mandatory value is set or not.
The fifth argument is the body of JavaScript function. You can use this to perform more general validation tests than just matching a regular expression, or you can leave it out altogether. It has access to one formal paramater, 'value' - the value of the input field being validated. It also has access to global variables such as RegExp.$1. It should return nothing (or an empty string) if validation succeeds, otherwise it should return a string to be shown to the user explaining the problem. Remeber to print double quotes around it.
Because we've got to escape all these quotes and escapes in this function, the strings are a bit messy, especially since there are a few '\n's to improve readability in the HTML source. Be careful.
ALTERNATIVELY, you can use some rules which are predefined in the javascript: add_integer("fieldname_1", "Display Name", 0); add_number("fieldname_1", "Display Name", 0); add_date("fieldname_1", "Display Name", 0); add_datetime("fieldname_1", "Display Name", 0);
ddf
- A DDField representing a field in the datadictionaryfieldname
- The name of the input tag to be validateddisplayname
- What to call the input field for the user's benefitmand
- Whether the field is mandatory (cannot be empty)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |