Ajax Smajax

This commit is contained in:
2024-01-23 13:22:06 -06:00
parent 1896014238
commit 4a115a4b42
180 changed files with 4784 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>10-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>gfv700ee10</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<org-netbeans-modules-projectapi.jsf_2e_language>Facelets</org-netbeans-modules-projectapi.jsf_2e_language>
<netbeans.hint.jdkPlatform>JDK_11__System_</netbeans.hint.jdkPlatform>
</properties>
</project-shared-configuration>

View File

@@ -0,0 +1,83 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>asdv</groupId>
<artifactId>Review_JSF</artifactId>
<version>1</version>
<packaging>war</packaging>
<name>Review_JSF-1</name>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<jakartaee>10.0.0</jakartaee>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>${jakartaee}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>13.0.2</version>
<classifier>jakarta</classifier>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>${jakartaee}</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,53 @@
/*
* 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 _01_ajax;
import jakarta.inject.Named;
import jakarta.enterprise.context.RequestScoped;
/**
*
* @author asdv5
*/
@Named(value = "ajaxBean")
@RequestScoped
public class AjaxBean
{
private String inputText1;
private String inputText2;
private String outputText1;
public String getOutputText1() {
return inputText1 + ", " + inputText2;
}
public String getInputText1() {
return inputText1;
}
public void setInputText1(String inputText1) {
this.inputText1 = inputText1;
}
public String getInputText2() {
return inputText2;
}
public void setInputText2(String inputText2) {
this.inputText2 = inputText2;
}
/**
* Creates a new instance of AjaxBean
*/
public AjaxBean()
{
}
}

View File

@@ -0,0 +1,29 @@
/*
* 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
*/
package _02_injection;
import java.util.ArrayList;
import java.util.Arrays;
/**
*
* @author caleb
*/
public class ForInjection {
private ArrayList<String> list =
new ArrayList(Arrays.asList(new String[] {"John", "Mary"}));
public ArrayList<String> getList()
{
return list;
}
public void setList(ArrayList<String> list)
{
this.list = list;
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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 _02_injection;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
/**
*
* @author caleb
*/
@Named(value="injectionBean")
@RequestScoped
public class InjectionBean {
@Inject
ForInjection fi;
/** Creates a new instance of InjectionBean */
public InjectionBean() {
}
public ForInjection getFi()
{
return fi;
}
public void setFi(ForInjection fi)
{
this.fi = fi;
}
}

View File

@@ -0,0 +1,20 @@
/*
* 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
*/
package _03_DAO_implementation_and_usage;
import java.sql.SQLException;
import java.util.List;
/**
*
* @author caleb
*/
public interface Dao<T> {
List<T> listAll() throws SQLException;
int insert(T t);
int delete(T t);
int update(T t);
int count();
}

View File

@@ -0,0 +1,31 @@
/*
* 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 _03_DAO_implementation_and_usage;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
/**
*
* @author caleb
*/
@Named(value="daoBean")
@RequestScoped
public class DaoBean {
private Dao dao;
public DaoBean()
{
dao = new DaoObjectManipulator();
}
public Dao getDao()
{
return dao;
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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
*/
package _03_DAO_implementation_and_usage;
import java.io.Serializable;
/**
*
* @author caleb
*/
public class DaoObject implements Serializable {
public DaoObject(int key1, String data1)
{
}
private int key1;
private String data1;
public String getData()
{
return data1;
}
public void setData(String data)
{
this.data1 = data;
}
public int getKey()
{
return key1;
}
public void setKey(int key)
{
this.key1 = key;
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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
*/
package _03_DAO_implementation_and_usage;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class DaoObjectManipulator implements Dao<DaoObject>, Serializable
{
@Override
public List<DaoObject> listAll()
throws SQLException
{
// test exception code
//if ( true)
// throw new SQLException();
List<DaoObject> tableDao = new ArrayList<DaoObject>();
String databaseName = "dao_test";
String userName = "java";
String password = "8VCS49HT2xjsEZvC";
String URL2 = "com.mysql.jdbc.Driver";
Connection con = new UtilitiesDatabase().connection(
databaseName, userName, password, URL2);
PreparedStatement ps = null;
try
{
if (con == null)
{
throw new RuntimeException("cannot connect to database");
}
String table = "";
ResultSet rs = null;
String sqlStr = "SELECT * FROM dao";
//prepare statement
ps = con.prepareStatement(sqlStr);
//execute
rs = ps.executeQuery();
int row = 0;
while (rs.next())
{
int key = rs.getInt(1);
String data = rs.getString(2);
DaoObject dao = new DaoObject(key, data);
tableDao.add(dao);
row++;
}
}
catch (SQLException ex)
{
ex.printStackTrace();
}
finally
{
try
{
new UtilitiesDatabase().closeDatabaseConnection(con);
// close the resources
if (ps != null)
{
ps.close();
}
}
catch (SQLException sqle)
{
System.out.println(sqle);
sqle.printStackTrace();
throw sqle;
}
}
return tableDao;
}
@Override
public int insert(DaoObject t)
{
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
@Override
public int delete(DaoObject t)
{
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
@Override
public int update(DaoObject t)
{
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
@Override
public int count()
{
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
}
}

View File

@@ -0,0 +1,96 @@
/*
* 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
*/
package _03_DAO_implementation_and_usage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
/**
*
* @author asdv5
*/
public class UtilitiesDatabase
{
public Connection connection(
String databaseName,
String userName,
String password,
String URL2
) //throws InstantiationException, IllegalAccessException
{
/*
String databaseName = "suppliers_parts_23";
String userName = "root";
String password = "root";
String URL2 = "com.mysql.jdbc.Driver";
Connection con = null;
*/
Connection con;
try
{// Load Sun's jdbc driver
Class.forName(URL2).newInstance();
System.out.println("JDBC Driver loaded!");
}
catch (Exception e) // driver not found
{
System.err.println("Unable to load database driver");
System.err.println("Details : " + e);
return null;
}
String ip = "localhost"; //internet connection
String url = "jdbc:mysql://" + ip + ":3306/" + databaseName + "?allowPublicKeyRetrieval=true&useSSL=false";
try
{
con = DriverManager.getConnection(url, userName, password);
con.setReadOnly(false);
}
catch (Exception e)
{
System.err.println(e.toString());
return null;
}
System.out.println("connection successfull");
return con;
}
public void closeDatabaseConnection( Connection con)
{
try
{
if (con != null)
{
con.close();
}
}
catch (SQLException e)
{
System.out.println(e);
e.printStackTrace();
}
}
public static java.sql.Date stringDateToSqlDate(String sDate)
{
java.util.Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try
{
date = sdf.parse(sDate);
}
catch (ParseException e)
{
e.printStackTrace();
}
return new java.sql.Date( date.getTime() );
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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
*/
package _03_DAO_implementation_and_usage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
/**
*
* @author asdv5
*/
public class UtilitiesDatabase
{
public Connection connection(
String databaseName,
String userName,
String password,
String URL2
) //throws InstantiationException, IllegalAccessException
{
/*
String databaseName = "suppliers_parts_23";
String userName = "root";
String password = "root";
String URL2 = "com.mysql.jdbc.Driver";
Connection con = null;
*/
Connection con;
try
{// Load Sun's jdbc driver
Class.forName(URL2).newInstance();
System.out.println("JDBC Driver loaded!");
}
catch (Exception e) // driver not found
{
System.err.println("Unable to load database driver");
System.err.println("Details : " + e);
return null;
}
String ip = "localhost"; //internet connection
String url = "jdbc:mysql://" + ip + ":3306/" + databaseName + "?allowPublicKeyRetrieval=true&useSSL=false";
try
{
con = DriverManager.getConnection(url, userName, password);
con.setReadOnly(false);
}
catch (Exception e)
{
System.err.println(e.toString());
return null;
}
System.out.println("connection successfull");
return con;
}
public void closeDatabaseConnection( Connection con)
{
try
{
if (con != null)
{
con.close();
}
}
catch (SQLException e)
{
System.out.println(e);
e.printStackTrace();
}
}
public static java.sql.Date stringDateToSqlDate(String sDate)
{
java.util.Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try
{
date = sdf.parse(sDate);
}
catch (ParseException e)
{
e.printStackTrace();
}
return new java.sql.Date( date.getTime() );
}
public static java.util.Date stringDateToJavaUtilitiesDate(String sDate)
{
java.sql.Date sqldate = stringDateToSqlDate(sDate);
return new java.util.Date(sqldate.getTime() );
}
}

View File

@@ -0,0 +1,20 @@
package asdv.review_jsf.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,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,24 @@
<?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>
</web-app>

View File

@@ -0,0 +1,109 @@
<?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>Facelet Title</title>
</h:head>
<h:body>
<h:form id="id_form1">
<h3>1 AJAX tag embedded</h3>
<h:inputText value="#{ajaxBean.inputText1}"/>
<br/>
<h:inputText value="#{ajaxBean.inputText2}">
<f:ajax event="keyup" execute="@this" render="id_form1:id_1 id_form1:id_2"/>
</h:inputText>
<br/>
<h:outputLabel id="id_1" value="#{ajaxBean.outputText1}"></h:outputLabel>
<br/>
<h:outputLabel id="id_2" value="#{ajaxBean.outputText1}"></h:outputLabel>
</h:form>
<h:form>
<h3>2 Class injection</h3>
<p:dataTable var="x" value="#{injectionBean.fi.getList()}">
<p:column>
#{x.toString()}
</p:column>
</p:dataTable>
</h:form>
<h:form>
<h3>3 DAO</h3>
#{daoBean.dao.listAll()}
</h:form>
<h:form>
<h:commandLink value="4 Custom Conversions" action="index"/>
</h:form>
<h:form>
<h:commandLink value="5 Custom Validations" action="index"/>
</h:form>
<h:form>
<h:commandLink value="6 DataTable - Primefaces pagination and its value-variable" action="index"/>
</h:form>
<h:form>
<h:commandLink value="7 DataTable - passing a parameter value to the bean" action="index"/>
</h:form>
<h:form>
<h:commandLink value="8 Action Listeners" action="index"/>
</h:form>
<h:form>
<h:commandLink value="9 Value Change Listeners" action="index"/>
</h:form>
<h:form>
<h:commandLink value="10 Dynamic select-one, select many" action="index"/>
</h:form>
<h:form>
<h:commandLink value="11 navigation via navigation rules" action="index"/>
</h:form>
<h:form>
<h:commandLink value="12 Messages JSF via FacesContex" action="index"/>
</h:form>
<h:form>
<h:commandLink value="13 Messsages Primefaces p:growl via FacesContex " action="index"/>
</h:form>
<h:form>
<h:commandLink value="14 catch exception in CDI bean - record exception in server and display p:grow message " action="index"/>
</h:form>
<h:form>
<h:commandLink value="15 handle_exception_before_rendering " action="index"/>
</h:form>
<h:form>
<h:commandLink value="16 calling javascipt methods form JSF" action="index"/>
</h:form>
<h:form>
<h:commandLink value="17 using CSS files in JSF" action="index"/>
</h:form>
<h:form>
<h:commandLink value="18 rendered attibute in connection to CDI Bean" action="index"/>
</h:form>
<h:form>
<h:commandLink value="19 EL -- arraylists, sets, maps" action="index"/>
</h:form>
<h:form>
<h:commandLink value="20 EL -- functions" action="index"/>
</h:form>
</h:body>
</html>