<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    大漠駝鈴

    置身浩瀚的沙漠,方向最為重要,希望此blog能向大漠駝鈴一樣,給我方向和指引。
    Java,Php,Shell,Python,服務器運維,大數據,SEO, 網站開發、運維,云服務技術支持,IM服務供應商, FreeSwitch搭建,技術支持等. 技術討論QQ群:428622099
    隨筆 - 238, 文章 - 3, 評論 - 117, 引用 - 0
    數據加載中……

    A Blog Application with Wideplay's Warp Framework(1)

    A Blog Application with Wideplay's Warp Framework

    First check out the Hello World example to get yourself going. In this article, I'll show you how to knock together a simple Blog application where you can browse and read blog entries. You will learn the following Warp concepts:

    • Page Injection
    • RESTful behavior and the HyperLink component
    • The Table and Column components
    • Simple Internationalization (i18n)

    First let's create ourselves a data model object representing a blog. This will be a simple POJO with 2 fields: subject and text.

    public class Blog {

    private String subject;

    private String text;

    //don't forget your getters/setters here...

    }


    OK, now we make a list page where you can see a list of all the blogs currently in the system. For simplicity, we will store blogs in a HashMap. The Page object class for this list should look something like this:

    @URIMapping("/blogs")

    public class ListBlogs {

    private final Map<String, Blog> blogs = new HashMap<String, Blog>();



    public ListBlogs() {

    //setup a blog as dummy data

    blog = new Blog("MyBlog", "Warp is so great...");

    blogs.put(blog.getSubject(), blog);

    }



    public Collection<Blog> getBlogList() {

    return blogs.values();

    }

    }



    Note the @URIMapping annotation which tells warp to map this page object to the URI "/blogs". The getter for property blogList, simply returns a list of all the values contained in our HashMap of blogs. For the interesting part, let's make a template to layout our blogs:



    <?xml version="1.0" encoding="UTF-8"?>

    <html>



    <head>

    <title>Warp :: Blogs</title>

    </head>



    <body w:component="frame">

    <h1>A list of blog entries</h1>



    <table w:component="table" w:items="${blogList}"/>



    </body>

    </html>





    This is a very simple template. Inside our body we have only one real component (Table) and we pass it our list of blogs in the w:items property that we declared above. Go ahead and run the app now and point your browser to: http://localhost:8080/blogs, you should see a table with 2 columns (subject and text) corresponding to the Blog data model object we declared above. Table is smart enough to inspect the items given it and construct an appropriate set of display columns. The rows of the table reflect the data in each instance of the Blog object in our HashMap. Nice!

    OK, having the property names as the title of each column is not ideal--let's customize this. Customizing is as simple as adding a properties file in the same package as our Blog class, with the same name:

    Blog.properties:

    subject=Subject of Blog

    text=Content



    Now, run the app again and you should see the column names changed. In this way, you can also achieve internationalization (i18n). If you want to hide a property (i.e. not render a column for it), specify an empty key (so to hide subject, you would have just "subject=").

    OK, let's create a view blog page now. This page will display one blog entry. Let's start with the view portion (called ViewBlog.html):

    <?xml version="1.0" encoding="UTF-8"?>

    <html>



    <head w:component="meta">

    <title>Reading :: ${blog.subject}</title>

    </head>



    <body w:component="frame">

    <h1>Read...</h1>

    <h3>${blog.subject}</h3>



    ${blog.text}



    <a href="../home">back to list</a>

    </body>

    And its Page object:

    @URIMapping("/blog")

    public class ViewBlog {

    private Blog blog;



    //getters/setters...

    }



    Ok, this is fairly simple, but how does it know what blog to display? Let us use a RESTful idiom to achieve this. First, change your ViewBlog page object so that it takes a parameter indicating what blog to show:

    @URIMapping("/blog/{subject}")

    public class ViewBlog {

    private Blog blog;



    @OnEvent @PreRender

    public void init(String subject) { .. }

    }



    Ok, this tells warp that when the URL http://localhost:8080/blog/myblog is requested, to inject anything matching the {subject} portion of the @URIMapping (in this case "myblog") to the @PreRender event handler method. Hold on, we're not done yet--we still need to obtain the appropriate blog from our HashMap which is stored in the ListBlogs page. This is done via page-injection:

    @URIMapping("/blog/{subject}")

    public class ViewBlog {

    private Blog blog;



    @Inject @Page private ListBlogs listBlogs;



    @OnEvent @PreRender

    public void init(String subject) {

    this.blog = listBlogs.getBlog(subject);

    }

    }

    Finally, we need to modify ListBlogs and give it a getBlog() method to fetch a Blog by subject:

    @URIMapping("/blogs")

    public class ListBlogs {

    private Map<String, Blog> blogs = new HashMap<String, Blog>();



    public ListBlogs() { .. }



    public Collection<Blog> getBlogList() {

    return blogs.values();

    }



    public Blog getBlog(String subject) {

    return blogs.get(subject);

    }


    }


    Ok, now let's wire the pages together so clicking on a blog in the list will take us to the view page for that blog. I want to make the subject of the blog clickable, so let's use the Column component to override the default behavior of table (which just prints out the subject as text):

    <?xml version="1.0" encoding="UTF-8"?>

    <html>



    <head w:component="meta">

    <title>Warp :: Blogs</title>

    </head>



    <body w:component="frame">

    <h1>A list of blog entries</h1>



    <table w:component="table" w:items="${blogList}" class="mytableCss">

    <td w:component="column" w:property="subject">

    <a w:component="hyperlink" w:target="/blog"


    w:topic="${subject}">${subject}</a>

    </td>


    </table>



    </body>

    </html>





    Notice that we nest the hyperlink component inside the column override. This tells the Table component not to draw the column, instead to use our overridden layout instead. The attribute w:target simply tells the hyperlink the URI that we're linking (in this case /blog, which is the ViewBlog's mapping) and w:topic tells hyperlink to append the subject of the blog to the URI. So for a blog entitled "MyBlog," Warp will generate a URI as follows: /blog/MyBlog. And "MyBlog" gets stripped out and injected into the ViewBlog page's @PreRender handler so it can set it up.

    Also notice the addition of a non-Warp attribute class to the <table> tag, which refers to the CSS class I want to style my table with. This is a useful tool for both for previewability as well as the end result HTML--generally whatever HTML attributes you write on a component will be passed through the final rendered page.

    Done!

    posted on 2009-02-17 16:29 草原上的駱駝 閱讀(271) 評論(0)  編輯  收藏 所屬分類: JAVA框架

    主站蜘蛛池模板: 亚洲2022国产成人精品无码区| 99久久久国产精品免费无卡顿 | 国产精品免费观看视频| 国产黄在线观看免费观看不卡| 好吊妞在线新免费视频| 亚洲日本国产乱码va在线观看| h视频在线观看免费| 国产三级电影免费观看| 亚洲成a人无码亚洲成www牛牛| 13一14周岁毛片免费| 久久精品国产精品亚洲色婷婷| 一区二区3区免费视频| 免费a级毛片永久免费| 国产精品久久久久久久久免费| 亚洲成在人线av| 日韩免费在线视频| 亚洲校园春色小说| 成人免费男女视频网站慢动作| 亚洲国产精品精华液| 成人伊人亚洲人综合网站222| 四虎国产精品成人免费久久| 亚洲国产小视频精品久久久三级| 久久er国产精品免费观看8| 国产精一品亚洲二区在线播放| 日本一区二区免费看| 亚洲人成网站在线观看播放动漫| 免费毛片在线视频| 一级a性色生活片久久无少妇一级婬片免费放 | 亚洲精品夜夜夜妓女网 | 6080午夜一级毛片免费看| 色在线亚洲视频www| 亚洲AV中文无码乱人伦在线视色| 岛国精品一区免费视频在线观看| 亚洲av鲁丝一区二区三区| 免费无码又爽又刺激聊天APP| 色妞www精品视频免费看| 亚洲日韩aⅴ在线视频| 精品久久久久成人码免费动漫| 国产午夜亚洲精品不卡电影| 亚洲精品美女久久久久99| 希望影院高清免费观看视频|