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.

Global: Invalid state for inputs referenced from a FacesMessage via clientId

See original GitHub issue

We sometimes add errors to inputs via Java-business-logic: FacesContext.getCurrentInstance().addMessage("form:txt", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "Contact admin."));

This come with the limitation, that this input does not get the same red border like inputs which have an validation-error.

The following generic code make setValid(false) to all input´s which have a error-message.

private void transferFacesErrors2NotValid() {
	Spliterator<String> spliterator = Spliterators.spliteratorUnknownSize(FacesContext.getCurrentInstance().getClientIdsWithMessages(), 0);
	StreamSupport.stream(spliterator, false).forEach(clientId -> {
		long errors = FacesContext.getCurrentInstance().getMessageList(clientId).stream().filter(m -> m.getSeverity().equals(FacesMessage.SEVERITY_ERROR)).count();

		if (errors>0) {
			UIComponent uiComp = FacesContext.getCurrentInstance().getViewRoot().findComponent(clientId);
			if (uiComp instanceof UIInput) {
				((UIInput) uiComp).setValid(false);
			}
		}
	});
}

By setting valid to false the inputs get the red border.

Is this something we may add in some way to PrimeFaces?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
tandraschkocommented, Dec 18, 2019

I think we can add it with a config flag in 9.0 which is disabled per default

0reactions
christophs78commented, Sep 2, 2020

should work now

look good

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting the current global messages from FacesContext
When validation error messages are produced, the facelet works fine, because one of the messages tag has the globalOnly="true" ...
Read more >
Primefaces Message, Messages &amp; Growl components ...
Queuing messages require to pass through jsf lifecycle. ... false, String, When true, only facesmessages with no clientIds are displayed.
Read more >
17 Displaying Tips, Messages, and Help - Oracle Help Center
This chapter describes how to define and display tips and messages for ADF Faces components, and how to provide different levels of help...
Read more >
Component Reference - Red Hat on GitHub - JBoss.org
A reference guide to the components of the RichFaces 4 framework ... values from the input element and auxiliary information such as state-saving...
Read more >
Multiple Messages for a Single Component - Cameron Gregor
A FacesMessage can either be 'Global', which means it has no relation to any ... either from Java using the FacesMessages class as...
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