如何正确访问 a4j:jsFunction 结果中的数据字段

发布于 2024-08-03 19:17:48 字数 1864 浏览 5 评论 0原文

我目前正在尝试使用一些服务器端方法(作为一个组)验证一些前端值,并且遇到了处理结果的问题。

下面是启动这一切的按钮的 XHTML:

<h:commandButton action="#{Bean.save()}" 
        value="Save" 
           id="save" 
      onclick="checkForConfirmation();" />

以及 javascript,按钮调用其中一部分,jsFunction 调用另一部分

function checkForConfirmation()
{
         var name = document.getElementById("path:to:name").value;
         var address = document.getElementById("path:to:address").value;
         var city = document.getElementById("path:to:city").value;
         var state = document.getElementById("path:to:state").value;
         var zip = document.getElementById("path:to:zip").value;

         jsFunc1(name, address, city, state, zip);
}
function showConfirmPrompt()
{
            if(confirm('Confirmation before save')) 
            {
                return true;
            }

            return false; 
}

最后,jsFunction 这是有问题的部分:

<a4j:form>
        <a4j:jsFunction name="jsFunc1" action="#{Bean.shouldBeConfirmed()}" data="#{Bean.booleanResult}" oncomplete="alert(data); if (data) {showConfirmPrompt();}">
            <a4j:actionparam name="param1" assignTo="#{Bean.nameToBeValidated}"/>
            <a4j:actionparam name="param2" assignTo="#{Bean.addressToBeValidated}"/>
            <a4j:actionparam name="param3" assignTo="#{Bean.cityToBeValidated}"/>
            <a4j:actionparam name="param4" assignTo="#{Bean.stateToBeValidated}"/>
            <a4j:actionparam name="param5" assignTo="#{Bean.zipToBeValidated}"/>
        </a4j:jsFunction>
    </a4j:form>

问题是,到最后在这一系列事件中,“oncomplete”属性中的警报(数据)显示数据未定义。我需要定义它才能知道是否显示警告对话框。

我可以确认 Bean.shouldBeConfirmed() 方法确实正在运行,并且具有正确的参数,并且确实返回了正确的值,甚至设置了 Bean.booleanResult 变量的值(这是一个普通的 java 布尔值)。我在这里做错了什么?

I am currently trying to validate some front-end values with some server-side methods (as a group) and am running into issues dealing with the result.

Here is the XHTML for the button that starts it all:

<h:commandButton action="#{Bean.save()}" 
        value="Save" 
           id="save" 
      onclick="checkForConfirmation();" />

And the javascript, part of which the button calls, the other part of which the jsFunction calls

function checkForConfirmation()
{
         var name = document.getElementById("path:to:name").value;
         var address = document.getElementById("path:to:address").value;
         var city = document.getElementById("path:to:city").value;
         var state = document.getElementById("path:to:state").value;
         var zip = document.getElementById("path:to:zip").value;

         jsFunc1(name, address, city, state, zip);
}
function showConfirmPrompt()
{
            if(confirm('Confirmation before save')) 
            {
                return true;
            }

            return false; 
}

And finally, the jsFunction which is the problematic piece:

<a4j:form>
        <a4j:jsFunction name="jsFunc1" action="#{Bean.shouldBeConfirmed()}" data="#{Bean.booleanResult}" oncomplete="alert(data); if (data) {showConfirmPrompt();}">
            <a4j:actionparam name="param1" assignTo="#{Bean.nameToBeValidated}"/>
            <a4j:actionparam name="param2" assignTo="#{Bean.addressToBeValidated}"/>
            <a4j:actionparam name="param3" assignTo="#{Bean.cityToBeValidated}"/>
            <a4j:actionparam name="param4" assignTo="#{Bean.stateToBeValidated}"/>
            <a4j:actionparam name="param5" assignTo="#{Bean.zipToBeValidated}"/>
        </a4j:jsFunction>
    </a4j:form>

The problem is that, towards the end of this chain of events, the alert(data) in the 'oncomplete' attribute shows that the data is undefined. I need this to be defined in order to know whether or not to show a warning dialogue.

I can confirm that the Bean.shouldBeConfirmed() method is indeed running, and with the right parameters, and indeed returning the correct value, and even setting the value of the Bean.booleanResult variable (which is a normal java boolean). What am I doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悍妇囚夫 2024-08-10 19:17:48

虽然这是一个很老的问题,但我在 Richfaces 4 M3 上也遇到了同样的问题。 Yev 建议的参数不起作用。因此参考了 richfaces 的 JIRA
据此,这是一个错误(处于“无法修复”模式,不知道为什么!)
所以现在的解决方法是使用
事件数据
而不是
数据
oncomplete 处理程序中。
我测试过并且确实有效:)

Though this is a very old question, I had the same issue with Richfaces 4 M3. Parameteres suggested by Yev didn't work. So referred to richfaces's JIRA.
According to which, it is a bug (which is in "won't fix" mode, don't know why!)
So for now the workaround is to use
event.data
instead of
data
in the oncomplete handler.
I tested and it does work :)

得不到的就毁灭 2024-08-10 19:17:48

我的设置与您的设置完全一样,并且它对我有用。唯一的区别是,我在 jsFunction 上有额外的属性:

    <a4j:form>
    <a4j:jsFunction name="jsFunc1" 
        action="#{Bean.shouldBeConfirmed()}" 
        data="#{Bean.booleanResult}" 
        oncomplete="alert(data);"
        ignoreDupResponses="true"
        eventQueue="foo">
        ...

并且我的数据(您的 booleanResult)是一个 int。工作正常。

I have it exactly as your setup and it works for me. The only difference is, I have extra attributes on jsFunction:

    <a4j:form>
    <a4j:jsFunction name="jsFunc1" 
        action="#{Bean.shouldBeConfirmed()}" 
        data="#{Bean.booleanResult}" 
        oncomplete="alert(data);"
        ignoreDupResponses="true"
        eventQueue="foo">
        ...

And my data (your booleanResult) is an int. Works fine.

又怨 2024-08-10 19:17:48

我也面临同样的问题。如果是布尔结果,我们需要编写完整的方法名称,而不是删除 getter...
就像你的情况一样,它应该是 #{Bean.isBooleanResult}....
如果遇到问题请告诉我...

I have also face the same problem.. In case of Boolean results we need to write full method name instead removing getter...
like in your case it should be #{Bean.isBooleanResult}....
Let me know if face problem...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文