I have an Item entity associated with many Tag entities.
The page for adding new Items has the following snippet:
<s:decorate id="tagsField" template="layout/edit.xhtml">
<ui:define name="label">Tags</ui:define>
<h:selectManyListbox style="width: 300px;" size="10" value="#{itemHome.instance.tags}">
<f:validator validatorId="TagValidator"/>
<s:selectItems var="t" value="#{allTags}" label="#{t.name}" />
<s:convertEntity />
</h:selectManyListbox>
</s:decorate>This is TagValidator code:
public void validate(FacesContext ctxt, UIComponent cmp, Object val) {
String message = null;
try {
List selectedVals = (List)val;
int numberOfTags = 0;
if (selectedVals != null) {
numberOfTags = selectedVals.size();
}
if (numberOfTags > 5)
message = "No more than 5 tags are allowed!";
} catch (Exception e){
message = "Something went wrong while processing tags!";
}
if (message != null) {
FacesMessage msg = new FacesMessage(
FacesMessage.SEVERITY_ERROR, message, message);
throw new ValidatorException(msg);
}
} Now, when I press Save, although the validation passes, I get the message The value is invalid
and the operation fails. I concluded it must have something to do Seam, as my custom validation passes.
Any idea what this may be related to? Any help is appreciated.