Using JavaScript in Page Flow and Portal Applications

 

The following topic explains how to access page elements, such as forms and user input elements, with JavaScript.

Limitations of Traditional Naming Techniques

In a stand alone web application, JavaScript typically accesses page elements by the id and name attributes. Page elements are given unique id or name attributes...

        <form name="myForm" onSubmit="return validateForm()" action="myAction">
           First Name: <input type="text" id="firstName"><br>
           Last Name:  <input type="text" id="lastName"><br>
           <input type="submit" value="Submit">
        </form>
在一个卓越的web程序中,通常Javascript通过id和name属性来访问页面元素。页面元素被赋予唯一的
id或者name属性。

...and then the page elements are accessed by JavaScript functions which refer to the id and name attributes...

        <script language="JavaScript">
        function validateForm() 
        {
            var error_message = "";
            if (document.myForm.firstName.value =="") error_message += "- your first name /n";
            if (document.myForm.lastName.value =="") error_message += "- your last name /n";
            if(error_message) 
            {
                alert("Please fill in the following fields:/n" + error_message);
                return false; 
            }
            return true; 
        }
        </script>

But when a web application is incorporated into a Portal application, this JavaScript technique does not suffice. This is because Portal applications may contain a collage of different web applications, with no guarantee that the page elements have unique id or name attributes. If two applications in the Portal each have page elements with the same id or name attributes, there is no way for JavaScript to access the one of these page elements, since JavaScript will always return the first page element it encounters as it searches for an element with a specified name or id. For this reason, Portal applications can be made to rewrite the name and id attributes of page elements, to ensure that each page element in the Portal has a unique identifier.

但当一个web程序被合并到一个Portal程序中,这项javascript技术没有效果。这是因为Portal程序可能包含不同web程序的拼接,无法保证页面元素具有相同的id或name属性。javascript总是返回它遇到的第一个id或者name相符的页面元素。因此,Portal程序可以
用来改写页面元素的id和name属性,以确保页面元素具有唯一的标识符。

Ensuring Unique Names for Each Page Element

To ensure that Page Flow page elements have unique identifiers inside a Portal, use the tagId attribute to identify the page elements. Workshop will append Portal and portlet context information to the tagId and write the result to the id and name attributes that are rendered in the browser. For example, the following Page Flow elements have been given tagId attributes.

通过使用tagId属性来标识页面元素,来保证Page Flow页面元素有唯一的标识符。

            MyJSP.jsp

        <netui:form tagId="myForm" onSubmit="return validateForm2()" action="myAction2">
           First Name: <netui:textBox tagId="firstName" dataSource="{actionForm.firstName}"/><br>
           Last Name:  <netui:textBox tagId="lastName" dataSource="{actionForm.lastName}"/><br>
           <netui:button type="submit" value="Submit"/>
        </netui:form>

When these Page Flow elements are contained in a Portal, they are rendered in the browser as the following HTML. Notice that Workshop has rewritten the id attributes to include context information about the Portal and portlet in which the Page Flow elements appear.

        <form id="portlet_3_1myForm" method="post" οnsubmit="return validateForm()">
            First Name: <input type="text" id="portlet_3_1{actionForm.firstName}" value=""/><br>
            Last Name:  <input type="text" id="portlet_3_1{actionForm.lastName}" value=""/><br>
           <input type="submit" value="Submit"/>
        </form>

Accessing Page Elements with JavaScript

To ensure that these page elements are available to client-side JavaScript, Workshop also provides a mapping function, getNetuiTagName( tagId, tag ), that maps the tagId values to the re-written id (and name) values that are rendered in the browser. The mapping is encoded into a JavaScript object written to the HTML source of the page.

为了确保客户端javascript能够访问页面元素,Workshop提供了一个映射函数getNetuiTagName( tagId, tag )

        // Build the netui_names table to map the tagId attributes
        // to the real id written into the HTML
        if (netui_names == null)
           var netui_names = new Object();
        netui_names.myForm="portlet_3_1myForm"
        netui_names.firstName="portlet_3_1{actionForm.firstName}"
        netui_names.lastName="portlet_3_1{actionForm.lastName}"

The function getNetuiTagName( tagId, tag ) reads this mapping object to retrieve the actual id or name attribute rendered in the browser.

The following JavaScript expression accesses the form element on the page MyJSP.jsp above.

        document[getNetuiTagName("myForm",this)]

The function call getNetuiTagName( "myForm", this ) resolves to the value portlet_3_1myForm. So the JavaScript expression points at the form element on the page.

        document["portlet_3_1myForm"]

To access the firstName element on MyJSP.jsp above, use the following JavaScript expression.

        document[getNetuiTagName("myForm",this)][getNetuiTagName("firstName",this)]

The following JavaScript function performs simple client-side validation on MyJSP.jsp.

        <script language="JavaScript">        
        function validateForm() 
        {
            var error_message = "";
            if (document[getNetuiTagName("myForm",this)][getNetuiTagName("firstName",this)].value =="") error_message += "- your first name /n";
            if (document[getNetuiTagName("myForm",this)][getNetuiTagName("lastName",this)].value =="") error_message += "- your last name /n";
            if(error_message) 
            {
                alert("Please fill in the following fields:/n" + error_message);
                return false; 
            }
            return true; 
        }        
        </script>

Passing the tagId Value to HTML Tags.

If you need to pass the value of the tagId attribute to an HTML tag, use the <netui:getNetuiTagName> tag. The <netui:getNetuiTagName> returns the value of a specified tagId attribute. In the following example, the HTML tag <label> is given access to the value of the tagId attribute.

    <netui:form action="processData">
        <netui:radioButtonGroup dataSource="{actionForm.selection}">
            <label for="<netui:getNetuiTagName tagId="radio1"/>">Display Text 1</label><netui:radioButtonOption tagId="radio1" value="value1"/><br>
            <label for="<netui:getNetuiTagName tagId="radio2"/>">Display Text 2</label><netui:radioButtonOption tagId="radio2" value="value2"/><br>
            <label for="<netui:getNetuiTagName tagId="radio3"/>">Display Text 3</label><netui:radioButtonOption tagId="radio3" value="value3"/><br>
        </netui:radioButtonGroup>    
        <netui:button value="Submit" />
    </netui:form>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用Matlab、Simulink和Stateflow进行控制算法建模的指导方法是: 1. 熟悉Matlab、Simulink和Stateflow工具:了解这些工具的基本功能、界面和操作方法,掌握其使用技巧和快捷键。 2. 确定模型的目标和需求:明确控制算法的设计目标和系统需求,例如控制稳定性、响应速度、鲁棒性等。 3. 确定模型的输入、输出和系统状态:将控制系统的输入、输出和状态变量明确定义,并结合具体应用场景进行合理选择。 4. 设计控制算法:根据控制系统的输入、输出和状态变量,设计合适的控制算法,包括传统控制算法如PID算法,以及现代控制方法如模型预测控制等。 5. 使用Simulink进行模型建立:根据控制算法的设计思路,使用Simulink工具建立控制系统的模型,包括各个子系统、传感器、执行器等组件的建模。 6. 使用Stateflow进行逻辑建模:对于有复杂逻辑的控制系统,使用Stateflow工具进行状态机建模,明确控制算法的状态转移和决策逻辑。 7. 参数调整和仿真验证:根据实际系统的特性和设计要求,对控制算法的参数进行调整,并使用Simulink进行仿真验证,评估系统性能和算法效果。 8. 优化和改进:根据仿真结果,对控制算法进行优化和改进,提高系统性能和稳定性。 9. 进行实际系统的实施和测试:将优化后的控制算法实施到实际系统中,并进行测试和调试,验证控制算法的实际效果。 10. 持续学习和改进:掌握新的控制算法和工具的应用方法,进行持续学习和改进控制系统的性能和稳定性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值