Unable to access CDI
I have a class that contains a method annotated with @PostConstruct which fetchs list of customers
@ViewScoped
@Named
public class CustomerController extends AlertResponse {
@PostConstruct
public List<Customer> init() {
ResponseEntity<List<Customer>> listResponse =
restTemplate.exchange("http://localhost:8030/api/customers/listCustomers",
HttpMethod.GET, null, new ParameterizedTypeReference<>() {
});
customersList = listResponse.getBody();
return customersList;
}
When i run the application i get this error
java.lang.IllegalStateException: Unable to access CDI
at javax.enterprise.inject.spi.CDI.current(CDI.java:65)
at com.sun.faces.cdi.CdiUtils.createDataModel(CdiUtils.java:308)
at com.sun.faces.facelets.component.UIRepeat.getDataModel(UIRepeat.java:255)
at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:465)
at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:515)
at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:1081)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1648)
at org.primefaces.component.column.Column.renderChildren(Column.java:90)
at org.primefaces.component.datatable.DataTableRenderer.encodeCell(DataTableRenderer.java:1356)
at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:1272)
at org.primefaces.component.datatable.DataTableRenderer.encodeRows(DataTableRenderer.java:1179)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:1119)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:1072)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:401)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:331)
at org.primefaces.component.datatable.DataTableRenderer.render(DataTableRenderer.java:106)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:97)
When i removed these lines, the view is rendred fine
<p:column headerText="Customer Status" sortBy="#{customer.customerStatus}"
filterBy="#{customer.customerStatus}">
<ui:repeat value="#{customer}" var="data">
<h:outputText rendered="#{data.customerStatus == 'Unlocked'}">
<p:tag styleClass="p-mr-2" severity="success" value="UnLocked"
rounded="true"/>
</h:outputText>
<h:outputText rendered="#{data.customerStatus == 'Locked'}">
<p:tag styleClass="p-mr-2" severity="danger" value="Locked"
rounded="true"/>
</h:outputText>
</ui:repeat>
</p:column>
What could be the problem Thank you in advance
1 answer
-
answered 2022-05-06 23:37
user3192295
@PostConstruct is for initialization purposes like opening a database connection. Methods annotated with @PostConstruct must have void return type and no parameter:
void init() { ...
do you know?
how many words do you know
See also questions close to this topic
-
Read each name in Array list to create seperate object for
I have a file that has student names, age, and an id number. I have a student class that holds the everything above for each student object. I stored all the names, id numbers. and age separately in an array list. Now im trying to assign the info to create a student object.
public class Student { private String lName; private int idNumber; private int age; public Student() { lName = ""; idNumber = 0; age = 0; } public Student(String l, int i, int a) { lName = l; idNumber = i; age = a; } public void setName(String last) { lName = last; } public String getName() { return lName; } public void setIdNum(int num) { idNumber = num; } public int getIdNum() { return idNumber; } public void setAge(int a) { age = a; } public int getAge() { return age; } }
My Text File looks something like this: This info is stored in parallel array lists. I don't quite get how to implement this into an object to pass it into my second contractor method.
Josh 2134 19 Smith 5256 21 Rogers 9248 19 Andrew 7742 20
Here's what I've tried;
public static void main(String[] args) { String file = "studentData.txt"; Scanner reader = new Scanner(file); ArrayList<String> lastNames = lNames(file); ArrayList<Integer> idNumbers = idNum(file); ArrayList<Integer> ageList = ages(file); Scanner input = new Scanner(System.in); Student s1 = new Student(); // confused about how to implement this constructor with the textile info for (int i = 0; i<idNumbers.size(); i++) { Student user = new Student(lastNames.get(i), idNumbers.get(i), ageList.get(i)); } //user enters idNumber to display age System.out.println("Enter ID Number"); //exception handling to be added int idNum = input.nextInt(); for (int i = 0; i<idNumbers.size(); i++) { if (idNum == idNumbers.get(i)) { s1.setAge(ageList.get(i)); System.out.println(s1.getAge()); } } }
-
Using EdittextPreference for Goto search
sorry for my poor English. I want to use EditTextPreference in my bottom nav like the pic below, ![screenshot][1]
I have recycleview xml in my project with in many sub cardview layouts(which is scrollable) and I want to create item in the bottom nav which is called "Goto". When the "Goto" item is clicked i want it to pop-up like the screenshot. And when user enters a number(according to the cardviews i.e if the number of cardview is 40 user must enter 1-40) I want to search the cardview by its ID. Thank you and I hope u got it, If u have any questions let me know [1]: https://i.stack.imgur.com/grK8P.jpg
My xml format look like this. As you see in the blow since the cardviews are huge in number it is not cool to scroll all the way down that is why i need Goto item in the bottom nav to search it by its ID when the user click number in the EditTextPreference as u see in the screenshot. i.e The screenshot is not from my app
<LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> <LinearLayout> <androidx.cardview.widget.CardView> <RealtiveLayout> <Textview/> <RealtiveLayout> </androidx.cardview.widget.CardView> </LinearLayout> .. .. .. .. many more..
-
How to get remaining time of the day in java?
I would like to calculate the time remaining for next day 00:00:00 from the current date time.
For e.g. time difference between 2
022-05-07T05:49:41.883807900Z
and2022-05-08T00:00:00Z
Expected answer:
18:10:19
or 65419 (in seconds).How can I achieve this with efficiently using java 8?
-
Hibernate handles id assigning instead of database
I have an auto-increment PK in a table and I want hibernate to handle id assigning instead of database. As my understanding the
@GeneratedValue(strategy = GenerationType.IDENTITY)
lets the database generate a new value with each insertion operation. So do we have any different solution to handle it? -
How can I delete a row by its SKU instead of its ID?
I try to delete the row using the sku of the product. I'm using spring boot and angular. I got an error when I added the sku on my button like this one
(click)="onDeleteProductBySku(deleteClick?.sku)"
it said that theProperty 'sku' does not exist on type '(product: Product) => void'.
. On my command prompt, I got this error. How can I solve this problem?Error: product/product.component.html:50:109 - error TS2339: Property 'sku' does not exist on type '(product: Product) => void'. 50 <button class="btn btn-outline-danger btn-sm me-2" (click)="onDeleteProductBySku(deleteClick?.sku)">Delete</button> product/product.component.ts:12:16 12 templateUrl: './product.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~~ Error occurs in the template of component ProductComponent.
ProductsController.java --> This is working on the postman.
//Delete a product record using sku //http://localhost:8080/products/deletebysku?sku=12345678 @DeleteMapping("/products/deletebysku") @ResponseBody private void deleteProductBySku(@RequestParam String sku){ productsService.deleteProductBySku(sku); }
product.component.ts
public deleteProduct!: Product; public onDeleteProductBySku(sku: string): void { this.productServive.deleteProductBySku(sku).subscribe( (response: void) => { this.messageShow(); console.log(response); this.getAllProduct(); }, (error: HttpErrorResponse) => { this.errorMessage(error.message); } ); } public deleteClick(product: Product) { this.deleteProduct = product; console.log("delete by sku"); }
product.service.ts
public deleteProductBySku(sku: string): Observable<void> { return this.http.delete<void>(`${this.apiServerUrl}/products/deletebysku?sku=${sku}`); }
product.component.html
<button class="btn btn-outline-danger btn-sm me-2" (click)="onDeleteProductBySku(deleteClick?.sku)">Delete</button>
-
Multithreading using springboot
I’m new to multithreading and I want to know how to approach it for my code, currently files are getting generated and processed into fielder using single thread hence unable to handle bulk file generation abs this needs to be handled using multithreading . How do I approach this ? Using java 11 and xml format springboot approach .
-
h:dataTable Setting the width of the cell has no effect
In
h:dataTable
, set the width of the style ofh:column
, but it is invalid. The code is as follows:<h:dataTable rowClasses="column50" .column50 { max-width: 100px; }
-
JSF 2.2 (Mojarra) calls f:ajax twice in nested composite:component
i've got a pretty simple example:
there is a nested composite component.
on my index.xhtml is a component called "ht:wrapper" to which are registered some ajax listeners for onKeyup and onChange events.
the compostite component "ht:wrapper" itself provides some clientBehaviors for given events and a nested compostite component "ht:input" this inner component is a simple h:inputText with clientBehaviors registered for keyup and change.
the ajax listener on index.xhtml will call a javascript function which adds the name of the event ("onKeyup" or "onChange") to a at the bottom of the input.
my problem: "onKeyup" fires twice if i press/release a single button.
is this a bug or im i dooing something wrong?
some tests with myfaces 2.2 seems to work as expected and fires only one event at a time.
here my minimum example:
index.xhtml
<h:form id="htmlForm"> <p> This is a simple example how a behavior (keyup, change) gets called twice. <br /> A simple h:inputText is nested in a composite component, which provides clientBehaviors. </p> <ht:wrapper id="htmlWrapper" value="#{myBean.htmlString}"> <f:ajax event="onKeyup" onevent="add('onKeyup')" /> <f:ajax event="onChange" onevent="add('onChange')" /> </ht:wrapper> <script> function add(s) { $('#htmlBehavior').append('<div>' + s + '</div>'); } </script> <div id="htmlBehavior" style="margin-top:10px; width: 250px; background-color: #ccc; border: 1px solid #472; padding: 5px"> <div> <b>Triggered Behaviors:</b> </div> </div> </h:form>
ht:wrapper
<cc:interface shortDescription="my simple input wrapper"> <cc:attribute name="value" required="true" /> <cc:clientBehavior name="onKeyup" targets="inputWrapper" event="onKeyup" /> <cc:clientBehavior name="onChange" targets="inputWrapper" event="onChange" /> </cc:interface> <cc:implementation> <ht:input id="inputWrapper" value="#{cc.attrs.value}" /> </cc:implementation>
ht:input
<cc:interface shortDescription="my input"> <cc:attribute name="value" required="true" /> <cc:clientBehavior name="onKeyup" targets="inputId" event="keyup" /> <cc:clientBehavior name="onChange" targets="inputId" event="change" /> </cc:interface> <cc:implementation> <h:inputText id="inputId" value="#{cc.attrs.value}" /> </cc:implementation>
pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.my.example</groupId> <artifactId>behavior</artifactId> <packaging>war</packaging> <version>1.0</version> <properties> <jetty.version>9.4.46.v20220331</jetty.version> <mojarra.version>2.2.20</mojarra.version> <myfaces.version>2.2.14</myfaces.version> </properties> <!-- Project dependencies --> <dependencies> <!-- Mojarra 2.2--> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId> <version>${mojarra.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>${mojarra.version}</version> <scope>compile</scope> </dependency> <!-- MyFaces 2.2 --> <!-- <dependency> <groupId>org.apache.myfaces.core</groupId> <artifactId>myfaces-api</artifactId> <version>${myfaces.version}</version> </dependency> <dependency> <groupId>org.apache.myfaces.core</groupId> <artifactId>myfaces-impl</artifactId> <version>${myfaces.version}</version> </dependency> --> </dependencies> <build> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>${jetty.version}</version> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
-
Problems with the attribute "placeholder" of an <p:inputText tag when the value of the inputText is empty
I am using JSF Mojarra 2.3.9.SP02 with PrimeFaces 7.0 running on Wildfly 17 with the PrimeFaces's own Sapphire template.
I have a severe problem with one <p:inputText element in my form, for which I have specified a placeholder, and whose initial value is empty. This is the first input field just below the panel group with the title "Kontaktperson" as shown in the attachment
Below is my minimal working example:
=========== .xhtml file ==================
<!DOCTYPE html>
<h:head> <f:facet name="first"> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/> <meta name="apple-mobile-web-app-capable" content="yes" /> </f:facet> <title>Hello</title> <h:outputScript name="js/nanoscroller.js" library="sapphire-layout" /> <h:outputScript name="js/layout.js" library="sapphire-layout" /> <h:outputScript name="js/ripple.js" library="sapphire-layout" /> </h:head> <h:body> <style> .md-inputfield_marg_top{ margin-top: 10px; } </style> <div class="ui-g ui-fluid"> <div class="card card-w-title"> <h:form id="resultsFormId"> <div class="card-title">Firmendaten bearbeiten</div> <p:fieldset legend="Kontaktperson" toggleable="true" toggleSpeed="500"> <div class="ui-g-12 ui-md-2"> <div class="ui-inputgroup"> <span class="ui-inputgroup-addon"> <i class="material-icons">account_circle</i> </span> <h:panelGroup styleClass="md-inputfield md-inputfield_marg_top"> <p:inputText value="#{fdTestBean.titel}" placeholder="Mag."/> <label>Titel</label> </h:panelGroup> </div> </div> <div class="ui-g-12 ui-md-2"/> <div class="ui-g-12 ui-md-8"> <div class="ui-inputgroup"> <span class="ui-inputgroup-addon"> <i class="material-icons">account_circle</i> </span> <h:panelGroup styleClass="md-inputfield md-inputfield_marg_top"> <p:inputText value="#{fdTestBean.qualifikation}" /> <label>Qualifikation</label> </h:panelGroup> </div> </div> <div class="ui-g-12 ui-md-6"> <div class="ui-inputgroup"> <span class="ui-inputgroup-addon"> <i class="material-icons">account_circle</i> </span> <h:panelGroup styleClass="md-inputfield md-inputfield_marg_top"> <p:inputText value="#{fdTestBean.vorname}"/> <label>Vorname</label> </h:panelGroup> </div> </div> <div class="ui-g-12 ui-md-6"> <div class="ui-inputgroup"> <span class="ui-inputgroup-addon"> <i class="material-icons">account_circle</i> </span> <h:panelGroup styleClass="md-inputfield md-inputfield_marg_top"> <p:inputText value="#{fdTestBean.nachname}"/> <label>Nachname</label> </h:panelGroup> </div> </div> </p:fieldset> </h:form> </div> </div> <h:outputStylesheet name="css/nanoscroller.css" library="sapphire-layout" /> <h:outputStylesheet name="css/ripple.css" library="sapphire-layout" /> <h:outputStylesheet name="css/grid.css" library="sapphire-layout" /> <h:outputStylesheet name="css/layout-#{guestPreferences.layout}.css" library="sapphire-layout" /> </h:body> </html>
And my backing bean here:
package at.home.digest.web.ave.makler.firma; import java.io.Serializable; import javax.inject.Named; @Named("fdTestBean") @javax.faces.view.ViewScoped public class FDTestBean implements Serializable { private String titel; private String qualifikation; private String vorname; private String nachname; public String getTitel() { return titel; } public void setTitel(String titel) { this.titel = titel; } public String getQualifikation() { return qualifikation; } public void setQualifikation(String qualifikation) { this.qualifikation = qualifikation; } public String getVorname() { return vorname; } public void setVorname(String vorname) { this.vorname = vorname; } public String getNachname() { return nachname; } public void setNachname(String nachname) { this.nachname = nachname; } }
-
When nesting another datatable in rowexpansion, splitbutton stops working when 2 or more main rows are loaded
So I'm trying to nest a datatable within another datatable in the rowexpansion tag as follows:
<h:form> <p:dataTable var="item" value="#{bean.items}"> <p:column> <p:rowToggler/> </p:column> <p:column headerText="Item Name"> <h:outputText value="#{item.name}"/> </p:column> <p:rowExpansion> <p:dataTable var="subitem" value="#{item.subitems}"> <p:column headerText="Subitem Name"> <h:outputText value="#{subitem.name}" /> </p:column> <p:column> <p:splitButton value="Save" action="#{bean.save}"> <p:menuitem value="Update" action="#{bean.update}"/> <p:menuitem value="Delete" action="#{bean.delete}"/> </p:splitButton> </p:column> </p:dataTable> </p:rowExpansion> </p:dataTable> </h:form>
the testing methods in the bean are just
public void save() { addMessage(FacesMessage.SEVERITY_INFO, "Success!", "Saved subitem"); PrimeFaces.current().ajax().update(":frmTopbar"); } public void update() { addMessage(FacesMessage.SEVERITY_INFO, "Success!", "Updated subitem"); PrimeFaces.current().ajax().update(":frmTopbar"); } public void delete() { addMessage(FacesMessage.SEVERITY_INFO, "Success!", "Deleted subitem"); PrimeFaces.current().ajax().update(":frmTopbar"); } public void addMessage(FacesMessage.Severity severity, String summary, String detail) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(severity, summary, detail)); }
If only a single item and its subitems is loaded, everything displays and splitbutton buttons work fine.
The bean just sends a FacesMessage to test and like I said, the message is properly shown for each of the 3 buttons.
But as soon as I load 2 or more items and their subitems, everything looks visually correct, but the commands in splitbutton no longer reach bean, so no FacesMessage is sent.
Does anyone have a clue about what is going on or a suggestion as to what can be done to fix it?
I'm using primefaces v11.0
Thanks a lot!
-
Java Server Faces - Ajax request with old session id causes error, if a new session already exists
This error has been happening for a while now in our logs, but we have never managed to replicate it.
2022-04-11 12:55:08,799 SEVERE [org.omnifaces.exceptionhandler.FullAjaxExceptionHandler] (default task-106) FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/error.xhtml' will be shown.: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'handler' resolved to null at com.sun.el.parser.AstValue.getTarget(AstValue.java:173) at com.sun.el.parser.AstValue.getType(AstValue.java:85) at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201) at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93) at org.jboss.weld.el.WeldValueExpression.getType(WeldValueExpression.java:93) at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95) at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1045) at javax.faces.component.UIInput.validate(UIInput.java:975) at javax.faces.component.UIInput.executeValidate(UIInput.java:1248) at javax.faces.component.UIInput.processValidators(UIInput.java:712) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261) at javax.faces.component.UIForm.processValidators(UIForm.java:253) at org.omnifaces.component.input.Form.processValidators(Form.java:152) at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:575) at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at javax.faces.component.UIForm.visitTree(UIForm.java:381) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700) at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:266) at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57) at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:219) at org.omnifaces.context.OmniPartialViewContext.processPartial(OmniPartialViewContext.java:124) at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1193) at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129) at org.omnifaces.filter.CacheControlFilter.doFilter(CacheControlFilter.java:239) at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) at com.mycompany.LoginFilter.doFilter(LoginFilter.java:250) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) at org.omnifaces.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:124) at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:108) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131) at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
Today, I have finally managed to replicate this error locally. It happens when you have two tabs open, with one of the tabs having an old, invalidated session id.
Steps to reproduce this:
- Open tab 1 and login to our application.
- Wait for tab 1's session to invalidate.
- Open tab 2 and login to our application.
- Go to tab 1 and do any ajax operation.
- Page crashes with the error above.
We use JSF 2.2 in Wildfly 10.1.0 (Mojarra 2.2.13) and make use of saving our state on the client side. Session id is in the cookie.
I think that in step 4, the ajax request uses the newer session and thus the user is deemed as logged in. Then it attempts to rebuild the view state on the backend, but fails to do so. I think it's because the view scoped beans have been destroyed when the old session got invalidated.
Is there a way of detecting this in my code? Preferably in a Http request filter, where I could redirect the user to the home page?
-
JSF ajax call giving error within openfacess library - JBoss 7.4 and Java 11
I'm deploying a web application(war file) to JBoss 7.4 server environment.
JBoss EAP 7.4.0.GA (WildFly Core 15.0.2.Final-redhat-00001) starting
Java Version
java.home = /usr/lib/jvm/java-11-openjdk-11.0.14.0.9-1.el7_9.x86_64
This web application uses Mojarra 2.3.14 + Richfaces 4.5.4 + Openfaces 3.0 libraries for some of the UI screens.
The application was running fine on JBoss 7.1/Java 8. After upgrading to JBoss 7.4/Java 11 any Ajax call on UI screen is giving below error in server log file. There were no change to JSF related libraries.
The below error is from Openfaces 3.0 library.
2022-Feb-16 19:02:51,591 [] INFO io.undertow.servlet:371 - BEFORE RESTORE_VIEW 1 2022-Feb-16 19:02:51,625 [] INFO io.undertow.servlet:371 - AFTER RESTORE_VIEW 1 2022-Feb-16 19:02:51,625 [] INFO io.undertow.servlet:371 - BEFORE APPLY_REQUEST_VALUES 2 2022-Feb-16 19:02:51,628 [] INFO io.undertow.servlet:371 - AFTER APPLY_REQUEST_VALUES 2 2022-Feb-16 19:02:51,628 [] INFO io.undertow.servlet:371 - BEFORE PROCESS_VALIDATIONS 3 2022-Feb-16 19:02:51,630 [] INFO io.undertow.servlet:371 - AFTER PROCESS_VALIDATIONS 3 2022-Feb-16 19:02:51,630 [] INFO io.undertow.servlet:371 - BEFORE UPDATE_MODEL_VALUES 4 2022-Feb-16 19:02:51,631 [] INFO io.undertow.servlet:371 - AFTER UPDATE_MODEL_VALUES 4 2022-Feb-16 19:02:51,631 [] INFO io.undertow.servlet:371 - BEFORE INVOKE_APPLICATION 5 2022-Feb-16 19:02:51,631 [] INFO io.undertow.servlet:371 - AFTER INVOKE_APPLICATION 5 2022-Feb-16 19:02:51,631 [] INFO io.undertow.servlet:371 - BEFORE RENDER_RESPONSE 6 2022-Feb-16 19:02:51,642 [] SEVERE webcontainer.jsf.application:1164 - Error Rendering View[/jsf/page/ps/overallportal/portal_configuration.xhtml]: java.lang.NullPointerException at deployment.expert3.war//org.openfaces.application.OpenFacesResourceHandler.isExternalResource(OpenFacesResourceHandler.java:96) at deployment.expert3.war//org.openfaces.application.OpenFacesResourceHandler.getRendererTypeForResourceName(OpenFacesResourceHandler.java:78) at com.sun.jsf-impl@2.3.14.SP04-redhat-00001//com.sun.faces.context.PartialViewContextImpl.renderComponentResources(PartialViewContextImpl.java:482) at com.sun.jsf-impl@2.3.14.SP04-redhat-00001//com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:314) at deployment.expert3.war//org.richfaces.context.ExtendedPartialViewContext.processPartial(ExtendedPartialViewContext.java:263) at javax.faces.api@3.0.0.SP04-redhat-00001//javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:228) at deployment.expert3.war//org.openfaces.ajax.PartialViewContext.processPartial(PartialViewContext.java:131) at javax.faces.api@3.0.0.SP04-redhat-00001//javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1102) at javax.faces.api@3.0.0.SP04-redhat-00001//javax.faces.component.UIComponent.encodeAll(UIComponent.java:1647) at com.sun.jsf-impl@2.3.14.SP04-redhat-00001//com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:442) at com.sun.jsf-impl@2.3.14.SP04-redhat-00001//com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:170) at javax.faces.api@3.0.0.SP04-redhat-00001//javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:132) at javax.faces.api@3.0.0.SP04-redhat-00001//javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:132)
This same web application works without issues JBoss 7.1 and Java 8. Anyone idea why we are getting above error ?
-
How to send Authorization header in JSF - Mojarra - PrimeFaces
We have a java 8 project with JSF Mojarra implementation with PrimeFaces 3.5. We are implementing the authentication OIDC using Spring Security.
The front has to include in each HTTP Request the header Authorization with the bearer token. We couldn't find how to add a header in a call any Primefaces component (commandbutton,etc).
When I use for example the commandLink tag (https://www.tutorialspoint.com/jsf/jsf_commandlink_tag.htm) I need that the rendered method
mojarra.jsfcljs
to send the Authorization header with my token when it calls the backend.Is there any way of send customized headers with Mojarra in order to implement OIDC protocol?