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;
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.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,58 @@
package beans;
import jakarta.enterprise.context.RequestScoped;
import java.util.Map;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Named;
import utilities.UtilitiesDatabase;
@Named(value = "clientBean")
@RequestScoped
public class ClientBean
{
private String fromCallerUrlOfParent;
private String fromCallerStockId;
private Map<String, String> map;
public Map<String, String> getMap()
{
return map;
}
public ClientBean()
{
getParametersFromCaller();
}
private void getParametersFromCaller()
{
//> Get parameters from caller
Map<String, String> m = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
this.fromCallerUrlOfParent = m.get("url_of_parent_param1");
this.fromCallerStockId = m.get("stock_id_param2");
UtilitiesDatabase.addMessage(FacesMessage.SEVERITY_INFO, "mouseOutListener", "");
map = m;
}
public String getFromCallerUrlOfParent()
{
return fromCallerUrlOfParent;
}
public String getFromCallerStockId()
{
return fromCallerStockId;
}
public void getRequestFromMap() {
map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
}
}

View File

@@ -0,0 +1,61 @@
/*
* 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 bl.DataFromDatabase;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.SessionScoped;
import jakarta.faces.application.ConfigurableNavigationHandler;
import jakarta.faces.context.ExternalContext;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import java.io.Serializable;
import java.util.List;
import org.primefaces.event.SelectEvent;
import pojos.Stock;
/**
*
* @author asdv5
*/
@Named(value = "stockBean")
@SessionScoped
public class StockBean implements Serializable
{
@Inject
DataFromDatabase dbData;
List<Stock> stocks;
@PostConstruct
void init()
{
stocks = dbData.getList();
}
public List<Stock> getStocks()
{
return stocks;
}
public void setStocks(List<Stock> stocks)
{
this.stocks = stocks;
}
public void onRowSelect(SelectEvent event)
{
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
Stock a = (Stock) event.getObject();
String page = "client-page";
String params = "&url_of_parent_param1=" + "index";
params += "&stock_id_param2=" + a.getStockId();
ConfigurableNavigationHandler handler = (ConfigurableNavigationHandler) fc.getApplication().getNavigationHandler();
handler.performNavigation(page + "?faces-redirect=true" + params);
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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 bl;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import pojos.Stock;
/**
*
* @author asdv5
*/
public class DataFromDatabase implements Serializable
{
private List<Stock> list = new ArrayList<>();
public DataFromDatabase()
{
for (int i = 1; i <= 100; ++i)
{
String stockId = "stockID" + i;
String companyName = "stockID" + i;
double priceCurrent = Math.random() * 1000;
double priceClosing = priceCurrent + Math.random() * 10;
long numberOfSharesAvailable = (long) (Math.random() * 10000000);
long numberOfSharesSold = numberOfSharesAvailable / 3;
list.add(new Stock(stockId, companyName, priceCurrent, priceClosing, numberOfSharesAvailable, numberOfSharesSold));
}
}
public List<Stock> getList()
{
return list;
}
}

View File

@@ -0,0 +1,138 @@
/*
* 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 pojos;
import java.io.Serializable;
public class Stock implements Serializable
{
private static final long serialVersionUID = 1L;
private String stockId;
private String companyName;
private double priceCurrent;
private double priceClosing;
private long numberOfSharesAvailable;
private long numberOfSharesSold;
public Stock()
{
}
public Stock(String stockId)
{
this.stockId = stockId;
}
public Stock(String stockId, String companyName, double priceCurrent, double priceClosing, long numberOfSharesAvailable, long numberOfSharesSold)
{
this.stockId = stockId;
this.companyName = companyName;
this.priceCurrent = priceCurrent;
this.priceClosing = priceClosing;
this.numberOfSharesAvailable = numberOfSharesAvailable;
this.numberOfSharesSold = numberOfSharesSold;
}
public String getStockId()
{
return stockId;
}
public void setStockId(String stockId)
{
this.stockId = stockId;
}
public String getCompanyName()
{
return companyName;
}
public void setCompanyName(String companyName)
{
this.companyName = companyName;
}
public double getPriceCurrent()
{
return priceCurrent;
}
public void setPriceCurrent(double priceCurrent)
{
this.priceCurrent = priceCurrent;
}
public double getPriceClosing()
{
return priceClosing;
}
public void setPriceClosing(double priceClosing)
{
this.priceClosing = priceClosing;
}
public long getNumberOfSharesAvailable()
{
return numberOfSharesAvailable;
}
public void setNumberOfSharesAvailable(long numberOfSharesAvailable)
{
this.numberOfSharesAvailable = numberOfSharesAvailable;
}
public long getNumberOfSharesSold()
{
return numberOfSharesSold;
}
public void setNumberOfSharesSold(long numberOfSharesSold)
{
this.numberOfSharesSold = numberOfSharesSold;
}
@Override
public int hashCode()
{
int hash = 0;
hash += (stockId != null ? stockId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object)
{
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Stock))
{
return false;
}
Stock other = (Stock) object;
if ((this.stockId == null && other.stockId != null) || (this.stockId != null && !this.stockId.equals(other.stockId)))
{
return false;
}
return true;
}
@Override
public String toString()
{
return "asdv.mp1_ajax.entities.Stock[ stockId=" + stockId + " ]";
}
}

View File

@@ -0,0 +1,111 @@
/*
* 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 utilities;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Iterator;
public class UtilitiesDatabase
{
public Connection connection(
String databaseName,
String userName,
String password,
String URL2
) throws SQLException, InstantiationException,
IllegalAccessException, ClassNotFoundException
{
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);
throw e;
}
String ip = "localhost"; //internet connection
String url = "jdbc:mysql://" + ip + ":8889/" + databaseName + "?useSSL=false";
try
{
con = DriverManager.getConnection(url, userName, password);
con.setReadOnly(false);
}
catch (Exception e)
{
System.err.println(e.toString());
throw e;
}
System.out.println("connection successfull");
return con;
}
public void closeDatabaseConnection(Connection con)
throws SQLException
{
try
{
if (con != null)
{
con.close();
}
}
catch (SQLException e)
{
System.out.println(e);
e.printStackTrace();
throw e;
}
}
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());
}
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,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,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"
xmlns:f5="http://xmlns.jcp.org/jsf/passthrough"
xmlns:ui="jakarta.faces.facelets"
xmlns:f="jakarta.faces.core">
<h:head>
<title>Client</title>
</h:head>
<h:body>
<h:form id="f1">
<p:growl id="id_growl_messages_client"
globalOnly="true"
showDetail="true" redisplay="false"/>
<h1> Client's Page </h1>
page that called this page: #{clientBean.fromCallerUrlOfParent}
<br/>
stock id passed: #{clientBean.fromCallerStockId}
<br/>
#{clientBean.map}
<p:commandButton value="Map" action="#{clientBean.GetRequestFromMap()}"/>
</h:form>
</h:body>
</html>

View File

@@ -0,0 +1,84 @@
<?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"
xmlns:ui="jakarta.faces.facelets">
<h:head>
<title>MP1 Ajax</title>
<h:outputStylesheet library="css" name="styles.css"/>
</h:head>
<h:body>
<h:form id="f1">
<p:growl id="id_growl_messages"
globalOnly="true"
showDetail="true" redisplay="false"/>
<p:dataTable id= "id_dataTable1" value ="#{stockBean.stocks }"
style="width: 100%; "
var="stock"
scrollable="true"
paginator="true"
paginatorPosition="bottom"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}"
currentPageReportTemplate="{startRecord} to {endRecord} of #{stockBean.getStocks().size() } "
rows="10"
resizableColumns="true"
rowHover ="true"
draggableRows="true"
draggableColumns="true"
rowKey="#{stock.stockId}"
selectionMode="single"
selection="#{stock}"
>
<p:column headerText="Stock ID"
sortBy="#{stock.stockId}"
>
<p:outputLabel title= "Stock ID" value="#{stock.stockId}" />
</p:column >
<p:column headerText="Stock Name"
sortBy="#{stock.companyName}"
>
<p:outputLabel title= "Stock Name" value="#{stock.companyName}" />
</p:column >
<p:column headerText="Current Price"
sortBy="#{stock.priceCurrent}"
>
<p:outputLabel title= "Current Price" value="#{stock.priceCurrent}" />
</p:column >
<p:column headerText="Closing Price"
sortBy="#{stock.priceClosing}"
>
<p:outputLabel title= "Closing Price" value="#{stock.priceClosing}" />
</p:column >
<p:column headerText="Shares Availlable"
sortBy="#{stock.numberOfSharesAvailable}" >
<p:outputLabel title= "Shares Avialable" value="#{stock.numberOfSharesAvailable}" />
</p:column >
<p:column headerText="Shares Sold"
sortBy="#{stock.numberOfSharesSold}" >
<p:outputLabel title= "Shares Sold" value="#{stock.numberOfSharesSold}" />
</p:column >
<p:ajax event="rowSelect" update="f1:id_growl_messages"
listener="#{stockBean.onRowSelect}" />
</p:dataTable>
<p:draggable for="id_dataTable1" helper="clone" opacity="0.5"/>
<h:commandButton value="Refresh DataTable" action="#{stockBean.refresh()}"/>
</h:form>
<br/>
</h:body>
</html>