Ikthiander
Ikthiander

Reputation: 3917

calling a javascript from a4j:jsFunction in richfaces 3.3.3

i have a javascript which i put in the extraHeaderContent:

<ui:define name="extraHeaderContent">
    </script> -->
    <script type="text/javascript">
    function getTimezoneName() {
        var timezone = jstz.determine_timezone();
        return timezone.name();
    }
    </script>
</ui:define>

i want to use this script to get the time zone and then to use it in a4j:jsFunction like this:

<a4j:jsFunction name="getTimezoneName" data="#{usertimezone.userTimeZone}" >
             <a4j:actionparam name="userTimeZone" 
                              assignTo="#{usertimezone.userTimeZone}"
                              />
</a4j:jsFunction>

or even like this:

<a4j:jsFunction action="#{usertimezone.prepareTimeZone()}" >
             <a4j:actionparam name="userTimeZone" 
                              value="getTimezoneName()"
                              assignTo="#{usertimezone.userTimeZone}"
                              noEscape="true"/>
</a4j:jsFunction>

but none of these are working. what am i doing wrong?

Upvotes: 0

Views: 4253

Answers (1)

DaveB
DaveB

Reputation: 3083

I think you have confused how a4j:jsFunction works, it allows you to trigger a serverside method from javascript (you seem to be trying to work the other way around)

For example...

<a4j:jsFunction name="myJavascriptMethod" action="#{myActionBean.myJavaMethod}" >
    <a4j:actionparam name="param" assignTo="#{myActionBean.beanParam}"/>
</a4j:jsFunction>

<script>
    var param = "foo";
    myJavascriptMethod(param);
</script>

Upvotes: 2

Related Questions