This is a piece difficult,It's JSF i'm using jakarta faces api 3.0.0 , it seems in a ManagedBean calling FacesContext to acquire the jakarta.faces.context.ExternalContext and use its getContext method that returns "java.lang.Object" that is either a PortletContext or a ServletContext (i'm not using neither need a portlet library) it does not respond or seem to gain the applications' running instance in Tomcat 10.
I need to obtain the proper instance of jakarta.servlet.ServletContext.
The docs do give reasons the ExternalContext getContext is not called except at startup or shutdown and does not make clear sense.
So shifting to another method that is called during operation from ExternalContext getApplicationMap a java.util.Map and using get "anobjectname" did not operate either.
I need to access the class attributes i placed into the jakarta.servlet.ServletContext of the app as to that thereof in normal circumstance as always operates, jakarta.servlet.ServletContext getAttribute "TheLoadedClassAttribute"
The JSF page is XML and renders and calls the methods and shows but i cannot reach the proper ServletContext instance when i call these in the ManagedBean. It also shows no error in the catalina.out log.
As you can see i've been shifting the code around this way and that but no result , but no error either !
package beans;
import com.sun.faces.config.WebConfiguration;
import jakarta.faces.bean.ManagedBean;
import jakarta.faces.bean.ManagedProperty;
import jakarta.faces.bean.SessionScoped;
//import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletContext;
import com.nicephotog.tools.objectattribute.WebAppToolRAMDataServingObj;
import com.nicephotog.tools.objectattribute.objattrifc.RamStringB64;
@ManagedBean(name="imagebytedatabean")
@SessionScoped
public class ImageByteDataBean{
//ServletContext appconxt; WebAppToolRAMDataServingObj dat; RamStringB64 b64obj;
//
String imagedata;
String testout;
public ImageByteDataBean(){}
public void setImageData(String imgNumber){
// jakarta.faces-3.0.0-RC5.jar
WebConfiguration wbc = WebConfiguration.getInstance();
ServletContext appconxt = wbc.getServletContext();
WebAppToolRAMDataServingObj dat = (WebAppToolRAMDataServingObj)appconxt.getAttribute("DataStoreObj");
RamStringB64 b64obj = dat.getRAMStringB64Store();
String idat = (b64obj.getRAMstringB64((int)new Integer(imgNumber).intValue()));
System.out.println("begin idat in managed bean : "+idat);
this.imagedata = idat;
}
public String getImageData(){
return this.imagedata;
}
public void setTestout(String testout){
this.testout=testout;
}
public String getTestout(){
return this.testout;
}
}//enclss
/*
public void setImagedata(Integer imgNumber){
java.util.Map appconxt = (java.util.Map)((jakarta.faces.context.ExternalContext)((jakarta.faces.context.FacesContext)jakarta.faces.context.FacesContext.getCurrentInstance()).getExternalContext()).getApplicationMap();
WebAppToolRAMDataServingObj dat = (WebAppToolRAMDataServingObj)appconxt.get("DataStoreObj");
RamStringB64 b64obj = dat.getRAMStringB64Store();
String idat = (b64obj.getRAMstringB64((int)imgNumber.intValue()));
System.out.println("begin idat in managed bean : "+idat);
this.imagedata = idat;
}
*/
HERE IS AN ERROR OUTPUT when @ManagedBean has parenthesized arguments to name the bean.
12-Nov-2022 03:46:05.050 WARNING [http-nio-8080-exec-3] com.sun.faces.context.SessionMap.put JSF1063: WARNING! Setting non-serializable attribute value into HttpSession (key: imagebytedatabean, value class: beans.ImageByteDataBean).
12-Nov-2022 03:46:05.054 SEVERE [http-nio-8080-exec-3] com.sun.faces.application.view.FaceletViewHandlingStrategy.handleRenderException Error Rendering View[/welcomeJSF.xhtml]
jakarta.el.ELException: /welcomeJSF.xhtml: Method not found: class beans.ImageByteDataBean.testout(java.lang.String)
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:47)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:42)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:170)
at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1454)
at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1454)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:164)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:93)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:72)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:178)
at jakarta.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:682)
at jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:437)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:872)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1695)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
12-Nov-2022 03:46:05.078 1100 [http-nio-8080-exec-3] com.sun.faces.context.ExceptionHandlerImpl.log JSF1073: jakarta.el.ELException caught during processing of RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=/welcomeJSF.xhtml: Method not found: class beans.ImageByteDataBean.testout(java.lang.String)
12-Nov-2022 03:46:05.078 1100 [http-nio-8080-exec-3] com.sun.faces.context.ExceptionHandlerImpl.log /welcomeJSF.xhtml: Method not found: class beans.ImageByteDataBean.testout(java.lang.String)
jakarta.el.ELException: /welcomeJSF.xhtml: Method not found: class beans.ImageByteDataBean.testout(java.lang.String)
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:47)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:42)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:170)
at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1454)
at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1454)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:164)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:93)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:72)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:178)
at jakarta.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:682)
at jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:437)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:223)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:185)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:158)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:119)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:872)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1695)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Following is its xml page , its only set for test output , the parameterized set method is able to inside or outside of an element and the whole process completes , but no result , but no error.
<!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">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JSP Page</title>
</h:head>
<f:view>
<h:body>
<h1><h:outputText value="JavaServer Faces" /></h1>
#{imagebytedatabean.testout('So heres some text to blow your mind!')}
<h:outputText value="#{imagebytedatabean.testout}" />
<p />
#{imagebytedatabean.imageData('4')}
<p />
<h:outputText value="#{imagebytedatabean.imageData}" />
</h:body>
</f:view>
</html>
I obtained the FacesContext and classes it obtains that indicate or insinuate coherent association with the the overall application context the jakarta.servlet.ServletContext.
SOLVED IT (mainly i should instantiated the properties) i simply could not understand the program flow of parameterized methods, so removed them (need to find good docs about parameterized EL methods), i'll just need to add another property to commit processing for page processing flow.
A good work around would/may be using WebConfiguration class to obtain the request parameters internally in the bean to obtain an image index with the postback url.
// jakarta.faces-3.0.0-RC5.jar jakarta.servlet.jsp.jstl-2.0.0.jar
// jakarta.inject-api-2.0.0.jar jakarta.annotation-api-62.jar
// nicephotog-web-tools.jar https://drive.google.com/file/d/1gjHmdC-BW0Q2vXiQYmp1rzPU497sybNy/view?usp=share_link
package beans;
import com.sun.faces.config.WebConfiguration;
import jakarta.faces.bean.ManagedBean;
//import jakarta.inject.Named;
//import jakarta.faces.bean.ManagedProperty;
//import jakarta.faces.bean.SessionScoped;
import jakarta.faces.bean.RequestScoped;
import jakarta.servlet.ServletContext;
import com.nicephotog.tools.objectattribute.WebAppToolRAMDataServingObj;
import com.nicephotog.tools.objectattribute.objattrifc.RamStringB64;
// (name = "imageByteDataBean", eager = true) @ManagedBean(name="imagebytedatabean")
//@Named("imageByteDataBean")
@ManagedBean
@RequestScoped
public class ImageByteDataBean{
//
String imagedata="4";
String testout="Internal text value";
public ImageByteDataBean(){}
public void setImagedata(String imagedata){
this.imagedata = imagedata ;
}
public String getImagedata(){
makeImg(imagedata);
return this.imagedata;
}
public void setTestout(String testout){
this.testout=testout;
}
public String getTestout(){
return this.testout;
}
public String makeImg(String umber){
/*
jakarta.faces-3.0.0-RC5.jar
javax package is identical to jakarta except for javax package name
THIS OPERATES TOO - NOTE THE CAST (jakarta.servlet.ServletContext) NOTE A CAST (javax.servlet.ServletContext)
jakarta.servlet.ServletContext appconxt = (jakarta.servlet.ServletContext)(jakarta.faces.context.FacesContext.getCurrentInstance()).getExternalContext().getContext();
*/
WebConfiguration wbc = WebConfiguration.getInstance();
ServletContext appconxt = wbc.getServletContext();
WebAppToolRAMDataServingObj dat = (WebAppToolRAMDataServingObj)appconxt.getAttribute("DataStoreObj");
RamStringB64 b64obj = dat.getRAMStringB64Store();
imagedata = (b64obj.getRAMstringB64((int)new Integer(umber).intValue()));
System.out.println("begin idat in managed bean : "+imagedata);
return imagedata;
}
}//enclss
the test page xml
<!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">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JSP Page</title>
</h:head>
<f:view>
<h:body>
<h1><h:outputText value="JavaServer Faces" /></h1>
<h:outputText value="#{imageByteDataBean.testout}" />
<p />
<p />
<h:outputText value="#{imageByteDataBean.imagedata}" />
</h:body>
</f:view>
</html>