dojo.ById不工作

时间:2014-03-20 16:06:01

标签: javascript dojo xpages

我有一个正常运行的日历小部件。我遇到的问题是选择日期时 - 代码找不到我想要设置到所选日期的字段,我不知道为什么不这样做。

    <xp:panel id="calendarHolder">
        <script>
            require([ "dijit/Calendar", "dojo/date", "dojo/domReady!", "dijit/registry" ],
            function(Calendar, date){ 
            new Calendar({ value: new Date(),

            onValueSelected: function(date){calendarDateClicked(date);
                    }},"mycal");

            //Set month in correct format
            function setMonth(month){
                switch(month)
                {
                case 1:
                month = "Jan";
                break;
                case 2:
                month = "Feb";
                break;
                case 3:
                month = "Mar";
                break;
                case 4:
                month = "Apr";
                break;
                case 5:
                month = "May";
                break;
                case 6:
                month = "Jun";
                break;
                case 7:
                month = "Jul";
                break;
                case 8:
                month = "Aug";
                break;
                case 9:
                month = "Sep";
                break;
                case 10:
                month = "Oct";
                break;
                case 11:
                month = "Nov";
                break;
                case 12:
                month = "Dec";
                break;
                }
                return month;
            }
            //create Click action
            function calendarDateClicked(date){
                var d = new Date(date);

                var month = (d.getMonth() + 1);
                month = setMonth(month);
                var day = '' + d.getDate() + ",";
                var year = d.getFullYear();

                var dateString = [month,day,year].join(" ");

        dojo.byId('#{id:hiddenCalWidgetSelectedDate}').value = dateString

                dojo.byId('#{id:calDate}').value = dateString;
                XSP.partialRefreshPost("#{id:mainPanel}",{
                    onComplete: function() {
                        XSP.partialRefreshGet("#{id:sideViews}", {});
                    }
                });//Post Value to server
            }

             });
        </script>

        <div id="mycal">
        </div>
        <div id="textbox">
        <xp:inputText id="hiddenCalWidgetSelectedDate"
                style="display:block;" value="#{sessionScope.selectedDate}">
                <xp:this.defaultValue><![CDATA[#{javascript://
var d = new Date(/*Today*/);
var month = '' + (d.getMonth() + 1);
var day = '' + d.getDate();
var year = d.getFullYear();

    if (month.length < 2) month = '0' + month;
    if (day.length < 2) day = '0' + day;

    return [day,month,year].join("/");  }]]></xp:this.defaultValue>
</xp:inputText></div>
</xp:panel>

我得到的错误是dojo.byId(&#39;#{id:hiddenCalWidgetSelectedDate}&#39;)为空

任何帮助都将不胜感激。

格雷姆

1 个答案:

答案 0 :(得分:5)

如果将正常的脚本块添加到XPage,EL将无法解析。

您必须在 xp:scriptBlock 中添加代码。