0

If I upgrade from Mojarra 2.1.21 to Mojarra 2.1.22, 23, 24, or 26, I became an error in my view. The error has something to do with binding. (Duplicate component id) because I had binding to sessionScoped bean properties. I have changed my bean to use EL-scoped binding. So my question:

  1. Is it safe to use EL-Binding and give a bound component as parameter and read(and set properties on this component). E.g.

    View:

     <p:dataTable binding="#{table}"> ...</p:dataTable>
     <p:commandButton action="#{bean.doit(table)}" />
    

    Bean:

     public void doit(DataTable dt) {
        dt.getSomething();
        dt.setSomething();
     }
    
  2. Why it's first happened from Mojara version 2.1.22 (this version number included) ?

Tony
  • 2,016
  • 3
  • 27
  • 50

1 Answers1

2

Is it safe to use EL-Binding and give a bound component as parameter and read(and set properties on this component). E.g.

Point is, you should never bind a component as a property of a bean which is in broader scope than the request scope. UI components are inherently request scoped. During building/restoring of the view, JSF will check if the getter doesn't already return an existing component and then reuse it instead of creating a new one the usual way. However, if the bean returns an already-created one from a previous/other request/view/session which belongs to a completely different view, then this all would fail as the state collides.

In this particular solution, you're nowhere referencing the component as a bean property, so that's absolutely safe. But, probably better yet is to just bind the particular component attribute you're actually interested in instead of the whole component:

<p:dataTable something="#{bean.something}">

with

private String something;

public void doit() {
    System.out.println(something);
    something = "something new";
}

See also:


Why it's first happened from Mojara version 2.1.22 (this version number included) ?

Here are the 2.1.22 release notes. So far I'm seeing nothing strictly related to those symptoms. So, this was apparently a fix without a ticket. Perhaps a developer came along and saw some bogus code by coincidence and thought, hey that isn't right, let's fix it right now! I don't closely track the actual changes in source code which are performed without a ticket, so sorry I can't answer that part.

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