XPages Request Processing Lifecycle explorer code...


XPages Request Processing Lifecycle explorer...

Push the following code into an NSF, and use to explore and gain understanding of the XPages Request Processing Lifecycle:

Code 1: XSP markup...

<?xml version="1.0" encoding="UTF-8"?>
<xp:view id="view1" xmlns:xp="http://www.ibm.com/xsp/core" style="background:#fff;margin:10px;">
	<xp:this.beforePageLoad>
		<![CDATA[#{javascript:
			print(" ");
			print("Request:\tStarted...");
			print(" ");
			print("Page:\t\tview1->beforePageLoad")}]]>
	</xp:this.beforePageLoad>
	<xp:this.afterPageLoad>
		<![CDATA[#{javascript:print("Page:\t\tview1->afterPageLoad")}]]>
	</xp:this.afterPageLoad>
	<xp:this.afterRestoreView>
		<![CDATA[#{javascript:print("Page:\t\tview1->afterRestoreView")}]]>
	</xp:this.afterRestoreView>
	<xp:this.beforeRenderResponse>
		<![CDATA[#{javascript:print("Page:\t\tview1->beforeRenderResponse")}]]>
	</xp:this.beforeRenderResponse>
	<xp:this.afterRenderResponse>
		<![CDATA[#{javascript:print("Page:\t\tview1->afterRenderResponse")}]]>
	</xp:this.afterRenderResponse>
	<xp:panel id="p1"
		style="margin:10px;padding:10px;border:2px dashed #0f0;width:400px;"
		title="p1">
		<xp:label value="p1" id="label1" style="font-weight:bold;"></xp:label>
		<xp:br></xp:br>
		<xp:br></xp:br>
		<xp:text id="txt1"
			rendered="#{javascript:print('Control:\ttxt1->rendered'); return true}"
			loaded="${javascript:print('Control:\ttxt1->loaded'); return true}"
			value="#{javascript:java.lang.System.currentTimeMillis()}">
		</xp:text>
		<xp:panel id="p2"
			style="margin:10px;padding:10px;border:2px dashed #00f;">
			<xp:label value="p2" id="label2" style="font-weight:bold;"></xp:label>
			<xp:br></xp:br>
			<xp:br></xp:br>
			<xp:text id="txt2"
				rendered="#{javascript:print('Control:\ttxt2->rendered'); return true}"
				loaded="${javascript:print('Control:\ttxt2->loaded'); return true}"
				value="#{javascript:java.lang.System.currentTimeMillis()}">
			</xp:text>
			<xp:br></xp:br>
			<xp:br></xp:br>
			<xp:inputText id="inputText1" required="true"
				disableClientSideValidation="true">
				<xp:this.validators>
					<xp:validateRequired
						message="Please supply a value">
					</xp:validateRequired>
				</xp:this.validators>
			</xp:inputText>
			<xp:message id="message1" for="inputText1"></xp:message>
			<xp:br></xp:br>
			<xp:br></xp:br>
			<xp:button value="p2" id="button2">
				<xp:eventHandler event="onclick" submit="true"
					refreshMode="partial" execMode="partial" refreshId="p2" execId="p2">
					<xp:this.action><![CDATA[#{javascript:print("Event:\t\tp2->partial refresh/execute")}]]></xp:this.action>
				</xp:eventHandler>
			</xp:button>
			<xp:button value="p2 immediate" id="button4">
				<xp:eventHandler event="onclick" submit="true"
					refreshMode="partial" execMode="partial" refreshId="p2" execId="p2"
					immediate="true">
					<xp:this.action><![CDATA[#{javascript:print("Event:\t\tp2->partial refresh/execute/immediate")}]]></xp:this.action>
				</xp:eventHandler>
			</xp:button>
			<xp:button value="p2 disableValidators" id="button6">
				<xp:eventHandler event="onclick" submit="true"
					refreshMode="partial" execMode="partial" refreshId="p2" execId="p2"
					disableValidators="true">
					<xp:this.action><![CDATA[#{javascript:print("Event:\t\tp2->partial refresh/execute/disableValidators")}]]></xp:this.action>
				</xp:eventHandler>
			</xp:button>
		</xp:panel>
		<xp:br></xp:br>
		<xp:button value="p1" id="button1">
			<xp:eventHandler event="onclick" submit="true"
				refreshMode="partial" execMode="partial" refreshId="p1"
				execId="p1">
				<xp:this.action><![CDATA[#{javascript:print("Event:\t\tp1->refresh/execute")}]]></xp:this.action>
			</xp:eventHandler>
		</xp:button>
		<xp:button value="p1 immediate" id="button3">
			<xp:eventHandler event="onclick" submit="true"
				refreshMode="partial" execMode="partial" refreshId="p1" execId="p1"
				immediate="true">
				<xp:this.action><![CDATA[#{javascript:print("Event:\t\tp1->refresh/execute/immediate")}]]></xp:this.action>
			</xp:eventHandler>
		</xp:button>
		<xp:button value="p1 disableValidators" id="button5">
			<xp:eventHandler event="onclick" submit="true"
				refreshMode="partial" execMode="partial" refreshId="p1" execId="p1"
				disableValidators="true">
				<xp:this.action><![CDATA[#{javascript:print("Event:\t\tp1->refresh/execute/disableValidators")}]]></xp:this.action>
			</xp:eventHandler>
		</xp:button>
	</xp:panel>
	<xp:br></xp:br>
	<xp:text id="txt3"
		rendered="#{javascript:print('Control:\ttxt3->rendered'); return true}"
		loaded="${javascript:print('Control:\ttxt3->loaded'); return true}"
		value="#{javascript:java.lang.System.currentTimeMillis()}">
	</xp:text>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:button value="p2 (partial execute / full refresh)" id="button7">
		<xp:eventHandler event="onclick" submit="true"
			execMode="partial" execId="p2">
			<xp:this.action><![CDATA[#{javascript:print("Event:\t\tp2->partial execute\tvalue: " +
				getComponent("inputText1").getValue())}]]></xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:button value="p2 (full execute / partial refresh)" id="button8">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="partial" refreshId="p2">
			<xp:this.action><![CDATA[#{javascript:print("Event:\t\tp2->partial refresh\tvalue: " +
				getComponent("inputText1").getValue())}]]></xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:button value="p2 (partial execute / partial refresh" id="button9">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="partial" execMode="partial" refreshId="p2" execId="p2">
			<xp:this.action><![CDATA[#{javascript:print("Event:\t\tp2->partial refresh/execute\tvalue: " +
				getComponent("inputText1").getValue())}]]></xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:br></xp:br>
	<xp:br></xp:br>
	<xp:button value="no id (partial execute / full refresh)" id="button10">
		<xp:eventHandler event="onclick" submit="true"
			execMode="partial">
			<xp:this.action><![CDATA[#{javascript:print("Event:\t\tno id->partial execute\tvalue: " +
				getComponent("inputText1").getValue())}]]></xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:button value="no id (full execute / partial refresh)" id="button11">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="partial">
			<xp:this.action><![CDATA[#{javascript:print("Event:\t\tno id->partial refresh\tvalue: " +
				getComponent("inputText1").getValue())}]]></xp:this.action>
		</xp:eventHandler>
	</xp:button>
	<xp:button value="no id (partial execute / partial refresh" id="button12">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="partial" execMode="partial">
			<xp:this.action><![CDATA[#{javascript:print("Event:\t\tno id->partial refresh/execute\tvalue: " +
				getComponent("inputText1").getValue())}]]></xp:this.action>
		</xp:eventHandler>
	</xp:button>
</xp:view>

Code 2: faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
  <lifecycle>
    <phase-listener>com.ibm.xsp.util.XSPPhaseListener</phase-listener>
  </lifecycle>
  <!--AUTOGEN-START-BUILDER: Automatically generated by IBM Lotus Domino Designer. Do not modify.-->
  <!--AUTOGEN-END-BUILDER: End of automatically generated section-->
</faces-config>

Code 3: XSPPhaseListener java class (put in a package that matches defined structure)

package com.ibm.xsp.util;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;

/**
 * @author Tony McGuckin, IBM
 */
public class XSPPhaseListener implements javax.faces.event.PhaseListener {

	private static final long serialVersionUID = 1L;

	public PhaseId getPhaseId() {
    	return PhaseId.ANY_PHASE;
    }

    public void beforePhase(PhaseEvent event) {
    	if(event.getPhaseId().equals(PhaseId.RESTORE_VIEW)){
        	System.out.println(" ");
    		System.out.println("Request:\tStarted...");
    	}
    	System.out.println(" ");
    	System.out.println("Lifecycle:\tBefore Phase: " + event.getPhaseId());
    }

    public void afterPhase(PhaseEvent event) {
    	System.out.println("Lifecycle:\tAfter Phase: " + event.getPhaseId());
    	System.out.println(" ");
    	if(event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)){
    		System.out.println("Request:\tCompleted.");
    		System.out.println(" ");
    	}
    }
}

Finally... explore the actions etc through a browser, and study the Domino console output to learn what is happening with your requests... like so -- enjoy!!

[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Request:       Started...
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     Before Phase: RESTORE_VIEW 1
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Page:          view1->afterRestoreView
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     After Phase: RESTORE_VIEW 1
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     Before Phase: APPLY_REQUEST_VALUES 2
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Control:       txt1->rendered
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Control:       txt2->rendered
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     After Phase: APPLY_REQUEST_VALUES 2
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     Before Phase: PROCESS_VALIDATIONS 3
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Control:       txt1->rendered
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Control:       txt2->rendered
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     After Phase: PROCESS_VALIDATIONS 3
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     Before Phase: UPDATE_MODEL_VALUES 4
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Control:       txt1->rendered
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Control:       txt2->rendered
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     After Phase: UPDATE_MODEL_VALUES 4
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     Before Phase: INVOKE_APPLICATION 5
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Event:         p1->refresh/execute
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     After Phase: INVOKE_APPLICATION 5
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     Before Phase: RENDER_RESPONSE 6
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Page:          view1->beforeRenderResponse
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Control:       txt1->rendered
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Control:       txt2->rendered
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Page:          view1->afterRenderResponse
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Lifecycle:     After Phase: RENDER_RESPONSE 6
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM:
[1EC8:000A-1EA8] 01/03/2012 10:10:50   HTTP JVM: Request:       Completed.



All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
1 comment(s)Login first to comment...
Andrew Grabovetskyi
(at 16:26 on 12.11.2013)
Thanks!