`
congpeixue
  • 浏览: 269843 次
  • 性别: Icon_minigender_1
  • 来自: ...
社区版块
存档分类
最新评论

Click framework 的 Page类(三)

阅读更多
导航
页面之间的导航是通过forwards, redirects 及设置页面模板的路径来实现的 。

Forward

为了迁移到另一个页面, 可以通过使用Servlet的RequestDispatcher来设置Page的forward属性.

例如通过路径index.htm来迁移到另一个页面。
/**
 * @see Page#onPost()
 */
public void onPost() {
   // Process form post
   ..
   
   setForward("index.htm");
} 
上述代码将调用一个新的映射为路径index.htm的page类。

Note: 当一个请求被定位到另一个页面时, 此时, 位于第二个页面的控件仍未被执行。
这样可以防止混乱和bug。
如:位于第二个页面的一个表单试图提交来自第一个页面的post请求。


传递迁移参数
当你迁移到另一个页面时, 请求参数将被保存。这是一个使用request来传递状态信息的简单方式。
例如你可以通过增加一个用户自定义对象来作为请求参数用于在迁移后的页面上来显示该对象。

public boolean onViewClick() {
   Long id = viewLink.getValueLong();
   Customer customer = CustomerDAO.findByPK(id); 
   
   // Set the customer object as a request parameter
   getContext().setRequestAttribute("customer", customer);
   setForward("view-customer.htm");
   
   return false;
} 

上面的代码片段用于迁移到view-customer.htm

<html>
 <head>
   <title>Customer Details</title>
 </head>
 <body>
   <h1>Customer Details</h1>
   <pre>
     Full Name: $customer.fullName
     Email:     $customer.email
     Telephone: $customer.telephone
    </pre>
  </body>
</html> 


请求属性被自动地添加到Velocity 上下文对象中, 所以在后面的页面模板中请求参数也是可用是。



Page Forwarding
Page Forwarding是页面间传递信息的另一种方式。 在这种情况下, 你使用 createPage() 来创建
迁移用的页面并在Page类中直接设置属性。最后, 你将此Page设置为你将要迁移的页面。例如

public boolean onEditClick() {
   Long id = viewLink.getValueLong();
   Customer customer = CustomerDAO.findByPK(id); 
   
   // Create a new EditPage instance based on the specified path
   EditPage editPage = (EditPage) getContext().createPage("/edit-customer.htm");
   editPage.setCustomer(customer);
   setForward(editPage);
   
   return false;
} 


当用createPage()方法建立一个Page时, 应确保你的页面路径以“/”字符开始。

如果Page的路径唯一, 你也可以使用对应的class来指定目标page。(尽管有些特殊,但有时也可能
会存在多个路径对应一个相同的class, 在这种情况下, 如果你调用Context.createPage ()将会抛
出一个异常, 因为Click不能决定该使用哪个路径)

使用这个技术,如上的代码可以修改为:

public boolean onEditClick() {
   Long id = viewLink.getValueLong();
   Customer customer = CustomerDAO.findByPK(id); 
   
   // Create a new EditPage instance based on its class
   EditPage editPage = (EditPage) getContext().createPage(EditPage.class);
   editPage.setCustomer(customer);
   setForward(editPage);
   
   return false;
}
这种Page forwarding 技术可以提供编译期安全并能让你摆脱代码指定路径的繁琐。











分享到:
评论

相关推荐

    Apache Click User Guide

    Apache Click is a simple JEE web application framework for commercial Java developers. Apache Click is an open source project, licensed under the Apache license . Click uses an event based programming...

    click-2.3.0.zip

    Click is a J2EE web application framework featuring a Page and Component oriented design. Click is an open source project licensed using the Apache license.

    robotframework-zoomba:扩展的Robot Framework库使测试GUI,RESTSOAP API,Mobile和Windows Desktop更加容易

    RobotFramework-Zoomba 介绍 Robotframework-Zoomba是使用跨越GUI,REST API,SOAP API,移动和Windows桌面(WinAppDriver)自动化的库的集合。 这些库是现有库 , , 和。...Click Element locator

    RobotFramework常见语法.pdf

    [Documentation] 截图 Capture Page Screenshot [Arguments] ${JSContent} [Documentation] 执⾏JS Execute JavaScript ${JSContent} [Arguments] ${location} [Documentation] 选择Frame Select Frame ${location} ...

    CSharp 3.0 With the .NET Framework 3.5 Unleashed(english)

    The .NET Framework Class Library (FCL) 43 C# and Other .NET Languages 45 The Common Type System (CTS) 46 The Common Language Specification (CLS) 46 Summary 46 2 Getting Started with C# and ...

    UiPath高级开发者认证-操作题

    2. On the landing page, Dashboard, click on the Work items menu item. Scrape the data in all the pages of the table, page by page, ensuring error handling and recovery. 3. For each page: - Filter the ...

    Java Language Conversion Assistant

    Windows 2000, Windows Server 2003, Windows XP Visual Studio .NET 2003 Instructions Click the Download button in the upper right-hand corner of this page to start the download, or choose a different ...

    微软Kinect for Windows7 SDK Beta开发工具包(32)

    On this page, click Download to start the Kinect for Windows SDK beta download. Click Run to start Setup, and follow the instructions in the Setup Wizard. Or, to save the download on your computer ...

    微软Kinect for Windows7 SDK Beta开发工具包(64)

    On this page, click Download to start the Kinect for Windows SDK beta download. Click Run to start Setup, and follow the instructions in the Setup Wizard. Or, to save the download on your computer ...

    北京中科信软 Visual Basic.NET培训

    接口和类的设计 SQL语句,存储过程 二 .NET框架&C#编程 面向对象的基本知识体系 .NET中的面向对象设计与应用 C#与设计模式 泛型 C#中的新特性 程序集 .NET应用程序部署和版本控制 委托和事件 线程 反射 ...

    VB.NET Developer's Guide(4574).pdf

    Customizing the Start Page 139 Accessibility Options 141 Summary 142 Solutions Fast Track 142 Frequently Asked Questions 143 Chapter 4 Common Language Runtime 145 Introduction 146 Component ...

    Login Control

    Right-click anywhere in the pane and select "Customize Toolbox...", click ".Net Framework" tab, browse and locate JoeWoods.LoginControl.dll as you did in step 1. This will create the LoginControl ...

    Selenium WebDriver Practical Guide 最新 原版

    Perform advanced actions such as drag-and-drop, double-click, right-click, and action builders on web pages Explore the advanced features of WebDriver such as handling cookies, taking ...

    asp.net知识库

    深入剖析ASP.NET组件设计]一书第三章关于ASP.NET运行原理讲述的补白 asp.net 运行机制初探(httpModule加载) 利用反射来查看对象中的私有变量 关于反射中创建类型实例的两种方法 ASP.Net应用程序的多进程模型 NET委托...

    IE浏览器自定义的下载管理器(VBIEDownloadMa nager)

    Click the "Download" button on this page, and then VBWebDownloader.exe will be launched. In VBWebDownloader.exe, you will find that the url is ...

    appium-pageobjectmodel:使用Java + Maven + TestNG进行页面对象模型设计。 支持并行

    阿皮页面对象模型 使用Java + Maven + TestNG进行页面对象模型设计的Appium移动测试自动化框架。 框架遵循许多行业最佳实践,并在单个代码库中支持Android和iOS。 在“最高评分的Udemy...UI命令(例如click,sendkeys

    SignalR 2.0 and MVC 5即时通讯完整版示例

    在Visual Studio中,创建一个面向.NET Framework 4.5的C#ASP.NET应用程序,将其命名为SignalRChat,然后单击确定。 创建网页 在New ASP.NET Project对话框中选择MVC,然后点击Change Authentication。 创建网页 ...

    ASP.NET3.5从入门到精通

    15.1.4 .NET Framework 绘图类 15.2 图形编程 15.2.1 Graphics 类 15.2.2 绘制基本图形 15.2.3 图形绘制实例 15.3 绘制文字特效 15.3.1 投影特效 15.3.2 倒影特效 15.3.3 旋转特效 15.4 绘制图片 15.4.1 载入图像...

    英文原版-Instant PHP Web Scraping 1st Edition

    However, web scraping can provide the tools and framework to accomplish this with the click of a button. It’s no wonder, then, that web scraping is a desirable weapon in any programmer’s arsenal....

Global site tag (gtag.js) - Google Analytics