I want to implement a custom PhaseListener in my faces-config.xml like it is suggested at stack overflow. So this is my faces-config.xml:

<lifecycle>
        <phase-listener>org.apache.myfaces.extensions.validator.core.startup.ExtValStartupListener</phase-listener>
        <phase-listener>org.apache.myfaces.extensions.validator.beanval.startup.JSF2AwareBeanValidationStartupListener</phase-listener>
        <phase-listener>org.apache.myfaces.extensions.validator.beanval.startup.BeanValidationStartupListener</phase-listener>
        <phase-listener>de.azt.MyPhaseListener</phase-listener>
</lifecycle>

And this is MyPhaseListener-Dummy:

public class MyPhaseListener implements PhaseListener {

    @Override
    public PhaseId getPhaseId() {
        return PhaseId.RENDER_RESPONSE;
    }

    @Override
    public void beforePhase(PhaseEvent event) {
        // Do your job here which should run right before the RENDER_RESPONSE.
    }

    @Override
    public void afterPhase(PhaseEvent event) {
        // Do your job here which should run right after the RENDER_RESPONSE.
    }

}

But this approach leads the application server to crash:

HTTP Status 500 - serialFactory

type Exception report

message serialFactory

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: serialFactory
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:229)
    org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    ch.ivyteam.ivy.dialog.execution.jsf.controller.rest.IvyRestServiceFilter.doFilter(IvyRestServiceFilter.java:54)
    ch.ivyteam.ivy.dialog.execution.jsf.controller.IvyFacesInstanceFilter.filterAsSystem(IvyFacesInstanceFilter.java:104)
    ch.ivyteam.ivy.dialog.execution.jsf.controller.IvyFacesInstanceFilter.access$0(IvyFacesInstanceFilter.java:79)
    ch.ivyteam.ivy.dialog.execution.jsf.controller.IvyFacesInstanceFilter$1.call(IvyFacesInstanceFilter.java:55)
    ch.ivyteam.ivy.dialog.execution.jsf.controller.IvyFacesInstanceFilter$1.call(IvyFacesInstanceFilter.java:1)
    ch.ivyteam.ivy.security.internal.SecurityManager.executeAsSystem(SecurityManager.java:1425)

So how is it possible to implement a custom PhaseListener?

asked 22.11.2013 at 16:31

Nikel%20Weis's gravatar image

Nikel Weis
(suspended)
accept rate: 57%

edited 22.11.2013 at 16:32

1

Hi Nikel,

I suppose this error appears at the start of your app? Have you exported your Phaselistener-Class in to a jar File? The application can only interpret compiled class files if you declare them in the xml file. So you have to export your package and insert the jar file into the lib-folder.

(28.11.2013 at 09:52) Raphael Bürgin Raphael%20B%C3%BCrgin's gravatar image

@Raphael: Thanks for the push into the right direction! The application does not crash at startup anymore.

(28.11.2013 at 10:41) Nikel Weis Nikel%20Weis's gravatar image

As Raphael Bürgin pointed out it is necessary to compile the class as jar file and place it in the lib-Folder. The syntax remains the same as in the initial question and the file should be named like the class - so it would be MyPhaseListener.jar (although the name is not best practice).

link

answered 28.11.2013 at 10:42

Nikel%20Weis's gravatar image

Nikel Weis
(suspended)
accept rate: 57%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×51
×32

Asked: 22.11.2013 at 16:31

Seen: 9,853 times

Last updated: 28.11.2013 at 10:42