trigger growl message from javascript

UI Components for JSF
jersingh
Posts: 9
Joined: 17 Feb 2012, 10:36

27 Feb 2012, 21:47

I'm doing client-side/javascript validation and would like to trigger the primefaces growl mechanism (which I think is jQuery) just to be consistent with some of the server-side validation that takes place in the app.

Is it possible to trigger a growl popup in javascript?

In this link: viewtopic.php?f=3&t=13399&p=40408&hilit ... owl#p40408 - it sounds like that's not possible but thought I'd ask for clarification.

Thanks,
Joe
PrimeFaces 3.2 | GlassFish 3.1.2 | Mojarra 2.1.6 (SNAPSHOT 20111206)
NetBeans 7.1.2 | JDK1.6 | Java EE 6
Windows 7 (64bit)

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

27 Feb 2012, 21:54

It's possible - just check the renderer!
But it's not user friendly.
Maybe you could create an feature to enhance the growl widget with some client side methods?
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

27 Feb 2012, 22:45

Already available in client side api;

Code: Select all

<p:growl widgetVar="g" />
Example with info message;

Code: Select all

g.renderMessage({summary:'infooo text', detail: 'detaaaaaaail text', severity: 0});
You need the jar below to use this as client side api of growl change a bit since 3.x.

http://repository.primefaces.org/org/pr ... -SNAPSHOT/

There is also .show(msgs) method where msgs is an array of message objects.

Use removeAll to hide all messages.

See;

http://code.google.com/p/primefaces/sou ... l/growl.js

jersingh
Posts: 9
Joined: 17 Feb 2012, 10:36

28 Feb 2012, 19:20

Works like a champ! Thanks!
PrimeFaces 3.2 | GlassFish 3.1.2 | Mojarra 2.1.6 (SNAPSHOT 20111206)
NetBeans 7.1.2 | JDK1.6 | Java EE 6
Windows 7 (64bit)

march_in
Posts: 14
Joined: 08 Mar 2012, 12:34

06 Apr 2012, 13:58

heisenberg wrote:Already available in client side api;

Code: Select all

<p:growl widgetVar="g" />
Example with info message;

Code: Select all

g.renderMessage({summary:'infooo text', detail: 'detaaaaaaail text', severity: 0});
You need the jar below to use this as client side api of growl change a bit since 3.x.

http://repository.primefaces.org/org/pr ... -SNAPSHOT/

There is also .show(msgs) method where msgs is an array of message objects.

Use removeAll to hide all messages.

See;

http://code.google.com/p/primefaces/sou ... l/growl.js
there is no renderMessage method in 3.1.1. Your solution works only in 3.2.
PrimeFaces 3.2| WebLogic 12c | Mojarra (JSF 2.0,1.0.0.0_2-0-2)
NetBeans 7.1.1 | JDK1.7 | Java EE 5
Windows 7, Google Chrome, Firefox, IE9

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

06 Apr 2012, 14:07

Yes, so? That is wat Heisenberg said...

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

06 Apr 2012, 14:13

As I've said, it has been added as of 3.2.

Btw, I've made that old post during 3.2 development, as of 3.2 final better to use.

Code: Select all

growl.show([{summary:'infooo text', detail: 'detaaaaaaail text', severity: 'info'}, {summary:'warn text', detail: 'detail text', severity: 'warn'}])
show(msgs) removes currently displayed messages and adds msgs.

march_in
Posts: 14
Joined: 08 Mar 2012, 12:34

06 Apr 2012, 14:26

tnx you said 3.x ;)
In your old post you wrote "severity: 0". severity better works in new post. thank you.
PrimeFaces 3.2| WebLogic 12c | Mojarra (JSF 2.0,1.0.0.0_2-0-2)
NetBeans 7.1.1 | JDK1.7 | Java EE 5
Windows 7, Google Chrome, Firefox, IE9

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

06 Apr 2012, 14:31

The link I provided was 3.2-SNAPSHOT.

Whatever, api is there now. :)

luckypier
Posts: 1
Joined: 26 Sep 2012, 20:25

26 Sep 2012, 22:06

Hi, i'm new with primefaces,
i was trying to show the some message in the growl, but why does this doesn't work?

Code: Select all

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

<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<link type="text/css" rel="stylesheet"
		href="#{request.contextPath}/javax.faces.resource/theme.css.xhtml?ln=primefaces-#{aplicacionManaged.theme}" />
	<script>

        function muestra(){
        	jQuery('#growl').show([{
                summary:'infooo text', 
                detail: 'detaaaaaaail text', 
                severity: 'info'}, 
                {
                    summary:'warn text', 
                    detail: 'detail text', 
                    severity: 'warn'
                }]);
        }
    </script>
</h:head>

<h:body>

	<p:growl id="growl" showDetail="true" life="5000" />

	<p:dialog visible="true" id="dialog" header="Login" widgetVar="dlg">
		<h:form>

			<h:panelGrid columns="2" cellpadding="5">

				<f:facet name="footer">
					
					<p:commandButton value="Click Me" type="button" onclick="muestra();" />	
				</f:facet>
			</h:panelGrid>
			
		</h:form>
	</p:dialog>

</h:body>
</html>
Please help!!!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: speandHap and 31 guests