PrettyFaces eating FacesMessage!?!?!!?

Splash Forums PrettyFaces Users PrettyFaces eating FacesMessage!?!?!!?

This topic contains 6 replies, has 3 voices, and was last updated by  Christian Kaltepoth 4 years, 10 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #18635

    filosofisto
    Participant

    I received that pretty is eating FacesMessage.

    Use Seam 3, JSF2, Pretty 3.3.2.

    Controller code:

    public String incluir() {

    Usuario user = securityService.adicionarUsuarioAdministrador(usuario, senha);

    evtInsert.fire(user);

    return "pretty:usuarioAdmin";

    }

    Event Observer:

    (public void onIncluir(@Observes(during=TransactionPhase.AFTER_SUCCESS) @Insert final Usuario usuario) {

    msg.info(new BundleKey("messages", "registro_incluido_sucesso"));

    })

    Page resulted by “pretty:usuarioAdmin”:

    <h:form id="registroUsuario">

    <p:growl id="growl" globalOnly="true" showDetail="false" sticky="true" />

    ...

    </h:form>

    If I remove Pretty, works fine!!

    #22837

    Hi!

    Did you add the MultiPageMessagesSupport phase listener to you configuration?

    <lifecycle>
    <phase-listener>com.ocpsoft.pretty.faces.event.MultiPageMessagesSupport</phase-listener>
    </lifecycle>

    See this chapter of the documentation for details:

    http://ocpsoft.org/docs/prettyfaces/3.3.2/en-US/html/navigation.html#navigation.faces_messages

    #22838

    What Christian said :)

    #22839

    filosofisto
    Participant

    Christian, I understand (have read article), but does not work :(

    Some idea?

    #22840

    So you added the phase listener and it is still not working? Weird.

    How do you invoke the JSF action producing the message? Via AJAX or a regular postback. Could also post your faces-config.xml?

    Or could you create a small sample app reproducing this and attach it to this thread?

    #22841

    filosofisto
    Participant

    Answers:

    How do you invoke the JSF action producing the message?

    Controller:

    package com.createprocess.creativeideas.controller;

    imports...

    @Stateful

    @ConversationScoped

    @Named

    public class RegistroUsuarioController implements Serializable {

    @Inject

    private SecurityService securityService;

    @Inject

    @Insert

    private Event<Usuario> evtInsert;

    @Begin

    public String begin() {

    return "pretty:usuarioAdmin";

    }

    @End

    public String end() {

    return "pretty:home";

    }

    public String incluir() {

    Usuario user = securityService.adicionarUsuarioAdministrador(usuario, senha);

    usuarios = null;

    evtInsert.fire(user);

    return "pretty:usuarioAdmin";

    //return "/pages/usuarios/admin/listaUsuariosAdmin.seam";

    }

    }

    Note that incluir() method throw event, and a observer method bellow put message in context:

    public class RegistroUsuarioEvent {

    @Inject

    private Messages msg;

    public void onIncluir(@Observes(during=TransactionPhase.AFTER_SUCCESS) @Insert final Usuario usuario) {

    msg.info(new BundleKey("messages", "registro_incluido_sucesso"));

    }

    }

    pretty-faces.xml:

    <?xml version="1.0" encoding="UTF-8"?>

    <pretty-config xmlns="http://ocpsoft.com/prettyfaces/2.0.4"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://ocpsoft.com/prettyfaces/2.0.4

    http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-2.0.4.xsd">

    <url-mapping id="home">

    <pattern value="/"></pattern>

    <view-id>/pages/home.seam</view-id>

    </url-mapping>

    <url-mapping id="logout">

    <pattern value="/logout"></pattern>

    <view-id>/home.seam</view-id>

    <action>#{identity.logout}</action>

    </url-mapping>

    <!-- Usuarios Admin -->

    <url-mapping id="usuarioAdmin">

    <pattern value="/usuarioAdmin"></pattern>

    <view-id>/pages/usuarios/admin/listaUsuariosAdmin.seam</view-id>

    <query-param name="cid">#{userManagementController.cid}</query-param>

    </url-mapping>

    <url-mapping id="incluirUsuarioAdmin">

    <pattern value="/incluirUsuarioAdmin"></pattern>

    <view-id>/pages/usuarios/admin/incluirUsuarioAdmin.seam</view-id>

    <query-param name="cid">#{userManagementController.cid}</query-param>

    </url-mapping>

    <url-mapping id="editarUsuarioAdmin">

    <pattern value="/editarUsuarioAdmin"></pattern>

    <view-id>/pages/usuarios/admin/editarUsuarioAdmin.seam</view-id>

    <query-param name="cid">#{userManagementController.cid}</query-param>

    </url-mapping>

    </pretty-config>

    faces-config.xml:

    <?xml version="1.0" encoding="UTF-8"?>

    <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="

    http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">

    <navigation-rule>

    <from-view-id>/login.xhtml</from-view-id>

    <navigation-case>

    <from-action>#{identity.login}</from-action>

    <from-outcome>failed</from-outcome>

    <to-view-id>/login.xhtml</to-view-id>

    </navigation-case>

    <navigation-case>

    <from-action>#{identity.login}</from-action>

    <from-outcome>exception</from-outcome>

    <to-view-id>/login.xhtml</to-view-id>

    </navigation-case>

    <navigation-case>

    <from-action>#{identity.login}</from-action>

    <from-outcome>success</from-outcome>

    <to-view-id>/pages/home.xhtml</to-view-id>

    <redirect />

    </navigation-case>

    </navigation-rule>

    <navigation-rule>

    <from-view-id>*</from-view-id>

    <navigation-case>

    <from-outcome>error</from-outcome>

    <to-view-id>/error.xhtml</to-view-id>

    </navigation-case>

    </navigation-rule>

    <lifecycle>

    <phase-listener>com.ocpsoft.pretty.faces.event.MultiPageMessagesSupport</phase-listener>

    </lifecycle>

    </faces-config>

    web.xml:

    <?xml version="1.0" encoding="UTF-8"?>

    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="

    http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <display-name>Creative Ideas</display-name>

    <context-param>

    <param-name>javax.faces.PROJECT_STAGE</param-name>

    <param-value>Development</param-value>

    </context-param>

    <servlet>

    <servlet-name>Faces Servlet</servlet-name>

    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

    <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>

    <servlet-name>Faces Servlet</servlet-name>

    <url-pattern>*.seam</url-pattern>

    </servlet-mapping>

    <session-config>

    <session-timeout>10</session-timeout>

    </session-config>

    <security-constraint>

    <display-name>Restrict access to XHTML documents</display-name>

    <web-resource-collection>

    <web-resource-name>XHTML</web-resource-name>

    <url-pattern>*.xhtml</url-pattern>

    </web-resource-collection>

    <auth-constraint />

    </security-constraint>

    <context-param>

    <param-name>com.ocpsoft.pretty.BASE_PACKAGES</param-name>

    <param-value>com.createprocess.creativeideas</param-value>

    </context-param>

    </web-app>

    listUsuariosAdmin.xhtml:

    <?xml version="1.0" encoding="UTF-8"?>

    <ui:composition xmlns="http://www.w3.org/1999/xhtml"

    xmlns:ui="http://java.sun.com/jsf/facelets"

    xmlns:f="http://java.sun.com/jsf/core"

    xmlns:h="http://java.sun.com/jsf/html"

    xmlns:p="http://primefaces.org/ui"

    xmlns:s="http://jboss.org/seam/faces"

    template="/WEB-INF/templates/default.xhtml">

    <ui:define name="content">

    <h3>Usuários Administradores</h3>

    <h:form id="registroUsuario">

    <p:growl id="growl" globalOnly="true" showDetail="false" sticky="true" />

    <p:commandButton value="Novo Usuário" action="#{registroUsuarioController.carregarIncluir}"/>

    <p:dataTable id="dataTable"

    var="user"

    value="#{usuarios}"

    paginator="true"

    rows="10"

    paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"

    rowsPerPageTemplate="5,10,15">

    <f:facet name="header">

    Usuários Administradores

    </f:facet>

    <p:column>

    <f:facet name="header">

    <h:outputText value="Usuário"/>

    </f:facet>

    <h:outputText value="#{user.usuario}"/>

    </p:column>

    <p:column style="width:25%">

    <f:facet name="header">

    <h:outputText value="Operações"/>

    </f:facet>

    <p:commandButton

    id="btnEditar"

    ajax="true"

    process="@this"

    value="Editar"

    action="pretty:editarUsuarioAdmin">

    <f:setPropertyActionListener

    target="#{registroUsuarioController.usuarioSelecionado}"

    value="#{user}"/>

    </p:commandButton>

    <p:commandButton

    id="btnExcluir"

    process="@this"

    value="Excluir"

    oncomplete="confirmation.show()">

    <f:setPropertyActionListener

    target="#{registroUsuarioController.usuarioSelecionado}"

    value="#{user}"/>

    </p:commandButton>

    </p:column>

    </p:dataTable>

    <p:confirmDialog id="confirmDialog" message="Excluir usuário selecionado?"

    header="Excluir" severity="alert" widgetVar="confirmation">

    <p:commandButton id="confirm" value="Sim" ajax="false" actionListener="#{registroUsuarioController.excluir}" />

    <p:commandButton id="decline" value="Não" onclick="confirmation.hide()" type="button" />

    </p:confirmDialog>

    </h:form>

    </ui:define>

    </ui:composition>

    Some help will be apreciate, thx.

    #22842

    Hi,

    I’m just guessing here, but perhaps TransactionPhase.AFTER_SUCCESS is too late for the PrettyFaces phase listener to capture the messages. Could you try to change this observer method to:

    public void onIncluir(@Observes @Insert final Usuario usuario) {
    msg.info(new BundleKey("messages", "registro_incluido_sucesso"));
    }

    Another possible problem could <p:growl>. Could you perhaps try to use <h:messages> to see if this helps?

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

Comments are closed.