Primefaces Chips Web Component

UI Components for JSF
Post Reply
f6750699
Posts: 21
Joined: 09 Oct 2013, 03:43

26 May 2017, 23:21

I have a CRUD and I want to change the inputTexArea:

Code: Select all

    <p:inputTextarea id="tags" value="#{myController.selected.tags}" />
To the new Primefaces <b>chips</b> component:

Code: Select all

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

Code: Select all

@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:

Code: Select all

    public List<String> getTags() {
    return Arrays.asList(tags.split(","));
    }
But the set method is not, because when I click on Save, occurs an Exception:

Code: Select all

    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.
Marcel Vieira
Primefaces 6.2 / JSF 2.2 / Glassfish 4

tandraschko
PrimeFaces Core Developer
Posts: 3607
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

27 May 2017, 10:51

Try to ask the hibernate validator guys. It seems like it uses getter and the property and those types doesn't match.
Thomas Andraschko

PrimeFaces Developer | PrimeFaces Extensions Founder

Apache Member | PMC @ OpenWebBeans, DeltaSpike, MyFaces, BVal | Contributor @ TomEE

Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

f6750699
Posts: 21
Joined: 09 Oct 2013, 03:43

30 May 2017, 19:45

tandraschko wrote:
27 May 2017, 10:51
Try to ask the hibernate validator guys. It seems like it uses getter and the property and those types doesn't match.
I really appreciate your help.
I've already posted this question in https://forum.hibernate.org/viewforum.php?f=1.

Thank you!
Marcel Vieira
Primefaces 6.2 / JSF 2.2 / Glassfish 4

f6750699
Posts: 21
Joined: 09 Oct 2013, 03:43

20 Mar 2018, 21:45

Hi @tandraschko.

As you've oriented me, I've aske the Hibernate Validator guys and they answered me to adapt my code (https://discourse.hibernate.org/t/prime ... ence/374/2).

Accordingly to https://www.primefaces.org/docs/guide/p ... de_6_2.pdf (page 103), chips uses a List, so I mapped my entity class as below:

Code: Select all

@Column(name = "TAGS")
private List<String> tags;

public List<String> getTags() {
    return tags;
}

public void setTags(List<String> tags) {
    this.tags = tags;
}
and got the Exception:

Code: Select all

org.eclipse.persistence.exceptions.ConversionException
Exception Description: The object [exampleTag1, exampleTag2, exampleTag3], of class 
[class java.lang.String], from mapping 
[org.eclipse.persistence.mappings.DirectToFieldMapping[tags-->APP.PRODUCT.TAGS]] 
with descriptor [RelationalDescriptor(entity.Product --> 
[DatabaseTable(APP.PRODUCT)])], could not be converted to [class [B].
Please, can you help me to solve this ?
Marcel Vieira
Primefaces 6.2 / JSF 2.2 / Glassfish 4

f6750699
Posts: 21
Joined: 09 Oct 2013, 03:43

22 Mar 2018, 00:14

Hi @tandraschko!

I've got some help in stackoverflow forum and finally resolved it:

Code: Select all

//entity bean column mapping :
@Lob
@Size(max = 2147483647)
@Column(name = "tagsColab")
private String tagsColab;

//entity bean methods:
public String getTagsColab() {
    return tagsColab;
}

public void setTagsColab(String tagsColab) {
    this.tagsColab = tagsColab;
}

public List<String> getTagsColabList() {
    if (tagsColab==null) {
        tagsColab = ""; // workaround to avoid NullPointerException when loading the form to insert new register
    }
    return Arrays.asList(tagsColab.split(","));
}

public void setTagsColabList(List<String> tagsColab) {
    this.tagsColab = (tagsColab); 
}

//JSF (use in the create or edit page):
<p:chips id="tagsColab" value="#{colabController.selected.tagsColabList}" />
Marcel Vieira
Primefaces 6.2 / JSF 2.2 / Glassfish 4

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests