The last beans we will add to our Projects are the CustomerView and ItemView which act as a vehicle between the JSF view and the Managed Beans.
java ee 6 tutorial

package view;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.validation.constraints.*;

@ManagedBean(name="customerView")
@RequestScoped
public class CustomerView {
 @Size(min = 5, max=20, message = "Please enter a valid Customer name (5-20 characters)")
 @NotNull(message = "Please enter a Customer name")
 private String customerName;
 
 @Size(min = 5, max=20, message = "Please enter a valid Country (5-20 characters)")
 @NotNull(message = "Please enter a Country")
 private String customerCountry;
 
 private int customerId;
 
 public void customerListener(AjaxBehaviorEvent event) { 
   this.customerName = this.customerName.toUpperCase();
 }
 public void countryListener(AjaxBehaviorEvent event) { 
   this.customerCountry = this.customerCountry.toUpperCase();
 } 
 // Getters / Setters methods here
 
 }

 

package view;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.validation.constraints.*;

@ManagedBean(name="itemView")
 
@RequestScoped
public class ItemView {
 @Min(value=0, message = "Order minimum 1 item") 
 @Max(value=1000, message = "Order maximum 1000 items") 
 private int orderQuantity;
 @Min(value=0, message = "Price cannot be less then 1") 
 private int orderPrice;
 @Size(min = 5, max=20, message = "Please enter a valid Product name (5-20 characters)")
 private String orderProduct;
 
 public void productListener(AjaxBehaviorEvent event) { 
   this.orderProduct = this.orderProduct.toUpperCase();
 } 

 // Getters / Setters methods here
 
}

Things to notice:
Both Beans use JSR 303 - bean validation, part of Java EE 6, which provides a mechanism to define data validation constraints in a way that is independent of the application tier.

 @Size(min = 5, max=20, message = "Please enter a valid Customer name (5-20 characters)")
 @NotNull(message = "Please enter a Customer name")
 private String customerName;

Both beans also use an AJAX listener which is triggered from the view pages when the user moves on to another field (onblur event).
The AJAX listener simply turns the text field into its uppercase equivalent.

 public void customerListener(AjaxBehaviorEvent event) { 
 this.customerName = this.customerName.toUpperCase();
 }     
0
0
0
s2smodern