Viewing page code for a JSF page

Each Facelet or Faces JSP page that you create has a corresponding file that contains its Java™ page code. The page code file includes such information as the Java classes that are referenced, data that is referenced when you drag records to the page, binding information, and any code scripted in the Quick Edit view for button actions or value changed events.

About this task

Note: A page code file is required if you want to add a relational record or relational record list to a JSF page. If you have page code suppression turned on when adding a relational record or relational record list, you are prompted to allow a page code file to be generated.

When you create a JSF page, an empty Java class with the same name is generated in the pagecode package. For example if you create a Facelet page named CustomerList.xhtml, the class pagecode.CustomerList is created. This class is registered as a request scope managed bean in the Faces configuration file, with the name of the Java class prefixed with pc_, so the CustomerList class is registered as the managed bean pc_CustomerList. This managed bean is used for the root of most of the value and method binding expressions in the Facelet page.

Generated page code package.

Page code managed beans are repositories for convenience methods for accessing relevant data from the page, such as UI components, other managed beans, and action logic. These methods are usually coupled with private references to the data, which are lazy initialized by the accessor methods.

To view the contents of the Java page code file for a JSF page:

Procedure

  1. Right-click within a blank area of the page in the Design, Split or Source view.
  2. Click Edit Page Code.

Results

By default, a page code file is generated for each JSF page, but you can change this at any time in the Preferences settings. You also have the options to delete page code file information when you delete a JSF page and to generate fields and getters in the page code file for all Faces components.

To configure the JSF page code options:
  1. Click Window > Preferences.
  2. Expand Web Tools > JavaServer Faces Tools > Page Code.

When you create the first JSF file in a Web project, the parent class for all the generated page code, pagecode.PageCodeBase, is generated into the project. This is a good location to add common functions that you want to use in all of your page code.

The parent for all page code comes with a number of convenience methods to be used in the action logic. These methods assist in finding components in the UI tree, manual navigation, and logging, among other functions.

Example of UI components in page code

About this task

For example, drag a Button - Command onto a Facelet page, change its ID to selectButton, and edit its command event so that the source is:
<h:commandButton type="submit" value="Submit"	styleClass="commandButton" id="selectButton" 
action="#{pc_CustomerSelect.doSelectButtonAction}">
</h:commandButton>
The page code managed bean is automatically updated with an instance of the UI component underlying this tag, a convenience method for initializing and accessing that component, and the method implementing the command event:
protected UINamingContainer subview1;
	protected HtmlCommandButton selectButton;
	protected HtmlForm form1;

	protected UINamingContainer getSubview1() {
		if (subview1 == null) {
			subview1 = (UINamingContainer) findComponentInRoot("subview1");
		}
		return subview1;
	}

	protected HtmlCommandButton getSelectButton() {
		if (selectButton == null) {
			selectButton = (HtmlCommandButton) findComponentInRoot("selectButton");
		}
		return selectButton;
	}

	protected HtmlForm getForm1() {
		if (form1 == null) {
			form1 = (HtmlForm) findComponentInRoot("form1");
		}
		return form1;
	}

}

Feedback