eclipse-ee4j / mojarra

Mojarra, a Jakarta Faces implementation
Other
159 stars 109 forks source link

ui:repeat throw duplicate component id error when set jakarta.faces.PARTIAL_STATE_SAVING=false in web.xml #5233

Open Harry3014 opened 1 year ago

Harry3014 commented 1 year ago

jsf-impl version

I use wildfly27 and jsf-impl version is 4.0.0.SP01

To Reproduce

web.xml

<context-param>
  <param-name>jakarta.faces.PARTIAL_STATE_SAVING</param-name>
  <param-value>false</param-value>
</context-param>

view

<h:form id="form">
    <ui:repeat value="#{testBean.lists}" var="list">
        <h:selectOneListbox valueChangeListener="#{test.listener}" size="2">
            <f:selectItems value="#{list}" />
            <f:ajax process="@this" />
        </h:selectOneListbox>
    </ui:repeat>
</h:form>

model

@Named
@ViewScoped
public class TestBean {
    private static List<String> list1 = Arrays.asList("1", "2");
    private static List<String> list2 = Arrays.asList("3", "4");
    private static List<List<String>> lists = Arrays.asList(list1, list2);

    public void listener(ValueChangeEvent e) {
        message = (e.getOldValue() + " -> " + e.getNewValue());
    }

    public List<List<String>> getLists() {
      return lists;
    }
}

Exception

When I click one item then throw JSF1007 (duplicate component id error)

java.lang.IllegalStateException: Component ID form:j_idt4:j_idt6 has already been found in the view. at com.sun.faces.util.Util.checkIdUniqueness(Util.java:1167) at com.sun.faces.util.Util.checkIdUniqueness(Util.java:1156) at com.sun.faces.util.Util.checkIdUniqueness(Util.java:1156) at com.sun.faces.util.Util.checkIdUniqueness(Util.java:1156) at com.sun.faces.application.view.FaceletFullStateManagementStrategy.saveView(FaceletFullStateManagementStrategy.java:674) at jakarta.faces.application.StateManager.getViewState(StateManager.java:243) at com.sun.faces.context.PartialViewContextImpl.renderState(PartialViewContextImpl.java:493) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:310) .....

Addition context If set jakarta.faces.PARTIAL_STATE_SAVING=true, it works correctly.

BalusC commented 1 year ago

Apart from the concrete problem, may I ask why exactly you're disabling partial state saving and thus using full state saving? Full state saving is discommended (de-facto deprecated) since introduction of partial state saving in JSF 2.0 and subject to be removed in a future Faces version because it's so inefficient and technically unnecessary. So I'm trying to understand use cases where it's still considered necessary (probably it's used as a work around against some problem in partial state saving?) so that we can improve Faces (e.g., fix that problem in partial state saving) in order to not make full state saving necessary anymore.

BalusC commented 1 year ago

FSS will be deprecated in 4.1. See also https://github.com/jakartaee/faces/issues/1829

mnriem commented 10 months ago

@Harry3014 As FSS will be deprecated in 4.1 / 5.0 can we close this out as won't fix and assume you are going to use PSS going forward? Or is there a specific reason for using FSS here?

BalusC commented 10 months ago

If you wish to use Mojarra 4.0 with FSS for your specific use case, then use a minimum of Mojarra 4.0.0-M6. That's the last version on which your use case worked for me. It broke in 4.0.0-M7 and it appears to be another regression of https://github.com/eclipse-ee4j/mojarra/pull/4808. Curious detail is that your use case works fine in latest 2.3.x and 3.0.x which is supposed to have the same fixes as 4.0.x related to #4808. I suspect something went wrong related to physical removal of JSP support in 4.0. But after debugging for over a hour I still couldn't figure out where it goes wrong. As FSS is going to be deprecated nonetheless I didn't feel like continuing. You're of course open to debug on your own with this new information and then create a PR on this.

Still I'd love to know and understand the reason to use FSS on your project as that's supposed to be completely unnecessary since JSF 2.0. If that was just a legacy which you forgot to migrate then ok just do it. But if that was to work around some bug which only surfaces when using PSS then by all means let us know so we can fix that bug and you can switch back to PSS.