question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chips: validator acts on list instead of item

See original GitHub issue

Using e.g. <f:validateLongRange minimum="0" maximum="42" /> in the chips component does not work as the validator acts on the value list instead of the single items. Adding a valid integer item results in a validation error. It seems impossible to use List<Integer>.

On the other hand, adding a string to the int list immediatelly throws an error. The validator is not called at all.

Environment:

  • PF Version: 8.0.2
  • Mojarra 2.3.14

Expected behavior The validator validates an added item before the item is finally added to the list.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mellowarecommented, Mar 31, 2021

Actually the more i think about this maybe it should handle this. reopening.

1reaction
svenhaagcommented, Dec 16, 2020

Thanks @melloware, that’s exactly what I already did. Like so:

public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
  List list = (List) value;
  for (Object entry : list) {
    if (null != entry) {
      final long longValue = Long.parseLong(String.valueOf(entry));
      if (666L == longValue) { // exemplary
        throw new ValidatorException(...);
      }
    }
  }
}

Additionally I have set up a ValueChangeListener to modify (sort and make unique) the Chips entries, like so:

public void handleChipsValueChange(final ValueChangeEvent event) {
	final List<String> newList = ((List<String>) event.getNewValue());
	newList.removeAll(Collections.singleton(null));
	newList.sort(Comparator.comparingInt(Integer::valueOf));

	// remove duplicates in place
	final Set<String> deDuplicated = new HashSet<>();
	Iterator<String> it = newList.iterator();
	while (it.hasNext()) {
		final String entry = it.next();
		if (deDuplicated.contains(entry)) {
			it.remove();
		} else {
			deDuplicated.add(entry);
		}
	}
}

Cheers

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 2+ material mat-chip-list formArray validation
How do I validate that a mat-chip has been added to the mat-chip-list . I am using ReactiveForms. I have tried with the...
Read more >
validation for chips · Issue #8801 · angular/components - GitHub
The goal is that invalid chips are never created and the user receives an early feedback instead of having to delete the chip....
Read more >
CHIPS and Science Act
DIVISION A—CHIPS ACT OF 2022. Sec. 101. Short title. Sec. 102. Creating helpful incentives to produce semiconductors (CHIPS) for.
Read more >
Text - H.R.2471 - 117th Congress (2021-2022): Consolidated ...
Legislation ; Legislation Text; Committee Reports; Congressional Record ... for each end-item covered by the preceding proviso, a detailed list of the ...
Read more >
Cryptographic Module Validation Program CMVP
Module Name Standard Status Thunder FIPS 140‑2 Coordination (11/14/2022) Acronis SCS Cryptographic Module FIPS 140‑2 Review Pending (9/26/2022) Encryption Card 9TCE‑PCN‑10GU+AES10G‑F FIPS 140‑2 Coordination (9/28/2022)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found