How can I style invalid text field content in Spring MVC (JSP) - spring-mvc

The Spring MVC JSP tag library has a tag for rendering form errors. This makes it easy to render an error message next to, say, an input text field. However, it is common practice on many websites to also style the input text field itself (with a red border maybe) to highlight a validation error.
Is there any way of doing this with the Spring JSP tags or will I have to bake my own solution?

I have never used Spring MVC JSP tags but looking at the documentation it looks like cssErrorClass is the way to go:
<form:input path="userName" cssErrorClass="error"/>
Equivalent to "class" - HTML Optional Attribute. Used when the bound field has errors.
Obviously you can now define input.error class in your CSS stylesheet.

You can use spring:bind tag around the form:input tag. In between the spring:bind tag you can use something like ${status.error ? 'error' : ''} for your style class.
status.error will be true if errors. form input field is available

Related

How do I solve my layouts being messed up due to fields_with_error in RoR app?

I'm using Fomantic(Semantic) UI in my Ruby on Rails, and I realize my forms get messed up when validations fail because of the fields_with_errors class that's automatically added. Is there a known fix for this?
Prior to submission, my form looks like this
After a failed submission, where nothing is entered in any of the field, it looks like this
In one of my projects I use the following code inside config/application.rb
config.action_view.field_error_proc = Proc.new do |html_tag, instance|
%Q(<div class="field error">#{html_tag}</div>).html_safe
end
This code uses semantic way of indication of fields in error state. You can further customise this setting to your needs, see rails docs for details.
Next important point is an extra check on your form tag to add semantic ui form error class, something like:
form_for(#model, html: {class: #model.errors.any? ? 'ui form error' : 'ui form'}) do |f|
This will show error messages if you use them.

How to allow goog.html.sanitizer.HtmlSanitizer.Builder to permit the "placeholder" attribute

I use goog.html.sanitizer.HtmlSanitizer.Builder to create safe HTML that I then dynamically insert into a dialog. I wanted to have an input field that uses the Html 5 "placeholder" attribute.
I tried
.alsoAllowTagsPrivateDoNotAccessOrElse ([ "placeholder"])
and got an expected nasty compiler error!
I ended up adding the place holder attribute to the closure-library attribute white list javascript code. The call to alsoAllowTagsPrivateDoNotAccessOrElse was removed and all worked well.

Which Seam component to use: <h:outputLink> or <h:commandLink>?

I'm very new to Seam and am just getting used to the different components available. I'm wondering which one I should use for this situation.
The answer to this question explains the difference between <h:outputLink> and <h:commandLink>, that <h:outputLink> produces just a basic HTML link tag with GET request and <h:commandLink> submits a POST via a click event.
I just want to attach a simple jQuery click event to a link. I don't want the link to redirect to anywhere or submit a form. I basically want the equivalent of href="#" (I understand that commandLink generates href="#" but it seems heavy-handed for a simple link with no form submission). But <h:outputLink> implicitly adds an href value unless I put value="#" (which seems hacky).
What component do I want to use here? I seem to be missing some very basic element.
(First: <h:outputLink> and <h:commandLink> are standard JSF components, not part of the Seam framework.) In this case, you can just use the standard HTML tag <a>, because you appear not to be using anything special to JSF.

Spring Framework.... wat is difference between form:errors path and form:lable path...?

i AM NEW TO Spring Framework . Can any body explain me difference between form:label path and form:errors path and Spring:message
I am confuse ......
form:label renders an html label element
form:errors render an span element showing an error message after validating a form
spring:message is the element used to show internationalized messages

How to show a bold message with Seam 2 StatusMessages?

I have a seam component where I put a message using standard seam annotation:
#In
private StatusMessages statusMessages;
public void myMethod()
{
statusMessages.add("Welcome, #{user.getName()}, after confirmation you will be able to log in.");
}
and than in the xthml page to show this message:
<h:messages id="mensagensHome" globalOnly="true" styleClass="message"
errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"
rendered="#{showGlobalMessages != 'false'}" />
This is working perfectly, but I have a requirement where the name should be Bold. Than I have already tryed placing standard html tags in my message like:
statusMessages.add("Welcome, <b> #{user.getName()} </b>, after confirmation you will be able to log in.");
But than it shows the tags on the page and does not turn the name bold.
I have also tried using unicode escape character to render the html tags, but again no success.
Is it possible to use standard html tags from code looking forward to format messages in Seam?
Tx in advance.
Actually you can't, unlike h:outputText h:messages don't have an escape property where you would be able to do escape="false".
In the link bellow you can find a sample on how to extend h:messages, actually it's not exactly h:messages that is extended but the end result is the same. So you can set escape="false" in h:messages and have the browser parse html tags.
http://balusc.blogspot.com/2010/07/using-html-in-jsf-messages.html
Be careful if you display something that the user inserted because this is is prone to html injection.
Note: The link is not mine, but it did work for me.

Resources