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.0

Jspx Bean

This is the same as the Simple Form (Ajax) however this time the Data Binding is done by using Jspx Bean. Jspx Bean is a normal standard Java Bean like the Customer Bean in the code below. In order to use a Java class as a Jspx Bean it is required to declare the instance of this bean in the controller and annotate it with @JspxBean

The Annotation should describe the name of the bean customer this value is used in the HTML file for EL expression. The expression will be for example



Html file
  1. The EL expression is used in Read/Write
    1. in case of read, the expression is written anywhere in the page
    2. in case of write, the expression is written in the attribute value.
java file
  1. It is only required to declare the jspx bean instance as shown in code. No need for any server side declaration for the HTML controls.
More details about Jspx Bean are found in this document
Demo

Username:
Password:
Mobile:
email:
Birthdate:
Martial Status:

Source Code:

<page contoller="org.bay.jspx.demo.live.Bean" >
	<html>
		<body>
			<form>
			<ajaxPanel>
					<table cellspacing="20px;"  class="demotext">
						<tr>
							<td>
							<table>
								<tr>
									<td> Username: </td>
									<td>
									<input type="text" id="username"  value="${customer.username}" />
									</td>
								</tr>
								<tr>
									<td> Password: </td>
									<td>
									<input type="password" id="password" value="${customer.password}"/>
									</td>
								</tr>
								<tr>
									<td> Mobile: </td>
									<td>
									<input type="text" id="mobile" value="${customer.mobile}"/>
									</td>
								</tr>
								<tr>
									<td> email: </td>
									<td>
									<input type="text" id="email" value="${customer.email}"/>
									</td>
								</tr>
								<tr>
									<td> Birthdate: </td>
									<td>
									<calendar id="birthdate" title="birth date" value="${customer.birthdate}"/>
									</td>
								</tr>
								<tr>
									<td> Martial Status: </td>
									<td>
									<select id="mstatus" value="${customer.mstatus}">
										<option value=""> -----</option>
										<option value="Single"> Single </option>
										<option value="Married"> Married </option>
										<option value="Divorced"> Divorced </option>
										<option value="In relationship"> In relationship </option>
									</select>
									</td>
								</tr>
								<tr>
									<td colspan="2" align="right">
									<input type="button" onserverclick="printUser" value="save" 
									submitonce="true"/>
									</td>
								</tr>
							</table>
							</td>
							<td valign="top">
							<table id="userData" rendered="false">
								<tr>
									<td> Username: </td>
									<td> ${customer.username} </td>
								</tr>
								<tr>
									<td> Password: </td>
									<td> ${customer.password} </td>
								</tr>
								<tr>
									<td> Mobile: </td>
									<td> ${customer.Mobile} </td>
								</tr>
								<tr>
									<td> email: </td>
									<td> ${customer.email} </td>
								</tr>
								<tr>
									<td> Birthdate: </td>
									<td> ${customer.birthdate} </td>
								</tr>
								<tr>
									<td> Martial Status: </td>
									<td> ${customer.mstatus} </td>
								</tr>
							</table></td>
						</tr>
					</table>
				</ajaxPanel>
			</form>
		</body>
	</html>
</page>
		
				

package org.bay.jspx.demo.live;

import org.bay.jspx.demo.live.model.Customer;

import eg.java.net.web.jspx.engine.annotation.JspxBean;
import eg.java.net.web.jspx.ui.pages.ContentPage;

/**
 * @author Amr.ElAdawy
 * Apr 3, 2012 12:01:19 PM
 */
public class Bean extends ContentPage
{

	@JspxBean(name = "customer")
	Customer customer = new Customer();
	@JspxWebControl
	GenericWebControl userData;

	public void printUser(WebControl sender, String args)
	{
		userData.setRendered(true);
	}
}

				

package org.bay.jspx.demo.live.model;

import java.util.Date;

/**
 * Model for Customer
 * @author amr.eladawy
 * May 16, 2012 6:10:39 PM
 */
public class Customer
{
	String username;
	String password;
	String email;
	Date birthdate;
	String mstatus;
	String mobile;

	public String getUsername()
	{
		return username;
	}

	public void setUsername(String username)
	{
		this.username = username;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public String getEmail()
	{
		return email;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}

	public Date getBirthdate()
	{
		return birthdate;
	}

	public void setBirthdate(Date birthdate)
	{
		this.birthdate = birthdate;
	}

	public String getMstatus()
	{
		return mstatus;
	}

	public void setMstatus(String mstatus)
	{
		this.mstatus = mstatus;
	}

	public String getMobile()
	{
		return mobile;
	}

	public void setMobile(String mobile)
	{
		this.mobile = mobile;
	}

}