Calling javascript function on Managed bean

Asked

Viewed 572 times

0

I am using the JSF framework with primefaces 6.0 and as I am new, I am having difficulty calling a javascript when finishing a bean method with scope @Requestscoped. How can I do that? Is there any other way using this scope?

I want to call a script to show a feedback notification of the result to the user.

Remembering that there may be an error when starting the page in @Postconstruct init, the bean initializer method, so I need to call the script without action from a button.

1 answer

2


But Javascript is really necessary?

Since you use Primefaces, I think it would be ideal to have a p:messages or p:Growl component on the screen and add your message by the bean when finishing the method using:

//... Seu código
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Feedback para o usuário"));

I usually encapsulate this code in a superclass add() method, but it’s up to you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.