I want to use the Key generated for JDO objects in my java google webapp directly as the id attributes in the html document that I present to my users.
The html id string is not case sensitive, must start with [a-zA-Z] and can then contain [A-Za-z0-9-_]. When converting a google app engine Key to a string using KeyFactory.keyToString(key) (Java), it returns “a websafe string. For example, this string can safely be used as an URL parameter embedded in a HTML document.”
Is the websafe format in java string compatible with the html ID attribute format?
And if not, what is the best way to convert between the two string formats? So that I can have two methods similar to:
public static String htmlToGae(String htmlID){ ... }
public static String gaeToHTML(String gaeID){ ... }
if (gaeToHTML(htmlToGae(htmlID)) == htmlID)
return "thank you! :)";
A simple “All swanes are white”-test seems to suggest that the websafe string that KeyFactory returns are compatible with the html id attribute:
for (int ii = 0; ii < 100; ii++)
out.println(KeyFactory.createKeyString("Document", "swan" + ii));
Yes that’s perfectly usable as an HTML id.