Reputation: 330
(note: I subclassed jakarta.faces.component.UISelectItem and overridden toString, but for now the code below is effectively identical although i will be in future , removing the object search and simply obtaining the value from "listbox" , also be placing an array in init and make static for session bean) I created a JSF session bean with jakarta.faces-3.0.0-RC5.jar and apache-tomcat-10.0.12 using HtmlSelectOneListbox to show all TimeZone choices (It Works!) , but i find there is very little scope for the initial code infrastructure to work with because some components don't appear to have a pattern of creating them for using them that operates with UISelectItems (plural the wrapper of UIselectItem). Eventually i found some advice on the net that a class with interface java.util.Map can be placed into setValue of UISelectItems ,but placing an array of UISelectItem[] into UISelectItems does not operate! Neither does jakarta.faces.model.SelectItem[] get placed into UISelectItems but is put in a "group" that from API docs is a mystery to me how. I found from the API doc , to create a suitable array for UISelectItems requires five particular methods must be used compulsory successfully upon UISelectItem to place into UISelectItems (That finally got it operating). How is a jakarta.faces.model.SelectItem placed into anything for "binding" given that if it is in a group or the group can somehow be specified somewhere. Too, it took me some time to realize there was a system to create the html "option values" and setItemValue with setValue used on UISelectItem allows the server to store a proper matching index of values sent and recieved K,V
I know what binding is and I know what binding does, I just did that! (Also in 2010) but...some nice references to other JSF material. How does the 'binding' attribute work in JSF? When and how should it be used? This following is extremely helpful but not much of the problem as it does not use binding in f:selectItems. JSF-2 f:selectItems with Map does not display itemLabel
The following is used for "value=" with f:selectItems and is wrong for use in "binding"! itemLabel method is a compulsory on UIComponent How to populate options of h:selectOneMenu from database? Another recommended uses richfaces not jakarta
This is part of the interesting creature, this extends Object in Jakarta API docs jakarta.faces.model.SelectItem but cannot find a suitable alike to f:selectItems in either API or tag! Also the mimmick for optgroup labelling tag is another difficulty to find anything about in model or jakarta.faces.component.html In DHTML and HTML a "select" tag does not require any option or optgroup(if supported) tags because they can all be inserted in page and managed dynamically, hence a UISelectOneListbox(or other classes produce "select") will render without any nested tags although it has a body tag processor for nested tags
Someone wanted to see the XHTML page SOURCE
<?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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<f:view>
<h:head>
<meta http-equiv="Content-Type" content="application/xhtml+xml" />
<meta content="index,follow" name="robots" />
<meta content="" name="Description" />
<meta content="" name="Keywords" />
<meta content="nicephotog AT gmail.com" name="Author" />
<title>PAGE TITLE</title>
<!-- <link href="CSS-FILE-NAME.css" type="text/css" rel="stylesheet" /> -->
<!-- <script type="text/javascript" src="http://localhost:8080/JsfTestApp/newjavascript.js" /> -->
<script type="text/javascript">
//<![CDATA[
/* This script written by Samuel A Marchant [email protected] 7th Oct 2023
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
rdx=0;
pass=false;
/*
function sbm(){
document.forms[0].submit();
}
function getSelVal(){
//alert(""+document.getElementById("bcb").value);
return document.getElementById("bcb").value;
}
function setSecval(){
document.getElementById("fmm:selhide").value = getSelVal();
//alert("[1] "+document.getElementById("fmm:selhide").value);
return document.getElementById("fmm:selhide").value;
}
*/
function matchIdxforRestart(ire){
rdx=ire;
return rdx;
}
function psvL(ps){
pass=ps;
return pass;
}
function seledoc(ixnm){
//alert("ixnm : "+ixnm+" rdx ");
matchIdxforRestart(parseInt((ixnm+1)));
return document.getElementById("fbb:cec").selectedIndex=ixnm;
}
function findField(){
return document.getElementById("findinlist").value;
}
function findmatchingindex(){
opr = document.getElementById("fbb:cec").options;
lin = opr.length;
currentword=new String(document.getElementById("findinlist").value).toLowerCase();
//efendi=new String(" ");
efendi=currentword; //debug
afi = "";
or=0;
pass=psvL(false);
hasfound=false; // for stop
/*
if((parseInt(currentword.indexOf(efendi))==-1)){
efendi=currentword;
matchIdxforRestart(0); // rdx
or=0;
pass=false;
hasfound=false;
}else{
if(parseInt(currentword.length)!=parseInt(efendi.length)){
efendi=currentword;
matchIdxforRestart(0); // rdx
or=0;
pass=false;
hasfound=false;
}else{;}
}
*/
stp=false;
while(or<lin && stp==false){
if((rdx!=0) && (rdx<lin) && (pass==false)){
or=rdx;
pass=psvL(true);
}else{;}
afi=(new String(opr[or].value)).toLowerCase();
if(afi.indexOf(efendi)!=-1){
seledoc(parseInt(or));
pass=psvL(false);
hasfound=true;
or=lin;
}else{
if((or==(lin-1)) && (hasfound==false)){
stp=true;
matchIdxforRestart(0);
}else{
if(or>(lin-2)){
matchIdxforRestart(0);
pass=psvL(false);
or=0;
}else{;}
}
}
or++;
} //ewhl
}//enfunc
//]]>
</script>
</h:head>
<h:body id="fug" style="background-image: url(bkg.png);font-family:arial;font-size:13pt;margin: 10px;">
<!--
created by SUcommanderXer Last Pre Beta www.nicephotog-jsp.net
-->
<center>
<b>The <span style="color:rgb(250,80,0);font-style:italic;">HttpOutputTools (<i>-----------------</i> "-------------------")</span> Java <span style="color:rgb(250,80,0);font-style:italic;">Jar</span> project</b>
<p />
<!--
worldtime html and hidden jsf
-->
<input type="button" value=" find " onclick="findmatchingindex();" /> <input type="text" id="findinlist" value="" />
<br />
<h:form id="fbb" rendered="true">
<h:selectOneListbox required="true" id="cec" binding="#{selOneLiBox.listBox}" label="World Time Regions" style="font-size: 13pt;width:500px;" value="#{selOneLiBox.currentTimeWorldZone}">
<f:selectItems rendered="true" binding="#{selOneLiBox.seLits}" />
</h:selectOneListbox><br />
<h:commandButton id="sbmtt" action="getmoretime" value="Submit" />
</h:form>
<p />
<h:outputText value="#{selOneLiBox.worldTime}" rendered="true" escape="false" />
<p />
<p />
<!-- Put a time and date JSF field in here , and control to find particular timezone and location e.g. combobox list -->
<div style="padding:10px;width:95%;text-align:left;font-size:10pt;border:rgb(150,150,150) 3px solid;visibility:visible;">
<b>The <span style="color:rgb(250,80,0);font-style:italic;">HttpOutputTools (------------- "------------")</span> Java <span style="color:rgb(250,80,0);font-style:italic;">Jar</span> project</b>
<p style="font-style: italic;color: rgb(0,100,0);font-weight: bold;" />
[ Quick note REMEMBER THIS : In a nutshell 99.999r percent of all method calls in code when using the package should be from an interface, classes are only ever directly instantiated from the package if one of three server application scope server memory stored classes are constructed for loading at application init (names ending with 'Obj' that after retrieval with getAttribute() from the server should be cast to / received on an identifier as an interface) or it is the one special class to obtain the Interface 'Tool', the interface used to obtain almost all other interfaces ]
<p />
The HttpOutputTools projects started as a java web server file read/write output mechanism <b>to assist lowering repetitive server side coding overhead of extremely common segments of tasks and being able to setup read (from file) / writes (to output) for tunable conservation of RAM space</b>, particularly for small RAM allocation java servers such as in hosting plans.
<p />
Because many tasks of web server JSP,JSF or Servlet/Web Sevice use code that is repeated but often does require some severe modification for purpose, other library parts were added to build a set of common but short methods to lower repeated method call usage to produce these small common sub parts that occur, too, these methods often require other SE core library classes, resulting requirement for these classes to be used and callable in this package. These were added to the package by method calls to obtain and instantiate and use <i>from the one (or as few as possible) coding identifier</i> in the package rather than completely requiring to set up classes from import statements and instantiation.
<p />
Any reputable or J2EE Java Web Server contains a system to hold in memory special instantiated object classes instaniated at application startup that are obtained from the ServletContext or ApplicationContext. Some of the classes in the package are for use running stored in memory of the Web Server while the application is "on"(running), (However, a side note to this, all classes are Java SE core in the HTToutPutTools package and can be used in a desktop application or anywhere SE Core is used if wanted).
<p />
<span style="color:rgb(250,80,0);font-style:italic;font-weight:bold;">The jar package of classes includes:</span>
<p />
<ul>
<li>Hold commonly served documents or images (binary or B64) in memory either permanent or dynamically avoiding file handling.</li>
<li>Read files by "byte" in a small chunk section with self closing either for direct output or encrypted to Base 64 String.</li>
<li>Assess memory usage to assist preventing overrun during heavy server loading to custom trigger the JVM GC if required.</li>
<li>Help code internationalized java.time and form programs doing less coding and some web server relevant time pattern formats for UTC headers.</li>
<li>Text and time internationalization and Locale language testing with encodings, also a vast array of many HTML/XML entities.</li>
<li>Create and manage Cookies for server or page javascript.</li>
<li>Web server header commands list and special characters array for internationalization , header and script or cookies encoding.</li>
<li>Lower coding overhead of web server encoding schemes.</li>
<li>Binary search of byte literals, or byte literals of Strings in file , or with an Ignore Case version.</li>
<li>Storing special custom text "information" dynamically in server memory.</li>
<li>Quickly create or append to files e.g. temp files.</li>
</ul>
<p align="center" style="font-weight:bold;" />
Link: HttpOutPutTools Tutorial Link: HttpOutPutTools API Jar Documentation Link: HttpOutPutTools Sources Download
</div>
</center>
</h:body>
</f:view>
</html>
This is what i did and appear the only way to bind to the XHTML tag in page.
package beans;
import jakarta.faces.bean.ManagedBean;
//import jakarta.faces.bean.RequestScoped;
import jakarta.faces.bean.SessionScoped;
import jakarta.servlet.ServletContext;
import com.nicephotog.tools.*;
import com.nicephotog.tools.objectattribute.WebAppToolAPIconstantsObj;
import com.nicephotog.tools.wwwtimeifc.WebSqlTimeVar;
import java.util.Locale;
/*
SelOneLiBox.java completed 5th Oct 2023
JSF SelectOneListBox and UISelectItems binding
jakarta.faces-3.0.0-RC5.jar apache-tomcat-10.0.12 "nicephotog-web-tools.jar unreleased - Oct 5th 2023"
*/
/**
*
* @author samuel A Marchant [email protected]
*/
@ManagedBean
@SessionScoped
public class SelOneLiBox{
public jakarta.faces.component.html.HtmlSelectOneListbox listbox=null;
public jakarta.faces.component.UISelectItems useli=null;
public java.util.Map<String,jakarta.faces.component.UISelectItem> uiselsB=null;
public String currenttimeworldzone="Australia/ACT";
public String worldtime="none";
/*
The best i guess for doing this way is becausethe following require escaping into an XHTML (XML) document
because the ZoneId value String has a forward slash symbol in it . so illegal in xml (nb escaped is false in this)
uiiyinp.setItemValue(pack[pk]);
uiiyinp.setValue(pack[pk]);
*/
public String findZoneObj(){
String tzfound="";
java.util.Set<String> kys =uiselsB.keySet();
java.util.Iterator<String> io = kys.iterator();
jakarta.faces.component.UISelectItem si = new jakarta.faces.component.UISelectItem();
String ishsh ="";
boolean stp=false;
while((io.hasNext()==true) && (stp==false)){
si=uiselsB.get(io.next());
ishsh =si.toString();
if(ishsh.indexOf(currenttimeworldzone)!=-1){
//setCurrentTimeWorldZone(si.getItemLabel());
tzfound=si.getItemLabel();
stp=true;
}
}//enwhl
return (tzfound);
}//enmeth
public void setCurrentTimeWorldZone(String currentTimeWorldZone){ // setoption
this.currenttimeworldzone=currentTimeWorldZone;
}
public String getCurrentTimeWorldZone(){ // setoption
return currenttimeworldzone;
}
public jakarta.faces.component.UISelectItems getSeLits(){ // setoption
return useli;
}
public void setSeLits(jakarta.faces.component.UISelectItems useli){
this.useli=useli;
}
public void setListBox(jakarta.faces.component.html.HtmlSelectOneListbox listbox){
if(listbox!=null){}else{
this.listbox=makelistbox();
}
this.listbox=listbox;
}
// NOTE encodeBegin e.t.c. methods are for outputing in a servlet string dynamically with a reference to the Faces servlet dynamically
public jakarta.faces.component.html.HtmlSelectOneListbox getListBox(){ // for h:text
if(listbox!=null){
listbox.saveState(jakarta.faces.context.FacesContext.getCurrentInstance());
}else{
this.listbox=makelistbox();
}
return listbox;
}
public jakarta.faces.component.UISelectItem makeSel(String pack,int pk){
jakarta.faces.component.UISelectItem uiiyinp = new jakarta.faces.component.UISelectItem();
uiiyinp.setItemDescription("World zone ID choice "+pk);
uiiyinp.setItemLabel(pack);
uiiyinp.setItemDisabled(false);
uiiyinp.setItemEscaped(false);
uiiyinp.setItemValue(pack);
uiiyinp.setValue(pack);
uiiyinp.setRendered(true);
return (uiiyinp);
}
public jakarta.faces.component.html.HtmlSelectOneListbox makelistbox(){ // for h:text
listbox = new jakarta.faces.component.html.HtmlSelectOneListbox();
String[] pack = obtainZoneIDarray();
int pck = pack.length;
uiselsB = new java.util.LinkedHashMap<String,jakarta.faces.component.UISelectItem>();
jakarta.faces.component.UISelectItem buiiyinp = new jakarta.faces.component.UISelectItem();
for(int pk=0;pk<pck;pk++){
buiiyinp = makeSel(pack[pk],pk);
//uiiyinp.setId(""+pack[pk]); String does not conform
buiiyinp.setParent(useli);
uiselsB.put(pack[pk],buiiyinp);
}//enfr
useli = new jakarta.faces.component.UISelectItems();
useli.setValue(uiselsB);
listbox.setSize(10);
listbox.setRendered(true);
listbox.saveState(jakarta.faces.context.FacesContext.getCurrentInstance());
return (listbox);
}
// com.nicephotog.tools.objectattribute.objattrifc ZoneIdAndLocalelObjAttr getStringZoneIDArray()
// class com.nicephotog.tools.objectattribute.WebAppToolAPIconstantsObj getAttribute() getTZoneIdLocalesArrayObjRef()
// NOTE following array should be stored in an Application scoped bean
public String[] obtainZoneIDarray(){
ServletContext appconxt = (jakarta.servlet.ServletContext)(jakarta.faces.context.FacesContext.getCurrentInstance()).getExternalContext().getContext();
return ((((WebAppToolAPIconstantsObj)appconxt.getAttribute("ConstantsObj")).getTZoneIdLocalesArrayObjRef()).getStringZoneIDArray());
}
public String getWorldTime(){
String tz = findZoneObj();
if(tz.length()<1){
tz=currenttimeworldzone; // bare value at loading of bean - then everything after is findZoneObj() object ID search and itemlabel
}
String tm = "<span style=\"font-weight:bold;font-size:15pt;\">";
try{
Tool tl = new ToolWww().getWwwTool();
WebSqlTimeVar wbsqtm = tl.getTimeStampPodNow();
wbsqtm.setThisZoneidObj(java.time.ZoneId.of(tz));
tm += "JSF ListBox : "+wbsqtm .getDayOfWeek(Locale.US)+" "+wbsqtm.getYYYYMMDD(true)+" "+wbsqtm.getHHMMSS()+" "+tz+" </span>";
}catch(Exception ecx){
System.out.println("Error in JSF bean WorldTimeBean getWorldTime()");
}
worldtime=tm;
return worldtime;
}
}//enclss
This is the XHTML page somewhat expigated
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head id="j_idt2">
<meta http-equiv="Content-Type" content="application/xhtml+xml" />
<meta content="index,follow" name="robots" />
<meta content="" name="Description" />
<meta content="" name="Keywords" />
<meta content="nicephotog AT gmail.com" name="Author" />
<title>PAGE TITLE</title>
<!-- <link href="CSS-FILE-NAME.css" type="text/css" rel="stylesheet" /> -->
<script type="text/javascript">
function sbm(){
document.forms[0].submit();
}
function getSelVal(){
//alert(""+document.getElementById("bcb").value);
return document.getElementById("bcb").value;
}
function setSecval(){
document.getElementById("fmm:selhide").value = getSelVal();
//alert("[1] "+document.getElementById("fmm:selhide").value);
return document.getElementById("fmm:selhide").value;
}
</script></head><body id="fug" style="background-image: url(bkg.png);font-family:arial;font-size:13pt;margin: 10px;">
<!--
created by SUcommanderXer Last Pre Beta www.nicephotog-jsp.net
-->
<center>
<b>The <span style="color:rgb(250,80,0);font-style:italic;">HttpOutputTools (<i>-----------------</i> "-------------------")</span> Java <span style="color:rgb(250,80,0);font-style:italic;">Jar</span> project</b>
<p></p>
<!--
worldtime html and hidden jsf
-->
<form id="fbb" name="fbb" method="post" action="/JsfTestApp/faces/newbasefile.xhtml;jsessionid=3F8D963E42CFE75ACC715C99EA214211" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="fbb" value="fbb" />
<select id="fbb:cec" name="fbb:cec" size="10" style="font-size: 13pt;width:500px;"> <option value="jakarta.faces.component.UISelectItem@69c63b36">Asia/Aden</option>
<option value="jakarta.faces.component.UISelectItem@2cc4a86a">America/Cuiaba</option>
<option value="jakarta.faces.component.UISelectItem@3de961d4">Etc/GMT+9</option>
<option value="jakarta.faces.component.UISelectItem@1d22a712">Etc/GMT+8</option>
<option value="jakarta.faces.component.UISelectItem@45e5300b">Africa/Nairobi</option>
<option value="jakarta.faces.component.UISelectItem@4ceb5725">America/Marigot</option>
<option value="jakarta.faces.component.UISelectItem@3a7a78ad">Asia/Aqtau</option>
<option value="jakarta.faces.component.UISelectItem@326852c7">Pacific/Kwajalein</option>
<option value="jakarta.faces.component.UISelectItem@5ee159e9">America/El_Salvador</option>
<option value="jakarta.faces.component.UISelectItem@48a56f6f">Asia/Pontianak</option>
<!--
MANY MANY MORE OPTIONS BETWEEN
-->
<option value="jakarta.faces.component.UISelectItem@6b2b64f5">Pacific/Majuro</option>
<option value="jakarta.faces.component.UISelectItem@415c8d4e">America/Argentina/Buenos_Aires</option>
<option value="jakarta.faces.component.UISelectItem@b9d93">Europe/Nicosia</option>
<option value="jakarta.faces.component.UISelectItem@6dabb6ab">Pacific/Guadalcanal</option>
<option value="jakarta.faces.component.UISelectItem@5d177b27">Europe/Athens</option>
<option value="jakarta.faces.component.UISelectItem@7804ab36">US/Pacific</option>
<option value="jakarta.faces.component.UISelectItem@24bf56a0">Europe/Monaco</option>
</select><input id="fbb:sbmtt" type="submit" name="fbb:sbmtt" value="Submit" /><input type="hidden" name="jakarta.faces.ViewState" id="j_id1:jakarta.faces.ViewState:0" value="1335364430110979657:2013716172780036343" autocomplete="off" />
</form>
<p></p><span style="font-weight:bold;font-size:15pt;">JSF ListBox : Friday 2023-10-06 13:08:39 Australia/ACT </span>
<p></p>
<p></p>
<!-- Put a time and date JSF field in here , and control to find particular timezone and location e.g. combobox list -->
<div style="padding:10px;width:95%;text-align:left;font-size:10pt;border:rgb(150,150,150) 3px solid;visibility:visible;">
<b>The <span style="color:rgb(250,80,0);font-style:italic;">HttpOutputTools (------------- "------------")</span> Java <span style="color:rgb(250,80,0);font-style:italic;">Jar</span> project</b>
<!-- OTHER INFO TEXT IN MARKUP ->
<p align="center" style="font-weight:bold;"></p>
Link: HttpOutPutTools Tutorial Link: HttpOutPutTools API Jar Documentation Link: HttpOutPutTools Sources Download
</div>
</center></body>
</html>
Here is an image of it all
I tried inserting the array of UISelectItem f:SelectItems tag by method and tried array of jakarta.faces.model.SelectItem to f:SelectItems tag and as f:SelectItems tag value but only java.util.Map succeeds.
Upvotes: -1
Views: 176
Reputation: 330
No one would like to answer their own question and basically it remains standing in part of it relating jakarta.faces.model.SelectItemGroup that becomes far more confusing than switching between java.util.Map<String,jakarta.faces.component.UISelectItem> to the jakarta.faces.model.SelectItem system.
To make it more efficient i initialized all of it in a static block except the list box because it will with its value require to be an "instance".
The real difference when using jakarta.faces.component.UISelectItems with jakarta.faces.model.SelectItem[] as array is it will then operate , but not for the UISelectIems if it is an array , UISelectItems must be a java.util.Map!
(Completed Oct 29 corrected property name, changed SelectItems() to static and null on set, a rule bend - knocks out 50Kb data each copy - works fine now )
Main code
package beans;
import jakarta.faces.bean.ManagedBean;
//import jakarta.faces.bean.RequestScoped;
import jakarta.faces.bean.SessionScoped;
import jakarta.servlet.ServletContext;
import com.nicephotog.tools.*;
import com.nicephotog.tools.objectattribute.WebAppToolAPIconstantsObj;
import com.nicephotog.tools.wwwtimeifc.WebSqlTimeVar;
import java.util.Locale;
/*
SelOneLiBox.java completed October 29th 2023 ( changed to have selectitems array static store variable approx. 50kb data and null global property variable as set )
JSF SelectOneListBox and UISelectItems binding
jakarta.faces-3.0.0-RC5.jar apache-tomcat-10.0.12 "nicephotog-web-tools.jar unreleased - Oct 5th 2023"
*/
/**
*
* @author samuel A Marchant [email protected]
*/
@ManagedBean
@SessionScoped
public class SelOneLiBox{
public static final int arrznln;
//public static final String[] dspnam; // if you want final use a "constructor"
//public static final String[] zonval;
public static final jakarta.faces.model.SelectItem[] allzone;
public static final boolean rendT=true;
public static final boolean disaB=false;
public static final boolean escp=false;
public static final boolean noseloP=false;
//private static final jakarta.faces.model.SelectItemGroup[] allzonechoices;
public static jakarta.faces.component.UISelectItems sLs=null;
public jakarta.faces.component.UISelectItems seLits=null;
public jakarta.faces.component.html.HtmlSelectOneListbox listbox=null; // setCurrentTimeWorldZone(listbox.getValue().toString());
//public java.util.Map<String,jakarta.faces.component.UISelectItem> uiselsB=null;
public String currenttimeworldzone="Australia/ACT";
public String worldtime="none";
static{
arrznln = ((((WebAppToolAPIconstantsObj)((jakarta.servlet.ServletContext)(jakarta.faces.context.FacesContext.getCurrentInstance()).getExternalContext().getContext()).getAttribute("ConstantsObj")).getTZoneIdLocalesArrayObjRef()).lengthArrayZoneIdObject());
String[] dspnam=((((WebAppToolAPIconstantsObj)((jakarta.servlet.ServletContext)(jakarta.faces.context.FacesContext.getCurrentInstance()).getExternalContext().getContext()).getAttribute("ConstantsObj")).getTZoneIdLocalesArrayObjRef()).getZoneIDNameTextArray());
String[] zonval=((((WebAppToolAPIconstantsObj)((jakarta.servlet.ServletContext)(jakarta.faces.context.FacesContext.getCurrentInstance()).getExternalContext().getContext()).getAttribute("ConstantsObj")).getTZoneIdLocalesArrayObjRef()).getStringZoneIDArray());
allzone = new jakarta.faces.model.SelectItem[arrznln];
String reconstr="";
for(int init=0;init<arrznln;init++){
reconstr=new String((zonval[init]+" - "+dspnam[init]+" -").getBytes());
allzone[init]=new SelectItemStringer();
allzone[init].setValue(zonval[init]);
allzone[init].setLabel(reconstr);
allzone[init].setDescription("zoneID choice");
allzone[init].setDisabled(disaB);
allzone[init].setEscape(escp);
//allzone[init].setNoSelectionOption(noseloP);
}//enfr
//allzonechoices = new jakarta.faces.model.SelectItemGroup("All ZoneID Choices","All ZoneID Choices",false,allzone);
sLs = new jakarta.faces.component.UISelectItems();
sLs.setValue(allzone);
}//enstat
/*
private static String[] putstrdspnm(String[] ip){
dspnam=ip;
return dspnam;
}
//zonval dspnam
private static String[] putstrzonam(String[] ip){
zonval=ip;
return zonval;
}
*/
public void setCurrentTimeWorldZone(String currentTimeWorldZone){ // setoption
this.currenttimeworldzone=currentTimeWorldZone;
}
public String getCurrentTimeWorldZone(){ // setoption
return currenttimeworldzone;
}
public void setSeLits(jakarta.faces.component.UISelectItems seLits){ // setoption
this.seLits=null;
}
public jakarta.faces.component.UISelectItems getSeLits(){ // setoption
seLits=sLs;
return seLits;
}
public void setListBox(jakarta.faces.component.html.HtmlSelectOneListbox listbox){
this.listbox=listbox;
}
// NOTE encodeBegin e.t.c. methods are for outputing in a servlet string dynamically with a reference to the Faces servlet dynamically
public jakarta.faces.component.html.HtmlSelectOneListbox getListBox(){ // for h:text
if(listbox!=null){
listbox.saveState(jakarta.faces.context.FacesContext.getCurrentInstance());
}else{
this.listbox=makelistbox();
}
return listbox;
}
/*
-- groups to make
America
Etc
Africa
Asia
Pacific
Indian
Europe
GMT
Australia
Canada
Atlantic
US
--Anything Else--
*/
public jakarta.faces.component.html.HtmlSelectOneListbox makelistbox(){ // for h:text
listbox = new jakarta.faces.component.html.HtmlSelectOneListbox();
listbox.setLabel("World Time Zone Localities");
listbox.setSize(10);
listbox.setRendered(true);
listbox.saveState(jakarta.faces.context.FacesContext.getCurrentInstance());
return listbox;
}
public String getWorldTime(){
String tm = "<span style=\"font-weight:bold;font-size:15pt;\">";
try{
Tool tl = new ToolWww().getWwwTool();
WebSqlTimeVar wbsqtm = tl.getTimeStampPodNow();
wbsqtm.setThisZoneidObj(java.time.ZoneId.of(currenttimeworldzone));
tm += "JSF ListBox : "+wbsqtm.getDayOfWeek(java.util.Locale.US)+" "+wbsqtm.getYYYYMMDD(true)+" "+wbsqtm.getHHMMSS()+" "+currenttimeworldzone+" </span>";
}catch(Exception ecx){
System.out.println("Error in JSF bean WorldTimeBean getWorldTime()");
}
worldtime=tm;
return worldtime;
}//enmeth
}//enclss
toString Class code to extend from each selectitem
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package beans;
/**
*
* @author samuel
*/
public class SelectItemStringer extends jakarta.faces.model.SelectItem{
public SelectItemStringer(){
super();
}
@Override
public String toString(){
return (String) super.getValue();
}
}//enclss
The XHTML JSF page source Completely corrected blips in the js
<?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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<f:view>
<h:head>
<meta http-equiv="Content-Type" content="application/xhtml+xml" />
<meta content="index,follow" name="robots" />
<meta content="" name="Description" />
<meta content="" name="Keywords" />
<meta content="nicephotog AT gmail.com" name="Author" />
<title>PAGE TITLE</title>
<!-- <link href="CSS-FILE-NAME.css" type="text/css" rel="stylesheet" /> -->
<!-- <script type="text/javascript" src="http://localhost:8080/JsfTestApp/newjavascript.js" /> -->
<style type="text/css">
li{font-weight:bold;}
</style>
<script type="text/javascript">
//<![CDATA[
/* This script written by Samuel A Marchant [email protected] 10th Oct 2023
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
efendi=new String(" ");
rdx=0;
pass=false;
hasfound=false;
/*
function sbm(){
document.forms[0].submit();
}
function getSelVal(){
//alert(""+document.getElementById("bcb").value);
return document.getElementById("bcb").value;
}
function setSecval(){
document.getElementById("fmm:selhide").value = getSelVal();
//alert("[1] "+document.getElementById("fmm:selhide").value);
return document.getElementById("fmm:selhide").value;
}
*/
function fndi(fstr){
efendi=fstr;
return efendi;
}
function matchIdxforRestart(ire){
rdx=ire;
return rdx;
}
function psvL(ps){
pass=ps;
return pass;
}
function seledoc(ixnm){
//alert("ixnm : "+ixnm+" rdx ");
matchIdxforRestart(parseInt((ixnm+1)));
return document.getElementById("fbb:cec").selectedIndex=ixnm;
}
function findField(){
return document.getElementById("findinlist").value;
}
function adjHasfound(hsf){
hasfound=hsf;
return hasfound;
}
function findmatchingindex(){
opr = document.getElementById("fbb:cec").options;
lin = opr.length;
currentword=new String(document.getElementById("findinlist").value).toLowerCase();
afi = "";
or=0; // while
pass=psvL(false);
if((currentword.length > 3) || (currentword.indexOf("us")!=-1) || (currentword.indexOf("uct")!=-1)|| (currentword.indexOf("sao")!=-1)|| (currentword.indexOf("tel")!=-1)|| (currentword.indexOf("rio")!=-1)|| (currentword.indexOf("boa")!=-1) || (currentword.indexOf("dar")!=-1) || (currentword.indexOf("la")!=-1) || (currentword.indexOf("st")!=-1) || (currentword.indexOf("snt")!=-1) || (currentword.indexOf("el")!=-1) || (currentword.indexOf("san")!=-1) || (currentword.indexOf("cet")!=-1) || (currentword.indexOf("gmt")!=-1) || (currentword.indexOf("gb")!=-1) || (currentword.indexOf("etc")!=-1) || (currentword.indexOf("utc")!=-1) || (currentword.indexOf("rok")!=-1) || (currentword.indexOf("met")!=-1) || (currentword.indexOf("nz")!=-1) || (currentword.indexOf("prc")!=-1) || (currentword.indexOf("wet")!=-1) || (currentword.indexOf("eet")!=-1) || (currentword.indexOf("+")!=-1) || (currentword.indexOf("-")!=-1)){
// BUT IF YOU HAVE FOUND THEN YOU START TO SEARCH FROM rdx NOT ZERO INDEX corrects start position
if((currentword.indexOf(efendi)==-1) || ((efendi.length==currentword.length) && (efendi.indexOf(currentword)==-1)) || (efendi.length!=currentword.length)){
fndi(currentword); // efendi=
matchIdxforRestart(0);
adjHasfound(false);
}else{;}
stp=false;
while((or<lin) && (stp==false)){
if((rdx!=0) && (rdx<lin) && (pass==false)){
or=rdx;
psvL(true);
}else{;}
afi=(new String(opr[or].value)).toLowerCase();
if(afi.indexOf(efendi)!=-1){
seledoc(parseInt(or));
psvL(false);
adjHasfound(true);
or=lin;
}else{
if((or==(lin-1)) && (hasfound==false)){
stp=true;
matchIdxforRestart(0);
}else{
if(or>(lin-2)){
matchIdxforRestart(0);
psvL(false);
or=-1;
}else{;}
}
}
or++;
} //ewhl
}else{
alert("Error: Please use minimum 4 characters - Word length too short "+efendi);
}
}//enfunc
//]]>
</script>
</h:head>
<h:body id="fug" style="background-image:url('../bkg.jpg');font-family:arial;font-size:13pt;margin: 10px;">
<script type="text/javascript">
// <![CDATA[
// JSF /faces/ background url syntax
// alert(""+document.getElementById("fug").style.backgroundImage);
// ]]>
</script>
<!--
created by SUcommanderXer Last Pre Beta www.nicephotog-jsp.net
-->
<center>
<b>The <span style="color:rgb(250,80,0);font-style:italic;">HttpOutputTools (<i>Version: Giant Fishing Spider</i> "Anclometes Rufus")</span> Java <span style="color:rgb(250,80,0);font-style:italic;">Jar</span> project</b>
<p />
<!--
worldtime html and hidden jsf
-->
<input type="button" value=" find " onclick="findmatchingindex();" /> <input type="text" id="findinlist" value="" />
<br />Note: Although can be found by local name , for some reason the following display name text does not get found by the script
<br />Eastern Greenland Time (America/Scoresbysund) can be found after GMT+10
<br />Western Greenland Time (America/Nuuk) can be found after GMT-11
<p/>
<h:form id="fbb" rendered="true">
<h:selectOneListbox required="true" id="cec" binding="#{selOneLiBox.listBox}" label="World Time Regions" style="font-size: 13pt;width:500px;" value="#{selOneLiBox.currentTimeWorldZone}">
<f:selectItems rendered="true" binding="#{selOneLiBox.seLits}" />
</h:selectOneListbox>
<h:commandButton id="sbmtt" action="getmoretime" value="Submit" />
</h:form>
<p />
<h:outputText value="#{selOneLiBox.worldTime}" rendered="true" escape="false" />
<p />
<p />
<!-- Put a time and date JSF field in here , and control to find particular timezone and location e.g. combobox list -->
<div style="padding:10px;width:95%;text-align:left;font-size:10pt;border:rgb(150,150,150) 3px solid;visibility:visible;">
<b>The <span style="color:rgb(230,50,0);font-style:italic;">HttpOutputTools (<i>Version: Giant Fishing Spider</i> "Anclometes Rufus")</span> Java <span style="color:rgb(250,80,0);font-style:italic;">Jar</span> project</b>
<p />
<span style="font-style: italic;color: rgb(0,100,0);font-weight: bold;">[ Quick note REMEMBER THIS : In a nutshell 99.999r percent of all method calls in code when using the package should be from an interface, classes are only ever directly instantiated from the package if one of three server application scope server memory stored classes are constructed for loading at application init (names ending with 'Obj' that after retrieval with getAttribute() from the server should be cast to / received on an identifier as it's original class name ending with "...Obj")
<br />...OR... it is the one special class to obtain the Interface 'Tool', the interface used to obtain almost all other interfaces, the class ToolWww with only one method getWwwTool() ]</span>
<p />
<b>
<u>There are two pre requisites for use of this jar tool</u> [Link: Java web Servers and Technologies list]<br />
1. A basic understanding of configuration and tuning of a Java web server e.g. Jakarta Tomcat 10 , Oracle Glassfish 4 or 5<br />
2. A basic understanding of Java Web Server programming for JSP, JSF and Servlet Web Applications</b>
<p />
The HttpOutputTools projects started as a java web server file read/write output mechanism <b>to assist lowering repetitive server side coding overhead of extremely common segments of tasks and being able to setup read (from file) / writes (to output) for tunable conservation of RAM space</b>, particularly for small RAM allocation java servers such as in hosting plans.
<p />
Because many tasks of web server JSP,JSF or Servlet/Web Sevice use code that is repeated but often does require some severe modification for purpose, other library parts were added to build a set of common but short methods to lower repeated method call usage to produce these small common sub parts that occur, too, these methods often require other SE core library classes, resulting requirement for these classes to be used and callable in this package. These were added to the package by method calls to obtain and instantiate and use <i>from the one (or as few as possible) coding identifier</i> in the package rather than completely requiring to set up classes from import statements and instantiation.
<p />
Any reputable or J2EE Java Web Server contains a system to hold in memory special instantiated object classes instaniated at application startup that are obtained from the ServletContext or ApplicationContext. Some of the classes in the package are for use running stored in memory of the Web Server while the application is "on"(running), (However, a side note to this, all classes are Java SE core in the HTTPoutPutTools package and can be used in a desktop application or anywhere SE Core is used if wanted).
<p />
<span style="color:rgb(250,80,0);font-style:italic;font-weight:bold;">The jar package of classes includes the following:</span>
<p />
<ul>
<li>Hold commonly served documents or images (binary or B64) in memory either permanent or dynamically avoiding file handling.</li>
<li>Read files by "byte" in a small chunk section with self closing either for direct output or encrypted to Base 64 String.</li>
<li>Assess memory usage to assist preventing overrun during heavy server loading to custom trigger the JVM GC if required.</li>
<li>Help code internationalized java.time and form programs doing less coding and some web server relevant time pattern formats for UTC headers.</li>
<li>Text and time internationalization and Locale language testing with encodings, also a vast array of many HTML/XML entities.</li>
<li>Create and manage Cookies for server or page javascript.</li>
<li>Web server header commands list and special characters array for internationalization , header and script or cookies encoding.</li>
<li>Lower coding overhead of web server encoding schemes.</li>
<li>Binary byte match search of files by byte literals, or with an Ignore Case byte literal search version if searching for strings in text files.</li>
<li>Storing special custom text "information" dynamically in server memory.</li>
<li>Quickly create or append to files e.g. temp files.</li>
</ul>
<p align="center" style="font-weight:bold;" />
Link: HttpOutPutTools Tutorial Link: HttpOutPutTools API Jar Documentation Link: HttpOutPutTools Sources Download
</div>
</center>
</h:body>
</f:view>
</html>
And the ouput page image
Upvotes: -1