-
1. Re: rich:select custom label in validation message
dan.james Mar 14, 2014 12:25 PM (in response to uwew)Hi Uwe,
I've just found your question from a google search, having encountered a similar problem.
In this case it looks like you could provide a requiredMessage attribute, e.g.:
<rich:select required="true" id="test3" requiredMessage="Simple select: please select a value">
These seem to override the automatic <rich:validator> messages. It's not a very dynamic solution though - you'd have to specify the whole message each time.
My issue is slightly different - I was experimenting with <rich:notifyMessages> to display the errors to the user on the right hand side of the screen. I wasn't planning on specifying individual messages, but to just use those generated by <rich:validator> based on the JPA validation constraints placed on the backing entity bean. However, I've run into the same issue as you that any label specified is not prefixed to the message, so it's not a very user-friendly approach for large forms as the link between field and error is lost.
Did you find any other way of getting round this?
Cheers,
Dan
-
2. Re: rich:select custom label in validation message
croco Mar 17, 2014 7:17 AM (in response to uwew)If you use BeanValidation you can add ValidationMessages.properties with your custom messages.
-
3. Re: rich:select custom label in validation message
michpetrov Mar 17, 2014 11:01 AM (in response to uwew)<h:outputLabel for="text" value="Some label" /><h:inputText id="text" /> <h:inputText id="text" label="Some label" />
These two rows don't do the same thing, the first one will just create a piece of text on your page. The second one will create a label that can be used in validation messages.
<rich:select> doesn't have a label attribute, though as pointed out you can use the requiredMessage attribute.
-
4. Re: rich:select custom label in validation message
dan.james Mar 17, 2014 11:45 AM (in response to croco)Thanks Matija,
I will be using BeanValidation, but the OP was using one of the built-in validation options in RF. (I'm new to this, so this SO answer helped clarify the difference for me).
I've looked into the ValidationMessages.properties option further, but I'm considering having the customised message defined explicitly with the constraint. E.g.:
In MyBean.java:
@Size(min=3,max=50,message="MyBean name should be between {min} and {max} characters long")
@NotNull
@Column(unique=true)
private String name;
Note that in this particular case using @Size instead of @Length is more portable, but I wanted the message to be more user-friendly so I have overridden the whole thing.
An alternative approach to prefix a custom 'label' to the standard output would be:
@Size(min=3,max=50,message="Name: {javax.validation.constraints.Size.message}")
Resulting message would be: "Name: size must be between 3 and 50" based on the default ValidationMessages.properties values.
I don't think either of these is perfect though..
Apologies for the hijack uwew. It looks like Michal Petrov has explained why the label attribute does not work for this component type. Additionally, you may find this link has a usable method for removing client IDs from standard JSF validation messages. In any case, it's been more than a month, so you've undoubtedly found your own way around this...
Cheers,
Dan
-
5. Re: rich:select custom label in validation message
croco Apr 2, 2014 12:41 PM (in response to dan.james)I would override javax.validation.constraints.Size.message for example with your desired message instead of defining it directly into message property of @Size. This way you won't lose internationalization. This is working for me.