JSF UISelectItems HtmlSelectOneListbox 绑定值 TimeZones

问题描述 投票:0回答:1

(注意:我子类化了 jakarta.faces.component.UISelectItem 并重写了 toString,但现在下面的代码实际上是相同的,尽管我将来会删除对象搜索并简单地从“listbox”获取值,也可以在 init 中放置一个数组并使会话 bean 成为静态) 我使用 HtmlSelectOneListbox 使用 jakarta.faces-3.0.0-RC5.jar 和 apache-tomcat-10.0.12 创建了一个 JSF 会话 bean 以显示所有时区选择(它有效!),但我发现初始代码基础设施的使用范围非常小,因为某些组件似乎没有创建它们的模式来使用与 UISelectItems (复数 UIselectItem 的包装器)一起操作的组件。 最终我在网上找到了一些建议,可以将具有接口 java.util.Map 的类放入 UISelectItems 的 setValue 中,但是将 UISelectItem[] 数组放入 UISelectItems 中不起作用! jakarta.faces.model.SelectItem[] 也没有被放入 UISelectItems 中,而是被放入一个“组”中,从 API 文档来看,这对我来说是一个谜。 我从 API 文档中发现,要为 UISelectItems 创建合适的数组,必须在 UISelectItem 上成功强制使用五个特定方法才能放入 UISelectItems (最终使其运行)。 如何将 jakarta.faces.model.SelectItem 放入“绑定”的任何内容中,如果它位于组中,或者可以以某种方式在某处指定该组。 同样,我花了一些时间才意识到有一个系统可以创建 html“选项值”,并且在 UISelectItem 上使用 setValue 的 setItemValue 允许服务器存储发送和接收的值的正确匹配索引K,V

我知道绑定是什么,我知道绑定的作用是什么,我就是这么做的! (也是在 2010 年)但是...对其他 JSF 材料的一些很好的参考。

“绑定”属性在 JSF 中如何工作?何时以及如何使用? 下面的内容非常有帮助,但问题不大,因为它没有在 f:selectItems 中使用绑定。 JSF-2 f:selectItems with Map 不显示 itemLabel

以下内容用于带有 f:selectItems 的“value=”,并且

在“绑定”中使用是错误的! itemLabel 方法是 UIComponent 上的强制方法 如何从数据库填充 h:selectOneMenu 的选项? 另一个推荐使用 richfaces 而不是 jakarta

这是有趣生物的一部分,它扩展了 Jakarta API 文档中的对象 jakarta.faces.model.SelectItem 但在 API 或标签中找不到与 f:selectItems 类似的合适工具!另外,optgroup 标签标签的模仿是在 model 或 jakarta.faces.component.html 中找到任何内容的另一个困难。在 DHTML 和 HTML 中,“select”标签不需要任何选项或 optgroup(如果支持)标签,因为它们都可以是插入页面并动态管理,因此 UISelectOneListbox(或其他类产生“选择”)将在没有任何嵌套标签的情况下呈现,尽管它有一个用于嵌套标签的主体标签处理器

有人想查看 XHTML 页面

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();" /> &nbsp; <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 &nbsp; &nbsp; Link: HttpOutPutTools API Jar Documentation &nbsp; &nbsp; Link: HttpOutPutTools Sources Download </div> </center> </h:body> </f:view> </html>
这就是我所做的,并且似乎是绑定到页面中 XHTML 标记的唯一方法。

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
这是经过部分阐述的 XHTML 页面

<?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> <!-- &lt;link href="CSS-FILE-NAME.css" type="text/css" rel="stylesheet" /&gt; --> <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>
这是全部的图像

我尝试通过方法插入 UISelectItem f:SelectItems 标记数组,并尝试将 jakarta.faces.model.SelectItem 数组插入 f:SelectItems 标记并作为 f:SelectItems 标记值,但只有 java.util.Map 成功。

java jsf binding tomcat10 selectonelistbox
1个回答
0
投票
没有人愿意回答自己的

问题,基本上它仍然存在于与此相关的部分中 jakarta.faces.model.SelectItemGroup 比在 java.util.Map 到 jakarta.faces.model.SelectItem 系统之间切换更令人困惑。 为了提高效率,我在静态块中初始化了所有内容(列表框除外),因为它的值要求是一个“实例”。

将 jakarta.faces.component.

UISelectItems

与 jakarta.faces.model.SelectItem[] 作为数组使用时的真正区别是它将随后进行操作,但不适用于 UISelectIems,如果它是数组,UISelectItems 必须成为 java.util.Map! (完全修正js中的blips并完成)

主要代码

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 12th 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 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 jakarta.faces.component.html.HtmlSelectOneListbox listbox=null; // setCurrentTimeWorldZone(listbox.getValue().toString()); 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"; 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); }//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 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){ 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"); useli = new jakarta.faces.component.UISelectItems(); //useli.setValue(uiselsB); useli.setValue(allzone); 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 类代码

/* * 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

XHTML JSF 页面源代码

<?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] 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("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>-----------------</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();" /> &nbsp; <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(250,80,0);font-style:italic;">HttpOutputTools (------------- "------------")</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 an interface) or it is the one special class to obtain the Interface 'Tool', the interface used to obtain almost all other interfaces ]</span> <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:</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 &nbsp; &nbsp; Link: HttpOutPutTools API Jar Documentation &nbsp; &nbsp; Link: HttpOutPutTools Sources Download </div> </center> </h:body> </f:view> </html>

以及输出页面图像

© www.soinside.com 2019 - 2024. All rights reserved.