1

I am new to using omnifaces. From the little I gathered, the postInvokeAction is a better choice to use when handling objects in flashscope rather than the jsf preRenderView event. But what I noticed is that the listener method is been called twice! I felt that the preInvokeAction is analogous to the before phase listener and the postInvokeAction analogous to the after phase listener equivalent of the PhaseID.INVOKE_APPLICATION and as such should be called only once for the corresponding event. Is this correct? Kindly explain to me please.

I currently run on Mojarra 2.1.17 and Omnifaces 1.3.

Thank you in anticipation for your replies!

layout1.html

    <h:body>
    <p style="color: blue; font-size: 12pt;">1. This is the main content of the file.</p>
    <ui:insert name="body_contents"/>
    <p style="color: blue; font-size: 12pt;">This is the the remaining part of the document...   in layout1</p>
    </h:body>

samplepage2.html

<h:body>
    <f:view>
        <f:metadata>
            <f:viewParam name="dummy_var" value="#{sampletest.val_test}"/>
            <f:event type="postInvokeAction" listener="#{sampletest.frompostinvokeaction}" />
            <f:event type="preRenderView" listener="#{sampletest.fromprerenderview}" />
        </f:metadata>
    </f:view>
    <ui:composition template='/layout1.html'>
        <ui:define name="title_on_head">
            <style type="text/css">
                .pkssd{
                    min-width: 340px; min-height: 30px; background: appworkspace; color: blue; font-size: 11pt; font-style: italic;
                }
            </style>
        </ui:define>
        <ui:define name="body_contents">
            <p class="pkssd">This is the active content...</p>
        </ui:define>
    </ui:composition>
</h:body>

SampleTest.java

@ManagedBean(name="sampletest")
@ViewScoped
public class SampleTest {
private String val_test;    public void frompostinvokeaction(){
    System.out.println("frompostinvokeaction: val_test: " + val_test);    }
public void fromprerenderview(ComponentSystemEvent cse){
    System.out.println("fromprerenderview : val_test: " + val_test);
}
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
shorley
  • 35
  • 1
  • 5
  • Works fine for me. It'd be helpful if you show an SSCCE of how you've used it. Then we can perhaps point out your mistake. – BalusC Feb 26 '13 at 18:56

1 Answers1

0

The way how you used master/client templates is not entirely correct. It's completely off from the specification and may have caused unspecified behavior.

The proper way would be this:

/WEB-INF/layout1.html

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
>
    <f:view>
        <ui:insert name="metadata" />
        <h:head>
            ...
            <ui:insert name="title_on_head" />
            ...
        </h:head>
        <h:body>
            ...
            <ui:insert name="body_contents" />
            ...
        </h:body>
    </f:view>
</html>

/samplepage2.html

<ui:composition template="/WEB-INF/layout1.html">
    <ui:define name="metadata">
        <f:metadata>
            <f:viewParam name="dummy_var" value="#{sampletest.val_test}"/>
            <f:event type="postInvokeAction" listener="#{sampletest.frompostinvokeaction}" />
            <f:event type="preRenderView" listener="#{sampletest.fromprerenderview}" />
        </f:metadata>
    </ui:define>

    <ui:define name="title_on_head">
        <style type="text/css">
            .pkssd{
                min-width: 340px; min-height: 30px; background: appworkspace; color: blue; font-size: 11pt; font-style: italic;
            }
        </style>
    </ui:define>

    <ui:define name="body_contents">
        <p class="pkssd">This is the active content...</p>
    </ui:define>
</ui:composition>

(yes, that's the complete file, there's nothing outside <ui:composition>)

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks BalusC! I did the refactoring as suggested but the postInvokeAction method is still been called two times. Any idea please? Appreciate your usual response. – shorley Feb 28 '13 at 08:34
  • Any chance that you're having CDI's `beans.xml` and using Weld older than 1.1.11? If so, see http://stackoverflow.com/questions/14598720/prerenderview-event-order-and-placement/14647248#14647248 and subsequently https://issues.jboss.org/browse/WELD-1247 – BalusC Feb 28 '13 at 11:06
  • Nope. Am not using that. Just using ManagedBean and ViewScoped. The complete code is already shown above. There's no beans.xml in my file also. Please advise – shorley Feb 28 '13 at 12:35
  • Sorry, I can't reproduce it. Which server are you using? – BalusC Feb 28 '13 at 12:42
  • Hello BalusC, i run on Glassfish3.1.2, mojarra 2.1.17 – shorley Mar 01 '13 at 08:12
  • I don't have 3.1.2 at hands, but I can't reproduce on 3.1.2.2. Just to exclude the one and other, have you manually registered `InvokeActionEventListener` in `faces-config.xml`? (you should not do that, it's already done in OmniFaces own `faces-config.xml`). It sounds too much like that you've somehow 2 instances of that phase listener registered. Perhaps you've duplicate OmniFaces JAR files? – BalusC Mar 01 '13 at 13:34
  • Hmmm, dat was just it! it was indeed duplicated. Quite a strange behaviour then, what do you think? Anyway BalusC, thanks so much! you are the man! – shorley Mar 01 '13 at 17:49
  • The phase listener is auto-registered via OmniFaces own `faces-config.xml`. If you've two of those JAR files, then you'll end up with two phase listeners, each independently doing its job. – BalusC Mar 02 '13 at 00:39
  • Ok, i understand now. Thanks so much once again BalusC! – shorley Mar 03 '13 at 10:18