This content has been marked as final.
Show 3 replies
-
1. Re: Validation messages HTML formatted, best practice?
yasudevil Aug 5, 2009 1:51 AM (in response to sl0005)I don't understand really well your question.
What do you mean by HTML Support? You mean change font colors and etc?
-
2. Re: Validation messages HTML formatted, best practice?
sl0005 Aug 5, 2009 8:42 AM (in response to sl0005)I mean do not escape HTML output (like in h:outputText there is an attribute escape).
I want for example to highlight the wrong letters in user input with red background, like this (wrong letters are
b
ande
) :Some letteres are wrong in "a<span class="wrongLetter">b</span>cd<span class="wrongLetter">e</span>"
<style> ..... .wrongLetter{ background-color : #FF3100; } ...... </style>
-
3. Re: Validation messages HTML formatted, best practice?
sl0005 Aug 5, 2009 9:03 AM (in response to sl0005)I could not find the way for using standard h:message in my case, so I solved it another way, by using h:outputText instead.
1) HashMap for custom validation messages :
@SuppressWarnings("serial") @Scope(ScopeType.SESSION) @Name("msgFactory") public class WebMsg extends HashMap<String, String>{ @Factory(value = "webmsg", autoCreate = true, scope = ScopeType.SESSION) public WebMsg getMessages() { return new WebMsg(); } @Override public String get(Object key){ String rez=super.get(key); if(rez!=null)remove(key); return rez; } }
2) Put validation messages in webmsg instead of FacesMessages.instance().addToControl :
//FacesMessages.instance().addToControl("email", "message"); webmsg.put("email", "message");
3) Use h:outputText instead of h:message
<h:outputLabel for="email" value="Email" /> <h:inputText id="email" value="#{user.email}"/> <h:outputText value="#{webmsg['email']}" escape="false"/>