Yes, I'm still here but I'm in a different timezone than all of you. So all this was going on at 3am my time and I was getting some much needed sleep =P

Anyways, this is an issue that I never quite solved either. I kind of put it on the sidelines because I had other more important things to tackle, but I would prefer a solution that uses a PhaseListener to scan for global messages after rendering and put them in the session. Then, have them put back into the JSF message queue in the before the first phase. The biggest problem I have with this solution is getting rid of the messages. Ideally, what would happen is that they are removed when they are displayed (I can't think of any use-cases where you'd want to have the global messages displayed twice on the same page). So I'm thinking of creating a custom message display component some time down the road that dequeues messages as they are displayed.

So that's my 2 cents.

Rich

Johannes Hiemer wrote:

Hi,
good to know, that there another ways to do it. In my solution the problem with a PhaseListener would be, that I need to get the current instance of a BaseController, or is it possible to save values to a phaseListener, and to dispense with my BaseController completly?

Richard are you still alive? :-)  What do you think?

Regards Johannes
"MyFaces Discussion" <[email protected]> schrieb am 05.08.05 11:24:28:
I don't know if this can helps you but there is the way to handle
messages throw redirects, the Matt Raible' way  into appFuse/JSF :


the message filter :
https://appfuse.dev.java.net/source/browse/appfuse/extras/jsf/src/web/org/appfuse/webapp/filter/MessageFilter.java?rev=1.1&view=auto&content-type=text/vnd.viewcvs-markup

the BasePage with addMessage method
https://appfuse.dev.java.net/source/browse/appfuse/extras/jsf/src/web/org/appfuse/webapp/action/BasePage.java?rev=1.1&view=auto&content-type=text/vnd.viewcvs-markup







2005/8/5, Martin Marinschek <[EMAIL PROTECTED]>:
---------- Forwarded message ----------
From: Martin Marinschek <[EMAIL PROTECTED]>
Date: Aug 5, 2005 11:05 AM Subject: Re: Messages and navigation rule redirects post
To: Johannes Hiemer <[EMAIL PROTECTED]>

Nice solution,

even though a bit verbose... You might want to try a phase-listener wich
you add before the render response phase and which checks for this bean and
adds the messages to the context instead of doing that in a bean as well.

regards,

Martin


On 8/5/05, Johannes Hiemer < [EMAIL PROTECTED]> wrote:
Hi Richard, Hi Martin,
perhaps I got something. I took my time this morning and spend it trying
some things. In my implementation I got a standard BaseController for all my
handlers. So I thought, why should I use this BaseController to save this
message for a while. After a few minutes I got a working solution.
Here is my code:

##### BaseController #####

private static FacesMessage notification;

       /**
* @return Returns the notification. */
       public FacesMessage getNotification() {
               return notification;
       }

       /**
        * @param notification The notification to set.
        */
public void setNotification(FacesMessage notification) { this.notification = notification;
       }

###### faces-config.xml ########

<managed-bean>
<managed-bean-name>BaseController</managed-bean-name>
<managed-bean-class>
itecon.web.resource.BaseController
               </managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

This is my BaseController, now we get to the SparepartHandler.java where
actually the first stept happens.
public String add() {
               message = this.getMessage();
                log.info (message);
               String notification =
Utils.getMessageResourceBundle(getBundle(), "internalDatasetExists", null,
getLocale());
               setNotification(new
FacesMessage(FacesMessage.SEVERITY_INFO, notification, notification));
               return message;
       }

As you can see, I get my notification from my ResourceBundle of the
Application. After the I put it through BaseController.setNotification into
my private static FacesMessage notification;
Till here - fine.

No I have a second managed bean called: NotificationHandler.

##### NotificationHandler.java #######

public class NotificationHandler extends BaseController implements
Serializable {
       private String hiddenField = null;

       public void pageLoad() {
               log.info(getNotification());
               facescontext.addMessage("globalMessage",
getNotification());
       }

       /**
        * @return Returns the hiddenField.
        */
       public String getHiddenField() {
               return hiddenField;
       }

/** * @param hiddenField The hiddenField to set.
        */
       public void setHiddenField(String hiddenField) {
               this.hiddenField = hiddenField;
       }
}

The hiddenField was created because I don't know another way to initialize
the managed-bean through my success.jspx
That's my managed bean in my faces-config.xml

###### faces-config.xml #####
<managed-bean>
<managed-bean-name>notificationSpringBean</managed-bean-name>
<managed-bean-class>
itecon.web.controller.NotificationHandler
               </managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>pageLoad</property-name>
                       <value>true</value>
               </managed-property>
       </managed-bean>

And last but not least my success.jspx.

####### success.jspx ######

<h:form id="form">
       <h:panelGrid columns="3" styleClass="parentTable"
headerClass="tableHeader" columnClasses="childTable">
               <f:facet name="header">
                       <h:outputText id="closer"
value="YIIPPIIEIIOOO SCHWEINEBACKE" />
               </f:facet>
               <h:inputHidden id="hiddenField"
value="#{notificationSpringBean.hiddenField}" />
               <x:messages id="globalMessage" layout="table"
               showSummary="true" showDetail="false" />
       </h:panelGrid>
</h:form>


As attachement the result.
To proove it:
Here the extract of my Resources.properties
internalDatasetExists=Dataset already exists
Try it, tell me If I am wrong, or if there better ways to do it.

Regards Johannes


______________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS! Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193





--

hicham ABASSI
[EMAIL PROTECTED]


______________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193


Reply via email to