简体   繁体   English

从a4j调用javascript:在richfaces 3.3.3中使用jsFunction

[英]calling a javascript from a4j:jsFunction in richfaces 3.3.3

i have a javascript which i put in the extraHeaderContent: 我有一个javascript,我把它放在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中使用它,如下所示:

<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? 我究竟做错了什么?

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) 我认为你已经混淆了a4j:jsFunction如何工作,它允许你从javascript触发服务器端方法(你似乎试图以相反的方式工作)

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM