I have a CRUD and I want to change the inputTexArea:
<p:inputTextarea id="tags" value="#{myController.selected.tags}" />
To the new Primefaces chips component:
<p:chips id="tags" value="#{myController.selected.tags}" />
An entity class excerpt:
@Lob
@Size(max = 2147483647)
@Column(name = "tags")
private String tags;
//GETTER AND SETTER OMITTED
The get method works fine, because the tags are displayed in the field as expected:
public List<String> getTags() {
return Arrays.asList(tags.split(","));
}
But the set method is not, because when I click on Save, occurs an Exception:
public void setTags(List<String> tags) {
this.tags = String.join(",", tags);
}
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.CharSequence
at org.hibernate.validator.internal.constraintvalidators.SizeValidatorForCharSequence.isValid(SizeValidatorForCharSequence.java:33)
at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateSingleConstraint(ConstraintTree.java:281)
Can someone help me, please ?
Thanks in advance.
ps.: I've already asked this to Primefaces team (https://forum.primefaces.org/viewtopic.php?f=3&t=51091), and a Primefaces core developer (Thomas Andraschko) orientated me to ask Hibernate validator team.
It seems like Hibernate validator is confused with your getter returning List<String>
for a String
field. Try this:
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public List<String> getTagsList() {
return Arrays.asList(tags.split(","));
}
public void setTagsList(List<String> tags) {
this.tags = String.join(",", tags);
}
And then:
<p:chips id="tags" value="#{myController.selected.tagsList}" />
p:chips uses a list as a value, why don't you use this instead:
private String tags = "aaaa,bbb";
public List<String> getTags() {
return Arrays.asList(tags.split(","));
}
public void setTags(List<String> tags) {
this.tags = String.join(",", tags);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With