It works but the output is broken :)

This commit is contained in:
2024-03-21 17:08:36 -05:00
parent 39b0da17b9
commit 118d95a69d
219 changed files with 7927 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package asdv.ajaxreview;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
/**
* Configures Jakarta RESTful Web Services for the application.
* @author Juneau
*/
@ApplicationPath("resources")
public class JakartaRestConfiguration extends Application {
}

View File

@@ -0,0 +1,20 @@
package asdv.ajaxreview.resources;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
/**
*
* @author
*/
@Path("jakartaee10")
public class JakartaEE10Resource {
@GET
public Response ping(){
return Response
.ok("ping Jakarta EE")
.build();
}
}

View File

@@ -0,0 +1,40 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template
*/
package beans;
import jakarta.inject.Named;
import jakarta.enterprise.context.RequestScoped;
/**
*
* @author asdv5
*/
@Named(value = "ajax1")
@RequestScoped
public class Ajax1
{
private String input1;
private String input2;
public String getInput1()
{
return input1;
}
public void setInput1(String input1)
{
this.input1 = input1;
}
public String getInput2()
{
return input2;
}
public void setInput2(String input2)
{
this.input2 = input2;
}
}

View File

@@ -0,0 +1,78 @@
package beans;
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.application.FacesMessage;
import jakarta.inject.Named;
import utilities.Utilities;
@Named(value = "ajax2")
@RequestScoped
public class Ajax2
{
private String farheneitTemperature;
private String celciusTemperature = "default value";
private String testInput;
private String miles;
public Ajax2()
{
System.out.println("-----------------------------------------constructor Ajax2()");
}
public String getTestInput()
{
return this.testInput;
}
public void setTestInput( String testInput)
{
System.out.println("testInput setter called");
this.testInput = testInput;
}
public String getMiles()
{
return miles;
}
public void setMiles(String miles)
{
System.out.println("miles: " + miles);
this.miles = miles;
}
public String milesToKilometers()
{
if ( this.miles == null )
return null;
double miles = Double.parseDouble( this.miles );
double km = miles * 1.65;
return String.valueOf(km);
}
public String getFarheneitTemperature(){return farheneitTemperature;}
public void setFarheneitTemperature(String farheneitTemperature)
{
System.out.println("setFarheneitTemperature: " + farheneitTemperature);
this.farheneitTemperature = farheneitTemperature;
this.celciusTemperature = convertFtoC();
Utilities.addMessage(FacesMessage.SEVERITY_INFO, farheneitTemperature, celciusTemperature);
}
public String getCelciusTemperature(){
return celciusTemperature;}
private String convertFtoC()
{
double f = Double.parseDouble( this.farheneitTemperature );
double c = (f - 32) * ( 5.0 / 9.0);
System.out.println("far: " + this.farheneitTemperature);
System.out.println("convert " + c);
celciusTemperature = String.valueOf(c);
return celciusTemperature;
}
}

View File

@@ -0,0 +1,73 @@
package beans;
import java.util.logging.Level;
import java.util.logging.Logger;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
@Named(value = "ajax3")
@RequestScoped
public class Ajax3
{
private static final Logger logger
= Logger.getLogger(Ajax3.class.getName());
private String firstName = "default";
private String lastName;
private String phone;
private String age;
private String address;
public Ajax3()
{
logger.log(Level.INFO, "Ajax3 constructor called" );
}
public String getFirstName()
{
return firstName;
}
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public String getLastName()
{
return lastName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public String getAge()
{
return age;
}
public void setAge(String age)
{
this.age = age;
}
public String getAddress()
{
return address;
}
public void setAddress(String address)
{
this.address = address;
}
public void ajaxAction(String executeNrender)
{
System.out.println(executeNrender);
logger.log(Level.INFO, "First Name = {0}", this.firstName);
logger.log(Level.INFO, "Last Name = {0}", this.lastName);
logger.log(Level.INFO, "Phone = {0}", this.phone);
logger.log(Level.INFO, "Age = {0}", this.age);
logger.log(Level.INFO, "Address = {0}", this.address);
System.out.println("--------------------------------------");
}
}

View File

@@ -0,0 +1,73 @@
package beans;
import jakarta.inject.Named;
import jakarta.enterprise.context.SessionScoped;
import java.io.Serializable;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.event.AbortProcessingException;
import jakarta.faces.event.AjaxBehaviorEvent;
import utilities.Utilities;
@Named(value = "ajax5")
@SessionScoped
public class Ajax5 implements Serializable
{
private boolean buttonRed = false;
private String input;
public void mouseOverListener(AjaxBehaviorEvent event)
throws AbortProcessingException
{
System.out.println("mouseOverListener");
setButtonRed(true);
Utilities.addMessage(FacesMessage.SEVERITY_INFO, "mouseOverListener", "red = true, input=" + input);
}
public void mouseOutListener(AjaxBehaviorEvent event)
throws AbortProcessingException
{
System.out.println("mouseOutListener");
setButtonRed(false);
Utilities.addMessage(FacesMessage.SEVERITY_INFO, "mouseOutListener", "red = false, input=" + input);
}
public String getInput()
{
return input;
}
public void setInput(String input)
{
this.input = input;
}
public boolean isButtonRed()
{
return buttonRed;
}
public void setButtonRed(boolean buttonRed)
{
this.buttonRed = buttonRed;
}
public void actionMethod()
{
Utilities.addMessage(FacesMessage.SEVERITY_INFO, "actionMethod()", "input=" + input);
}
}

View File

@@ -0,0 +1,44 @@
package beans;
import jakarta.inject.Named;
import jakarta.enterprise.context.SessionScoped;
import java.io.Serializable;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.event.AbortProcessingException;
import jakarta.faces.event.AjaxBehaviorEvent;
import utilities.Utilities;
/**
*
* @author ASDV2
*/
@Named(value = "ajax6")
@SessionScoped
public class Ajax6 implements Serializable
{
private int brand = 0;
public int getBrand()
{
return brand;
}
public void setBrand(int brand)
{
this.brand = brand;
}
public void clickListener(AjaxBehaviorEvent event)
throws AbortProcessingException
{
Utilities.addMessage(FacesMessage.SEVERITY_INFO, "clickListener", "brand= "+ brand);
}
public void changeListener(AjaxBehaviorEvent event)
throws AbortProcessingException
{
Utilities.addMessage(FacesMessage.SEVERITY_INFO, "changeListener", "brand= "+ brand);
}
}

View File

@@ -0,0 +1,60 @@
package beans;
import jakarta.enterprise.context.RequestScoped;
import jakarta.faces.application.FacesMessage;
import jakarta.inject.Named;
import utilities.Utilities;
@Named(value = "ajax7")
@RequestScoped
public class Ajax7
{
private String farheneitTemperature;
private String celciusTemperature;
private String miles;
public String getMiles()
{
return miles;
}
public void setMiles(String miles)
{
this.miles = miles;
}
public String milesToKilometers()
{
if ( this.miles == null || "".equals(miles) )
return null;
double miles = Double.parseDouble( this.miles );
double km = miles * 1.65;
return String.valueOf(km);
}
public String getFarheneitTemperature(){return farheneitTemperature;}
public void setFarheneitTemperature(String farheneitTemperature)
{
this.farheneitTemperature = farheneitTemperature;
this.celciusTemperature = convertFtoC();
Utilities.addMessage(FacesMessage.SEVERITY_INFO, farheneitTemperature, celciusTemperature);
}
public String getCelciusTemperature(){
return celciusTemperature;}
private String convertFtoC()
{
if ( "".equals(this.farheneitTemperature ) ||farheneitTemperature == null )
return "";
double f = Double.parseDouble( this.farheneitTemperature );
double c = (f - 32) * ( 5.0 / 9.0);
celciusTemperature = String.valueOf(c);
return celciusTemperature;
}
}

View File

@@ -0,0 +1,47 @@
package utilities;
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
/**
*
* @author asdv5
*/
public class Utilities
{
public static String simpleDateFormat( Date date)
{
if ( date == null )
return null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm");
String s = sdf.format( date);
return s;
}
public static void addMessage(FacesMessage.Severity severity, String summary, String detail)
{
FacesMessage msg = new FacesMessage(severity, summary, detail);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public static void clearAllMessages()
{
FacesContext context = FacesContext.getCurrentInstance();
Iterator<FacesMessage> it = context.getMessages();
while (it.hasNext())
{
it.next();
it.remove();
}
}
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="3.0" xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">
<!-- Define Persistence Unit -->
<persistence-unit name="my_persistence_unit">
</persistence-unit>
</persistence>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
bean-discovery-mode="all">
</beans>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="6.0" xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd">
<context-param>
<param-name>jakarta.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>jakarta.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<mime-mapping>
<extension>eot</extension>
<mime-type>application/vnd.ms-fontobject</mime-type>
</mime-mapping>
<mime-mapping>
<extension>otf</extension>
<mime-type>font/opentype</mime-type>
</mime-mapping>
<mime-mapping>
<extension>ttf</extension>
<mime-type>application/x-font-ttf</mime-type>
</mime-mapping>
<mime-mapping>
<extension>woff</extension>
<mime-type>application/x-font-woff</mime-type>
</mime-mapping>
<mime-mapping>
<extension>woff2</extension>
<mime-type>application/x-font-woff2</mime-type>
</mime-mapping>
<mime-mapping>
<extension>svg</extension>
<mime-type>image/svg+xml</mime-type>
</mime-mapping>
</web-app>

View File

@@ -0,0 +1,37 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="jakarta.faces.html"
xmlns:f="jakarta.faces.core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>ajax1</title>
</h:head>
<h:body>
<h3> Ajax tag embedded</h3>
<h4> On event keyup we execute/process this and we render one ID</h4>
<h:form>
<p:panelGrid columns="2" style="width: 50%">
<h:inputText id="inputName1"
value="#{ajax1.input1}">
<f:ajax event="keyup" execute="@this"
render="id_out1"
/>
</h:inputText>
<h:outputText id="id_out1" value="#{ajax1.input1}" />
<p:inputText id="inputName2"
value="#{ajax1.input2}">
<p:ajax event="keyup" process="@this"
update="id_out2"
/>
</p:inputText>
<p:outputLabel id="id_out2" value="#{ajax1.input2}" />
</p:panelGrid>
</h:form>
</h:body>
</html>

View File

@@ -0,0 +1,95 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>ajax2</title>
</h:head>
<h:body>
<h3> Ajax tag embedded -- Temperature Converter</h3>
<h4> event keyup reg-ex validation and multi-render with nested IDs. No need to specify IDs of parents</h4>
1. The Ajax2 constructor is called once, even though we have 2 h:forms, upon rendering. ( see Glassfish Log and line 20 of Ajax2.java)
<br/><br/>
2. Upon entering numbers in h:form id="idForm1" at LINE 34, we execute the inputText and we render all
ids that exits within h:form id="idForm1". We cannot render IDs outside this form.
We CANNOT render outPutText id_nested_cField2
<br/><br/>
3. Upon entering numbers in h:form id="idForm2" at LINE 51, we execute the inputText and we render all
ids that exists within h:form id="idForm2".
We CAN render outputText id_nested_cField2 becuase it is in within the form idForm2.
<br/><br/>
4. Upon every number typed in inputText id="id_in1" of form id="idForm1"
the constructor of the bean is called , then its setter. The output to celcius and the grown are called when we render.
<br/><br/>
5. The nested ID= id_nested_cField2 can be accessed only from with form
id="idForm2"
<br/><br/>
6. The command button of id=id_cm2 only updates the upper form with id="idForm1", because it has ajax=true
while the command button id=id_cm2 updates both upper and lpwer form forms
<h:form id="idForm1" >
<p:growl id="id_growl1" showDetail="true" showSummary="true"
life="4000"
redisplay="false"/>
<h:inputText id="id_in1" value="#{ajax2.farheneitTemperature}">
<f:ajax event="keyup" execute="@this"
render="cField1
id_nested_cField2
id_growl1" />
<f:validateRegex pattern = "[-+]?[0-9]*\.?[0-9]"/>
</h:inputText><br/>
<h:outputText value="Temperature in Celsius: #{ajax2.celciusTemperature}"
id="cField3"/>
<br/>
<p:commandButton id="id_cm1" ajax="true" value="send only this form because ajax=true" update="id_growl1"/>
</h:form>
<h:form id="idForm2" >
<p:growl id="id_growl2" showDetail="true" showSummary="true"
life="4000"
redisplay="false"/>
<p:panelGrid id="pg1" style="width: 100%" >
<p:column style="width: 100%">
<p:panelGrid id="pg2">
<p:column><h2> nested Ids</h2> </p:column>
<p:column>
<h2>
<h:outputText value="#{ajax2.celciusTemperature}"
id="id_nested_cField2"/>
</h2>
</p:column>
</p:panelGrid>
</p:column>
</p:panelGrid>
<br/>
<h:inputText value="#{ajax2.farheneitTemperature}">
<f:ajax event="keyup" execute="@this"
render="cField1
id_nested_cField2
d_growl2" />
<f:validateRegex pattern = "[-+]?[0-9]*\.?[0-9]"/>
</h:inputText><br/>
<h2>
Temperature in Celsius:
<h:outputText value="#{ajax2.celciusTemperature}"
id="cField1"/>
</h2>
<p:commandButton id="id_cm2" ajax="false" value="send all forms becuase ajax=false" update="id_growl"/>
</h:form>
</h:body>
</html>

View File

@@ -0,0 +1,126 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>ajax3</title>
</h:head>
<h:body>
1. constructor of ajax3 bean called once upon rending
<br/> <br/>
2. Test all cases one by one and see the outputs
<hr/>
AJAX - execute=form a render=@form
<h:form>
First Name <h:inputText value="#{ajax3.firstName}"/>
Last Name <h:inputText value="#{ajax3.lastName}"/>
Phone: <h:inputText value="#{ajax3.phone}"/>
Age: <h:inputText value="#{ajax3.age}"/>
Address: <h:inputText value="#{ajax3.address}"/>
<h:commandButton value="Say Hello" action='#{ajax3.ajaxAction("execute=form a render=@form")}'>
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
<h:panelGrid columns="6">
<h:outputText style="font-weight: bold;" value="@form"/>
<h:outputText style="color:red;" value="First Name: #{ajax3.firstName}"/>
<h:outputText style="color:blue;" value="Last Name: #{ajax3.lastName}"/>
<h:outputText style="color:green;" value="Phone: #{ajax3.phone}"/>
<h:outputText style="color:brown;" value="Age: #{ajax3.age}"/>
<h:outputText style="color: blueviolet" value="Address: #{ajax3.address}"/>
</h:panelGrid>
</h:form>
<br/>
<hr/>
AJAX - execute=@none , render=@form
<h:form>
First Name: <h:inputText value="#{ajax3.firstName}"/>
Last Name: <h:inputText value="#{ajax3.lastName}"/>
Phone: <h:inputText value="#{ajax3.phone}"/>
Age: <h:inputText value="#{ajax3.age}"/>
Address: <h:inputText value="#{ajax3.address}"/>
<h:commandButton value="Say Hello" action="#{ajax3.ajaxAction('execute=@none render=@form')}">
<f:ajax execute="@none" render="@form"/>
</h:commandButton>
<h:panelGrid columns="6">
<h:outputText style="font-weight: bold;" value="@form"/>
<h:outputText style="color:red;" value="First Name: #{ajax3.firstName}"/>
<h:outputText style="color:blue;" value="Last Name: #{ajax3.lastName}"/>
<h:outputText style="color:green;" value="Phone: #{ajax3.phone}"/>
<h:outputText style="color:brown;" value="Age: #{ajax3.age}"/>
<h:outputText style="color: blueviolet" value="Address: #{ajax3.address}"/>
</h:panelGrid>
</h:form>
<br/>
<hr/>
AJAX - execute=@this render=@form
<h:form>
First Name <h:inputText value="#{ajax3.firstName}"/>
Last Name <h:inputText value="#{ajax3.lastName}"/>
Phone: <h:inputText value="#{ajax3.phone}"/>
Age: <h:inputText value="#{ajax3.age}"/>
Address: <h:inputText value="#{ajax3.address}"/>
<h:commandButton value="Say Hello" action='#{ajax3.ajaxAction("execute=@this render=@form")}'>
<f:ajax execute="@this" render="@form"/>
</h:commandButton>
<hr/>
<h:panelGrid columns="6">
<h:outputText style="font-weight: bold;" value="@this"/>
<h:outputText value="Name: #{ajax3.firstName}"/>
<h:outputText value="Surname: #{ajax3.lastName}"/>
<h:outputText value="Phone: #{ajax3.phone}"/>
<h:outputText value="Age: #{ajax3.age}"/>
<h:outputText value="Address: #{ajax3.address}"/>
</h:panelGrid>
</h:form>
<br/>
<hr/>
AJAX - identifiers
<h:form>
First Name <h:inputText value="#{ajax3.firstName}"/>
Last Name <h:inputText id="nameInputId" value="#{ajax3.lastName}"/>
Phone: <h:inputText id="phoneInputId" value="#{ajax3.phone}"/>
Age: <h:inputText value="#{ajax3.age}"/>
Address: <h:inputText id="addressInputId" value="#{ajax3.address}"/>
<h:commandButton value="Say Hello" action="#{ajax3.ajaxAction('identifiers')}">
<f:ajax execute="nameInputId phoneInputId addressInputId" render="nameOutputId phoneOutputId ageOutputId"/>
</h:commandButton>
<hr/>
<h:panelGrid columns="6">
<h:outputText style="font-weight: bold;" value="identifiers"/>
<h:outputText style="color:red;" value="First Name: #{ajax3.firstName}"/>
<h:outputText id="nameOutputId" style="color:blue;" value="Last Name: #{ajax3.lastName}"/>
<h:outputText id="phoneOutputId" style="color:green;" value="Phone: #{ajax3.phone}"/>
<h:outputText id="ageOutputId" style="color:brown;" value="Age: #{ajax3.age}"/>
<h:outputText style="color: blueviolet" value="Address: #{ajax3.address}"/>
</h:panelGrid>
</h:form>
<br/>
<hr/>
AJAX - execute=@all render=@all
<hr/>
<h:form>
First Name <h:inputText value="#{ajax3.firstName}"/>
Last Name <h:inputText value="#{ajax3.lastName}"/>
Phone: <h:inputText value="#{ajax3.phone}"/>
Age: <h:inputText value="#{ajax3.age}"/>
Address: <h:inputText value="#{ajax3.address}"/>
<h:commandButton value="Say Hello" action="#{ajax3.ajaxAction('execute=@all render=@all')}">
<f:ajax execute="@all" render="@all"/>
</h:commandButton>
<hr/>
<h:panelGrid columns="6">
<h:outputText style="font-weight: bold;" value="@all"/>
<h:outputText style="color:red;" value="First Name: #{ajax3.firstName}"/>
<h:outputText style="color:blue;" value="Last Name: #{ajax3.lastName}"/>
<h:outputText style="color:green;" value="Phone: #{ajax3.phone}"/>
<h:outputText style="color:brown;" value="Age: #{ajax3.age}"/>
<h:outputText style="color: blueviolet" value="Address: #{ajax3.address}"/>
</h:panelGrid>
</h:form>
</h:body>
</html>

View File

@@ -0,0 +1,123 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>ajax4</title>
</h:head>
<h:body>
<hr/>
AJAX - process=form a update=@form
<h:form>
First Name <p:inputText style="width: 80px;" value="#{ajax3.firstName}"/>
Last Name <p:inputText style="width: 80px;" value="#{ajax3.lastName}"/>
Phone: <p:inputText style="width: 80px;" value="#{ajax3.phone}"/>
Age: <p:inputText style="width: 80px;" value="#{ajax3.age}"/>
Address: <p:inputText style="width: 80px;" value="#{ajax3.address}"/>
<p:commandButton value="Say Hello" action='#{ajax3.ajaxAction("process=form a update=@form")}'>
<p:ajax process="@form" update="@form"/>
</p:commandButton>
<p:panelGrid columns="6">
<p:outputLabel style="font-weight: bold;" value="@form"/>
<p:outputLabel style="color:red;" value="First Name: #{ajax3.firstName}"/>
<p:outputLabel style="color:blue;" value="Last Name: #{ajax3.lastName}"/>
<p:outputLabel style="color:green;" value="Phone: #{ajax3.phone}"/>
<p:outputLabel style="color:brown;" value="Age: #{ajax3.age}"/>
<p:outputLabel style="color: blueviolet" value="Address: #{ajax3.address}"/>
</p:panelGrid>
</h:form>
<br/>
<hr/>
AJAX - process=@none , update=@form
<h:form>
First Name: <p:inputText value="#{ajax3.firstName}"/>
Last Name: <p:inputText value="#{ajax3.lastName}"/>
Phone: <p:inputText value="#{ajax3.phone}"/>
Age: <p:inputText value="#{ajax3.age}"/>
Address: <p:inputText value="#{ajax3.address}"/>
<p:commandButton value="Say Hello" action="#{ajax3.ajaxAction('process=@none update=@form')}">
<p:ajax process="@none" update="@form"/>
</p:commandButton>
<p:panelGrid columns="6">
<h:outputLabel style="font-weight: bold;" value="@form"/>
<h:outputLabel style="color:red;" value="First Name: #{ajax3.firstName}"/>
<h:outputLabel style="color:blue;" value="Last Name: #{ajax3.lastName}"/>
<h:outputLabel style="color:green;" value="Phone: #{ajax3.phone}"/>
<h:outputLabel style="color:brown;" value="Age: #{ajax3.age}"/>
<h:outputLabel style="color: blueviolet" value="Address: #{ajax3.address}"/>
</p:panelGrid>
</h:form>
<br/>
<hr/>
AJAX - process=@this update=@form
<h:form>
First Name <p:inputText value="#{ajax3.firstName}"/>
Last Name <p:inputText value="#{ajax3.lastName}"/>
Phone: <p:inputText value="#{ajax3.phone}"/>
Age: <p:inputText value="#{ajax3.age}"/>
Address: <p:inputText value="#{ajax3.address}"/>
<p:commandButton value="Say Hello" action='#{ajax3.ajaxAction("process=@this update=@form")}'>
<p:ajax process="@this" update="@form"/>
</p:commandButton>
<hr/>
<h:panelGrid columns="6">
<h:outputLabel style="font-weight: bold;" value="@this"/>
<h:outputLabel value="Name: #{ajax3.firstName}"/>
<h:outputLabel value="Surname: #{ajax3.lastName}"/>
<h:outputLabel value="Phone: #{ajax3.phone}"/>
<h:outputLabel value="Age: #{ajax3.age}"/>
<h:outputLabel value="Address: #{ajax3.address}"/>
</h:panelGrid>
</h:form>
<br/>
<hr/>
AJAX - identifiers
<h:form>
First Name <p:inputText value="#{ajax3.firstName}"/>
Last Name <p:inputText id="nameInputId" value="#{ajax3.lastName}"/>
Phone: <p:inputText id="phoneInputId" value="#{ajax3.phone}"/>
Age: <p:inputText value="#{ajax3.age}"/>
Address: <p:inputText id="addressInputId" value="#{ajax3.address}"/>
<p:commandButton value="Say Hello" action="#{ajax3.ajaxAction('identifiers')}">
<p:ajax process="nameInputId phoneInputId addressInputId" update="nameOutputId phoneOutputId ageOutputId"/>
</p:commandButton>
<hr/>
<h:panelGrid columns="6">
<h:outputLabel style="font-weight: bold;" value="identifiers"/>
<h:outputLabel style="color:red;" value="First Name: #{ajax3.firstName}"/>
<h:outputLabel id="nameOutputId" style="color:blue;" value="Last Name: #{ajax3.lastName}"/>
<h:outputLabel id="phoneOutputId" style="color:green;" value="Phone: #{ajax3.phone}"/>
<h:outputLabel id="ageOutputId" style="color:brown;" value="Age: #{ajax3.age}"/>
<h:outputLabel style="color: blueviolet" value="Address: #{ajax3.address}"/>
</h:panelGrid>
</h:form>
<br/>
<hr/>
AJAX - process=@all update=@all
<hr/>
<h:form>
First Name <p:inputText value="#{ajax3.firstName}"/>
Last Name <p:inputText value="#{ajax3.lastName}"/>
Phone: <p:inputText value="#{ajax3.phone}"/>
Age: <p:inputText value="#{ajax3.age}"/>
Address: <p:inputText value="#{ajax3.address}"/>
<p:commandButton value="Say Hello" action="#{ajax3.ajaxAction('process=@all update=@all')}">
<p:ajax process="@all" update="@all"/>
</p:commandButton>
<hr/>
<h:panelGrid columns="6">
<h:outputLabel style="font-weight: bold;" value="@all"/>
<h:outputLabel style="color:red;" value="First Name: #{ajax3.firstName}"/>
<h:outputLabel style="color:blue;" value="Last Name: #{ajax3.lastName}"/>
<h:outputLabel style="color:green;" value="Phone: #{ajax3.phone}"/>
<h:outputLabel style="color:brown;" value="Age: #{ajax3.age}"/>
<h:outputLabel style="color: blueviolet" value="Address: #{ajax3.address}"/>
</h:panelGrid>
</h:form>
</h:body>
</html>

View File

@@ -0,0 +1,36 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>ajax5</title>
</h:head>
<h:body >
1.When an Ajax event triggers in the button, then it calls its listener AND the action method
<br/><br/>
2. In Order to send the form you must use f:ajax execute="@form" render="@form", line 25
<br/><br/>
<h:form>
<p:growl id="id_growl" showDetail="true" showSummary="true"
life="2000"
redisplay="false"/>
<h:inputText value="#{ajax5.input}"/>
<br/>
<h:commandButton value="Send form"
style="#{ajax5.buttonRed?'background-color:red':'background-color:yellow'}"
action="#{ajax5.actionMethod()}">
<f:ajax execute="@form" render="@form" />
<f:ajax event="mouseover" execute="@this" render="@this id_growl"
listener="#{ajax5.mouseOverListener}" />
<f:ajax event="mouseout" execute="@this" render="@this id_growl"
listener="#{ajax5.mouseOutListener}" />
</h:commandButton>
</h:form >
</h:body>
</html>

View File

@@ -0,0 +1,42 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>ajax6</title>
</h:head>
<h:body>
<h3> Valid event names you may use : blur, change, click, dblclick, focus, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, mouseup, valueChange.</h3>
<br/>
1. When it makes sense you can add events as needed and listeners for them.
<br/> <br/>
<h:form>
<p:growl id="id_growl1" showDetail="true" showSummary="true"
life="2000"
redisplay="false"/>
<p:growl id="id_growl2" showDetail="true" showSummary="true"
life="6000"
redisplay="false"/>
<h:selectOneMenu value="#{ajax6.brand}" id="brandID" >
<f:ajax event="change" execute="@this" render=" id_growl2"
listener="#{ajax6.changeListener}" />
<f:ajax event="click" execute="@this" render=" id_growl1"
listener="#{ajax6.clickListener}" />
<f:selectItem itemLabel="Ford" itemValue="1" />
<f:selectItem itemLabel="Chevy" itemValue="2" />
<f:selectItem itemLabel="Fiat" itemValue="3" />
<f:selectItem itemLabel="Honda" itemValue="4" />
<f:selectItem itemLabel="Opel" itemValue="5" />
<f:selectItem itemLabel="VW" itemValue="6" />
</h:selectOneMenu>
</h:form >
</h:body>
</html>

View File

@@ -0,0 +1,53 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:f5="http://xmlns.jcp.org/jsf/passthrough">
<h:head>
<title>ajax7</title>
</h:head>
<h:body>
<h2>1. Ajax tag as Wrapper, the keyup applies to all wrapped in it </h2>
<h2>2. Both inputs are validated and executed </h2>
<h:form>
<p:growl id="id_growl" showDetail="true" showSummary="true"
life="2000"
redisplay="false"/>
<f:ajax event="keyup" execute="tempID milesID"
render="cField kField id_growl" >
<h:inputText id="tempID"
f5:placeholder="Temperature in Fahrenheit"
value="#{ajax7.farheneitTemperature}">
<f:validateRegex pattern = "[0-9]*"/>
</h:inputText>
<br/><br/>
<h:inputText id="milesID"
f5:placeholder="Miles"
value="#{ajax7.miles}">
<f:validateRegex pattern = "[0-9]*"/>
</h:inputText>
</f:ajax>
<h2>
Temperature in Celsius:
<h:outputText value="#{ajax7.celciusTemperature}"
id="cField"/>
</h2>
<h2>
Kilometers:
<h:outputText value="#{ajax7.milesToKilometers()}"
id="kField"/>
</h2>
<h:commandButton value="Send to Server 2 inputs"> </h:commandButton>
</h:form>
</h:body>
</html>

View File

@@ -0,0 +1,29 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Ajax in button</title>
</h:head>
<h:body>
<h:form>
<h:commandLink value="1. Ajax tag on event keyup one render" action="ajax1"/>
<br/><br/>
<h:commandLink value="2. Ajax tag on event keyup validation and multi-rendrer" action="ajax2"/>
<br/><br/>
<h:commandLink value="3. Ajax tag on command button -- all cases" action="ajax3"/>
<br/><br/>
<h:commandLink value="4. Ajax Primefaces tag on command button -- all cases" action="ajax4"/>
<br/><br/>
<h:commandLink value="5. Ajax tag one with multi-events multi-listeners" action="ajax5"/>
<br/><br/>
<h:commandLink value="6. Ajax tag select one menu" action="ajax6"/>
<br/><br/>
<h:commandLink value="7. Wrapper-Ajax tag on keyup" action="ajax7"/>
</h:form>
</h:body>
</html>