سؤال

I have a commandLink which calls a backend page bean method. but I want to make a delay before it calls that method. How to do this using javascipt or primefaces?

هل كانت مفيدة؟

المحلول

PrimeFaces offers p:remoteCommand. It can be called via javascript and execute, do action and ajax process and updates. Use the p:commandLink to call a javascript function with a timeout. In short

<p:commandLink onclick="delayIt()" />

<p:remoteCommand name="remoteCommandName" ... action ... update ... process/>


<script type="text/javascript">
    var delayIt = function(){
       setTimeout( remoteCommandName,5000) //don't write () as it would execute it immediately
    }
</script>

نصائح أخرى

In primefaces try 'delay' as attribute. delay is null as default.

<p:commandLink id="clid" actionListener="#{buttonView.buttonAction}" delay="1000">
    <h:outputText value="text" />
</p:commandLink>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top