How to run a JS or jQuery function after an update, Reload in JSF and Primefaces?

Asked

Viewed 2,504 times

1

I need to run this function after a button gives an update="@form" on the page

<script type="text/javascript">
    function carregaCss(){
        $(".ui-icon-calendar").addClass("glyphicon glyphicon-calendar corPadrao");
        $(".ui-icon-seek-first").addClass("glyphicon glyphicon-backward corPadrao");
        $(".ui-datepicker-next span").addClass("glyphicon glyphicon-circle-arrow-right");
    }
</script>

It works in the page header, but when the ajax update is executed it does not work and the icons do not receive the classes they should receive..

  • Run the function in ajax update callback...

  • Is wearing a commandButton? Take a look at the attribute onComplete to call this function.

2 answers

1

To make the solution generic, put a call to the function inside the form.

So, every time an update is performed on form, the function will be called again, independent of the component that updated the form.

When the form is rendered again, the function will be called again

The idea is that it looks like:

<h:form>
 <script type="text/javascript">
  carregaCSS();
 </script>
...
  • 1

    Today I went through a similar situation and Felipe’s response was very useful..

0

I do so:

<p:commandButton ... update="@form" oncomplete="carregarCss()" />

the oncomplete is executed whenever the request made by the component is successfully executed. It is equivalent to Success ajax.

  • I tried this and it didn’t work, because when a field updates @form the css comes out and doesn’t work anymore, because it’s not just the buttons that give update="@form"

  • Selector classes are lost when updating components?

  • That.. If lost, do not update along with the form

  • You can’t use the attribute styleClass in these components to be able to search for later?

  • @Gerson, can you get the components using id or something else? I think the answer from Felipe Fonseca will help you, put it at the bottom of the page and see if it works.

Browser other questions tagged

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