Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnLoadScript: Behavior difference in MyFaces/Mojarra #804

Closed
melloware opened this issue Apr 19, 2024 · 3 comments
Closed

OnLoadScript: Behavior difference in MyFaces/Mojarra #804

melloware opened this issue Apr 19, 2024 · 3 comments

Comments

@melloware
Copy link
Contributor

Original PF ticket: primefaces/primefaces#11780

This example works in PF 13.0.7 but does not work in 13.0.8

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:o="http://omnifaces.org/ui"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
    <h:head></h:head>
    <h:body>
        <c:if test="true">

        </c:if>
        <o:onloadScript>
            console.log('hi');
        </o:onloadScript>
        <h:form>
            <h1>
                This example works in PF 13.0.7 but does not work in PF 13.0.8
            </h1>
            <p:autoComplete id="acSimple" value="#{autocompleteViewBean.value}"
                            completeMethod="#{autocompleteViewBean.complete}" scrollHeight="250"/>
        </h:form>
    </h:body>
</f:view>
</html>

In order for this to fail it has to have both a <c:if> and a <o:onloadScript>, so I'm not sure where is the bug, but it was working in previous versions.

I provided a minimal reproducer in:
pf-11780.zip

To run it:
mvn clean jetty:run -Pmyfaces23next FAILS
mvn clean jetty:run -Pmojarra23 WORKS

Then open http://localhost:8080/primefaces-test/ and check that the autocomplete doesn't work (the call is performed and I can see the results in the xhr response but the update is lost somehow).

Change PF version to 13.0.7 and it works again

Analysis

OK here is why. MyFaces puts it in both <eval> section and javax.faces.Resource section and Mojarra only puts it in the <eval> section.

Since I added this fix primefaces/primefaces#11714 it must be what is causing the issue.

MyFaces

<?xml version="1.0" encoding="UTF-8"?>
<partial-response id="j_id__v_0">
	<changes>
		<update id="javax.faces.Resource"><![CDATA[
            console.log('hi');
        ]]></update>
		<update id="j_id_9:acSimple"><![CDATA[<ul class="ui-autocomplete-items ui-autocomplete-list ui-widget-content ui-widget ui-corner-all ui-helper-reset" role="listbox"><li id="j_id_9:acSimple_item_0" class="ui-autocomplete-item ui-autocomplete-list-item ui-corner-all" data-item-label="Result 1" data-item-value="Result 1" data-item-class="">Result 1</li><li id="j_id_9:acSimple_item_1" class="ui-autocomplete-item ui-autocomplete-list-item ui-corner-all" data-item-label="Result 2" data-item-value="Result 2" data-item-class="">Result 2</li><li id="j_id_9:acSimple_item_2" class="ui-autocomplete-item ui-autocomplete-list-item ui-corner-all" data-item-label="Result 3" data-item-value="Result 3" data-item-class="">Result 3</li></ul>]]></update>
		<update id="j_id__v_0:javax.faces.ViewState:1"><![CDATA[YTFlMDk1NzRjYzBmMTlmYjAwMDAwMDAx]]></update>
		<eval><![CDATA[console.log('hi');]]></eval>
	</changes>
</partial-response>

Mojarra

<?xml version='1.0' encoding='utf-8'?>
<partial-response>
	<changes>
		<update id="j_idt6:acSimple"><![CDATA[<ul class="ui-autocomplete-items ui-autocomplete-list ui-widget-content ui-widget ui-corner-all ui-helper-reset" role="listbox"><li id="j_idt6:acSimple_item_0" class="ui-autocomplete-item ui-autocomplete-list-item ui-corner-all" data-item-label="Result 1" data-item-value="Result 1">Result 1</li><li id="j_idt6:acSimple_item_1" class="ui-autocomplete-item ui-autocomplete-list-item ui-corner-all" data-item-label="Result 2" data-item-value="Result 2">Result 2</li><li id="j_idt6:acSimple_item_2" class="ui-autocomplete-item ui-autocomplete-list-item ui-corner-all" data-item-label="Result 3" data-item-value="Result 3">Result 3</li></ul>]]></update>
		<update id="j_id1:javax.faces.ViewState:0"><![CDATA[-4627649845244533925:-1742591768271823828]]></update>
		<eval><![CDATA[console.log('hi');]]></eval>
	</changes>
</partial-response>

@BalusC the question is what is the correct place for this the Resource or eval? Is this something MyFaces is doing wrong or is the spec unclear?

@BalusC
Copy link
Member

BalusC commented May 5, 2024

Deja vu: #366

@melloware
Copy link
Contributor Author

I reopened MyFaces https://issues.apache.org/jira/browse/MYFACES-4378 with the reproducer and the 2 primefaces issues that lead me here.

Also the original fix that exposed this BalusC was this one: primefaces/primefaces#11714

I have a client I think using Wildfly 12 and I noticed every time they close and open a tab it keeps adding dynamic resources to the page even though they are already in the Faces Tree. My guess is its some Mojarra bug that has long since been fixed but I was trying to make PrimeFaces code smarter than just appending to the head always.

else if (id === PrimeFaces.ajax.RESOURCE) {
    $('head').append(content);
} 

@BalusC
Copy link
Member

BalusC commented May 24, 2024

Not an OmniFaces bug, closing off.

Note:

@BalusC BalusC closed this as completed May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants