Kuba Spatny
Kuba Spatny

Reputation: 26978

Primefaces Poll component triggers HTTP OPTIONS and Ajax call is not made

I am writing a web app where homepage needs to refresh every second. I decided to use Primefaces Poll component to make ajax calls periodically.

However the call is not made on the project base url, such as:

http://localhost:8080

but it does work correctly, when the url describes the folder structure:

http://localhost:8080/web/index.xhtml

Project structure:

enter image description here

Welcome-file in web.xml:

<welcome-file-list>
    <welcome-file>/web/index.xhtml</welcome-file>
</welcome-file-list>

index.xhtml

<?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://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>
<h:body>    

    <h:form>
        <h:outputText value="#{counterView.number}" id="counterNumber"/>
        <p:poll interval="1" listener="#{counterView.increment}" update="counterNumber"/>
    </h:form>    

</h:body>
</html>

CounterView.java

@Component("counterView")
@Scope("session")
public class CounterView {

    private int number;

    public int getNumber() {
        return number;
    }

    public void increment() {
        number++;
    }

}

Further debugging in FireBug shows that there's actually a HTTP OPTIONS method called:

enter image description here

But it's not even called to http://localhost:8080/web/index.xhtml but to http://web/index.xhtml and it's aborted after some time.


I could fix this problem by forcing a redirect to address http://localhost:8080/web/index.xhtml but I'd really like to know what's causing this problem and fix it more cleanly.

Upvotes: 0

Views: 454

Answers (1)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85781

You're setting an absolute path as your welcome file, this is noted by the first / in the value:

<welcome-file>/web/index.xhtml</welcome-file>

Remove it so it will be relative to the context path of your application:

<welcome-file>web/index.xhtml</welcome-file>

Upvotes: 2

Related Questions