1

Firstly, sorry my english. I'm brazilian and I have a problem. I have a panelGroup that is duplicating the validation message when I use the component global messages. Look:

That is my page xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
  xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
    <h:form>
        Hello from Facelets

        <h:panelGroup binding="#{testeMB.panel}" >

            <p:inputText id="field_id" value="#{testeMB.field}"
                required="true" />

            <p:commandButton id="button_id" value="Submeter"
                action="#{testeMB.submit}" ajax="false" />

        </h:panelGroup>
    </h:form>
</h:body>

That is my ManagedBean:

@ManagedBean
@ViewScoped
public class TesteMB implements Serializable {

    public static final long serialVersionID = 1L;

    private HtmlPanelGroup panel;
    private String field;

    public TesteMB() {

    }

    public void submit() {
        System.out.println("Form submited!!!");
    }

    // gets and sets

}

In the end, it prints the same message twice. Look:

enter image description here

Looking at the life cycle of the JSF in any cycle less RENDER_RESPONSE, there are 4 components. Has anyone here ever experienced this?

It was identified that this problem is going from version 2.1.22 onwards. What I do not know why. Thanks to everyone who tried.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Ascension
  • 1,511
  • 1
  • 11
  • 12

1 Answers1

1

Component instances are request scoped. You should not bind them to a bean in a broader scope. Bind them to a request scoped bean and inject the view scoped bean in it, if necessary.

Generally speaking, when using a powerful view technology like Facelets, binding a JSF component to a bean property is a huge code smell. Whatever functional requirement you thought to solve by binding the component to a bean property this way is most likely just solveable without using the binding.

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452