To th...">

Network components

I have a CRUD and I want to change inputTexArea:

<p:inputTextarea id="tags" value="#{myController.selected.tags}" /> 

To the new Primefaces chip component:

 <p:chips id="tags" value="#{myController.selected.tags}" /> 

Extract fragment entity:

 @Lob @Size(max = 2147483647) @Column(name = "tags") private String tags; //GETTER AND SETTER OMITTED 

The get method works just fine because the tags are displayed in the field as expected:

 public List<String> getTags() { return Arrays.asList(tags.split(",")); } 

But the set method does not exist, because when I click "Save", an exception is thrown:

 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 already asked this for the Primefaces team ( https://forum.primefaces.org/viewtopic.php?f=3&t=51091 ), and the main developer of Primefaces (Thomas Andraschko) directed me to ask the Hibernate validator team.

+5
source share
3 answers

It looks like the Hibernate validator is confused with your recipient returning a List<String> for the String field. Try the following:

 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}" /> 
+3
source

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); } 
+1
source

If you do not have java 8, but have an Apache Commons Lang library, you can use

StringUtils method: org.apache.commons.lang.StringUtils.join (tags, ",") instead of String.join (",", tags);

+1
source

Source: https://habr.com/ru/post/1265799/


All Articles