Re: PrettyFaces eating FacesMessage!?!?!!?

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

#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.