Get jspx at SourceForge.net. Fast, secure and Free Open Source software downloads home | download | demo project | contact us
jspx

Rate this article:

email
comment
Average Rate= 4.5

Hello Jspx (With Controller)

This is the same as the first example however this time the Label will be populated with the message from the java controller. Let's have a look on the changes applied since the previous example.
Html file
  1. The Label tag has an id with value "message"
  2. The Page tag has an attribute named controller with value "org.bay.jspx.demo.live.HelloJspxController" which is the full name of the java class that acts as the controller for this HTML
java file
  1. The controller class extends the Page from jspx. In case of Master or Content pages, the parent class should be MasterPage or ContentPage .
  2. In order to have access on the html element Label in the HTML file, an instance of WebControl Label should be declared
  3. Without Annotation
    1. The name of the label instance SHOULD be the same value as the ID value used in HTML file which is in our case message.
    2. There should be a getter and a setter for the control.
  4. With Annotation
    1. The name of the label instance MAY be the same value as the ID value used in HTML file which is in our case message.
    2. If the name of the instance is not the same as the id of the HMTL, then the annotation MUST specify the name value to be the same as the id of the HTML element which is in our case message
    3. No getters or setters are required.

Demo


Source Code:

			<page contoller="org.bay.jspx.demo.live.HelloJspxController" >
				<html>
					<body>
						<label id="message"></label>
					</body>
				</html>
			</page>
			

package org.bay.jspx.demo.live;

import eg.java.net.web.jspx.engine.annotation.JspxWebControl;
import eg.java.net.web.jspx.ui.controls.html.elements.Label;
import eg.java.net.web.jspx.ui.pages.Page;

public class HelloJspxController extends Page
{
	@JspxWebControl(name = "message")
	Label msg;

	@Override
	protected void pageLoaded()
	{
		msg.setValue("Hello Jspx from Java controller!");
	}
}