XPages getComponent()无法正常工作 [英] XPages getComponent() doesn't work correctly

查看:106
本文介绍了XPages getComponent()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XPage,它使用JQuery对话框和客户端验证来验证用户处理的输入.问题是,当我单击添加"按钮时,客户端验证有效,但是在服务器端找不到这些字段的属性.当用户单击打开对话框"按钮时,将显示对话框,这是魔术发生的地方,这是我的按钮(例如,只有一个属性):

I have an XPage which uses JQuery dialog and client-side validation to validate the input the user processes. The problem is that when I click Add button client-side validation works, but properties from those fields 'cannot ' be found on server side. When the user clicks 'Open dialog' button the dialog shows up and Here's my button where the magic happens(only one property, just for example):

<xp:button id="save_part_btn" value="+Add" style="float:right;">
             <xp:eventHandler event="onclick" submit="true"
                refreshMode="complete">
                <xp:this.action><![CDATA[#{javascript:
                    /*          
                    var estdoc:NotesDocument=database.getDocumentByUNID(doc_source.getDocument().getParentDocumentUNID())
                    var estPartdoc:NotesDocument=estdoc.getParentDatabase().createDocument()

                    Ignore it

                    estPartdoc.replaceItemValue('Form','Estimate_Cost_Part')
                    estPartdoc.replaceItemValue('Predoc',estdoc.getUniversalID())
                    estPartdoc.replaceItemValue('$OSN_IsSaved','1')
                    */

                    estPartdoc.replaceItemValue('TSNB_All',getComponent('input_tsnb_all').getValue())

                }]]></xp:this.action>

                        <xp:this.script><![CDATA[ 

                            var isValid = true;
                            var result = "";

                            function isStringEmpty(string2Check) 
                            {
                                return string2Check == "" || string2Check[0] == " ";
                            }

                            function isNumberCorrect(number2Check) 
                            {
                                return /^[1-9]\d*(,\d{1,3})?$/.test(number2Check.toString());
                            }


                            if(isStringEmpty(document.getElementById("#{id:input_tsnb_all}").value)) 
                            {
                                wholeValid = false;
                                result += '-The field cannot be empty\n'
                            }
                            else if(!isNumberCorrect(document.getElementById("#{id:input_tsnb_all}").value)) 
                            {
                                wholeValid = false;
                                result += '-The field is not correct\n'
                            }

                            if(!isValid)    
                            alert(result) 
                            return isValid;  

                ]]></xp:this.script>
            </xp:eventHandler>
</xp:button>

客户端验证非常有效-当用户输入不正确时,将显示alert消息.但是,在服务器端找不到input_tsbn_all,并且无法创建具有此属性的文档.确实可以,但是null中的input_tsbn_all的值.有什么问题吗?

Client-side validation works perfectly - when the user's input is incorrect alert message gets displayed. However, input_tsbn_all cannot be found on the server side and the document with this property can't not be created. Actually it does, but the input_tsbn_all's value in null. What is the problem?

该属性的标记为:

<xp:tr>
    <xp:td><xp:label value="All:"/></xp:td>
       <xp:td>
          <xp:inputText id="input_tsnb_all"
                            disableClientSideValidation="true"
                            styleClass="doc_field_textinput"  size="40" >
            <xp:this.converter>
                    <xp:convertNumber pattern="0.000"></xp:convertNumber>
            </xp:this.converter>
            </xp:inputText>
    </xp:td>
</xp:tr>

我的JQuery代码:

My JQuery code:

    var dialogAddPartDiv = $('.dialogAddPart'); 

      $('.addButton').click(function() 
      {
        dialogAddPartDiv.dialog('open');
      });

      dialogAddPartDiv.dialog(
      {
      create: function (event, ui) {


                    $(".ui-corner-all").css('border-bottom-right-radius','8px');
                    $(".ui-corner-all").css('border-bottom-left-radius','8px');
                    $(".ui-corner-all").css('border-top-right-radius','8px');
                    $(".ui-corner-all").css('border-top-left-radius','8px');

                    $(".ui-dialog").css('border-bottom-left-radius','0px');
                    $(".ui-dialog").css('border-bottom-right-radius','0px');
                    $(".ui-dialog").css('border-top-left-radius','0px');
                    $(".ui-dialog").css('border-top-right-radius','0px');

                    $('.ui-dialog-titlebar-close').css('margin', '-25px -20px 0px 0px').css('border', 'solid 2px').css('border-radius', '15px').css('border-color', '#05788d');
                    $('.ui-dialog-titlebar-close').css('width', '25px').css('height', '25px');
                },

        autoOpen: false,
        modal: true,
        beforeClose : function(event) 
        {
            if(!confirm("This won't be saved. Continue?"))
            {
            return false;
            }
            else 
            {

            }
        },
        width:600,
        resizable: false
      });
document.getElementsByClassName('ui-dialog-titlebar-close')[0].setAttribute('title', 'Close it?');

隐藏的div只是在页面上这样声明:<xp:div styleClass="dialogAddPart">

And the hidden div is just declared on the page like this: <xp:div styleClass="dialogAddPart">

推荐答案

您需要将输入绑定到通过请求持续存在的对象属性.一个愚蠢的例子可能是利用作为地图的viewScope对象.

You need to bind your input to a object property that persists through request. A silly example could be exploiting the viewScope object that is a Map.

<xp:inputText id="input_tsnb_all" value="#{viewScope.myInput}">
    ...

您稍后将在代码中执行的操作将是查找viewScope.myInput变量以执行所需的操作,而不是在ViewRoot树中查找组件.

What you would later on do in the code would be to look up the viewScope.myInput variable to do what you want with it, rather than finding the component in the ViewRoot tree.

对您来说,最好的建议是鼓励您建立一些JSF基础知识,以便理解为什么用这种方式来完成事情.

My best advice for you is to encourage you to build up some JSF fundamentals in order to understand why things are done this way.

A,XPages使JSF的最坏迭代成为可能,从而可以正确地学习事物.它大部分都推动了一个基础概念-旧的Notes开发人员思维方式-阻止您按其预期的方式使用该框架,即MVC.

Alas, XPages makes it for the worst possible iteration of JSF where to learn things in the right way. Most of it pushes an underlying concept - the old Notes developer mindset - that prevents you from working the framework in the way it is intended, that is MVC.

我不会告诉您避免这样做,因为您在Internet上看到的有关该主题的大部分内容都是老式汤.但是,即使您稍加关心,也可以阅读一本不太新的JSF书籍并从那里学习.或者,免费,您可能想在这里.当然,您将需要将阅读的内容与XPages中实际可用的内容进行中介,因为很遗憾,XPages本身就是对JSF的解释.

I'm not going to tell you to avoid doing that because much of what you see on the Internet about the topic is that old fashioned soup. But if you care, even a little, take a not too new JSF book and learn from there. Or, for free, you might want to have a look here. Of course, you will need to mediate what you read with what is actually available in XPages since, as I sad, XPages is an interpretation of JSF in its own right.

这篇关于XPages getComponent()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆