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

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

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

    Joeyta備忘記

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      9 Posts :: 0 Stories :: 9 Comments :: 0 Trackbacks

    Wicket Lab2 要求使用 TextField, DropDownChoice 及 Date picker 實作頁面跳轉的效果.

    開始備忘記:
    [1] Lab2 要求
    [2] 實作 Lab2

    [1] Lab2 要求:
    本次要求如下圖所示,
    當介面選擇 Male 後, 跳至 male 的訊息,
    當介面選擇 Female 後, 跳至 female 的訊息,



    [2] 實作 Lab2
    <!----------- web.xml ----------------->
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <display-name>CM269</display-name>

     <filter>
            <filter-name>WicketLab1First</filter-name>
            <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
            <init-param>
              <param-name>applicationClassName</param-name>
              <param-value>cm269.lab1.MyApp</param-value>
            </init-param> 
     </filter>
        <filter-mapping>
            <filter-name>WicketLab1First</filter-name>
            <url-pattern>/lab1/*</url-pattern>
        </filter-mapping>
       
     <filter>
            <filter-name>WicketLab2First</filter-name>
            <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
            <init-param>
              <param-name>applicationClassName</param-name>
              <param-value>cm269.lab2.MyApp</param-value>
            </init-param> 
     </filter>
        <filter-mapping>
            <filter-name>WicketLab2First</filter-name>
            <url-pattern>/lab2/*</url-pattern>
        </filter-mapping>   

    </web-app>
    <!----------- web.xml ----------------->


    ############### Lab2.properties ###############
    f.sex.null=-Pls Select-
    f.birth.IConverter.Date=You must input a date.
    ############### Lab2.properties ###############

    這裡的 f.sex.null 表示 html 頁裡 "f" form 的 sex element,
    表示 DropDownChoice 預設為 -Pls Select-
    如果 key/value 設成 null=-Pls Select- 則對所有 DropDownChoice 起作用.


    /************* Lab2.java ****************/
    package cm269.lab2;

    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;

    import org.apache.wicket.extensions.yui.calendar.DatePicker;
    import org.apache.wicket.markup.html.WebPage;
    import org.apache.wicket.markup.html.form.DropDownChoice;
    import org.apache.wicket.markup.html.form.Form;
    import org.apache.wicket.markup.html.form.TextField;
    import org.apache.wicket.markup.html.panel.FeedbackPanel;
    import org.apache.wicket.model.Model;

    public class Lab2 extends WebPage {

     private static final long serialVersionUID = 381689366528324660L;

     private Model nameModel;
     private Model sexModel;
     private Model birthModel;
     
     public Lab2() {
      FeedbackPanel feedback = new FeedbackPanel("msgs");
      add(feedback);
      Form form = new Form("f"){
       private static final long serialVersionUID = -8897899191585355738L;

       protected void onSubmit() {
        String sName = (String)nameModel.getObject();
        String sSex = (String)sexModel.getObject();
        Date dBirth = (Date)birthModel.getObject();
        
        if(sSex.equals("Male")){
         AbstractResult result = new Lab2ResultA(sName,dBirth);
         setResponsePage(result);   // 這裡表示按 submit 後, 跳至 Lab2ResultA 頁面
        } else if(sSex.equals("Female")){
         AbstractResult result = new Lab2ResultB(sName,dBirth);
         setResponsePage(result);   // 這裡表示按 submit 後, 跳至 Lab2ResultB 頁面
        }

       }
      };
      
      nameModel = new Model();
      TextField name = new TextField("name", nameModel, String.class);
      name.setRequired(true);
      form.add(name);
      
      sexModel = new Model();
      List sexes = new ArrayList();
      sexes.add("Male");
      sexes.add("Female");
      DropDownChoice sex = new DropDownChoice("sex", sexModel, sexes);
      sex.setRequired(true);
      form.add(sex);
      
      birthModel = new Model();
      TextField birth = new TextField("birth", birthModel, Date.class);
    //  TextField birth = new TextField("birth", birthModel, Date.class){
    //   private static final long serialVersionUID = 1441781496720134137L;
    //   public IConverter getConverter(Class type){
    //    return type == Date.class ? new DateConverter():null;
    //   }
    //  };
      birth.setRequired(true);
      birth.add(new DatePicker());
      form.add(birth);
      
      add(form);
     }
     
    }
    /************* Lab2.java ****************/


    <!----------- Lab2.html ----------------->
    <html>
     <head>
      <title>Lab2</title>
     </head>
     <body>
     
     <span wicket:id="msgs" />
     <form wicket:id="f">
      <table border>
       <tr><th colspan="2">CM269 Lab2</th></tr>
       <tr>
        <td>Name</td>
        <td>
         <input type="text" wicket:id="name" />
        </td>
       </tr>
       <tr>
        <td>Sex</td>
        <td>
         <select wicket:id="sex">
          <option>Male</option>
          <option>Female</option>
         </select>    
        </td>
       </tr>   
       <tr>
        <td>Date of Birth</td>
        <td>
         <input type="text" wicket:id="birth" />
        </td>
       </tr> 
       <tr>
        <td colspan="2">
         <input type="submit" value="OK" />
        </td>
       </tr>    
      </table>
     </form>
      
     </body>
    </html>
    <!----------- Lab2.html ----------------->


    /************* AbstractResult.java ****************/
    package cm269.lab2;

    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    import org.apache.wicket.markup.html.WebPage;
    import org.apache.wicket.markup.html.basic.Label;

    public class AbstractResult extends WebPage{

     private static final long serialVersionUID = 3148730572565560427L;

     protected String name;
     
     protected Date birth;
     
     public void doResult() {
      DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
      
      add(new Label("name",getName()));
      add(new Label("birth",dateFormat.format(getBirth())));
     }

     public String getName() {
      return name;
     }

     public void setName(String name) {
      this.name = name;
     }

     public Date getBirth() {
      return birth;
     }

     public void setBirth(Date birth) {
      this.birth = birth;
     }
     
     
    }
    /************* AbstractResult.java ****************/


    /************* Lab2ResultA.java ****************/
    package cm269.lab2;

    import java.util.Date;

    public class Lab2ResultA extends AbstractResult {

     private static final long serialVersionUID = -1230297067586624251L;

     public Lab2ResultA(String sName, Date dBirth) {
      setName(sName);
      setBirth(dBirth);
      doResult();
     }
     
    }
    /************* Lab2ResultA.java ****************/


    <!----------- Lab2ResultA.html ----------------->
    <html>
     <head>
      <title>Lab2ResultA</title>
     </head>
     <body>
     
     <table border="0">
      <tr>
       <td colspan="2">Dear Sir,</td>
      </tr>
      <tr>
       <td width="20">&nbsp;</td>
       <td>Your Registration is accepted.</td>
      </tr>
      <tr>
       <td>&nbsp;</td>  
       <td>Name:<span wicket:id="name">joeyta</span></td>
      </tr>
      <tr>
       <td>&nbsp;</td>  
       <td>Date of Birth:<span wicket:id="birth">1980/01/01</span></td>
      </tr>
      
     </table> 
     
     </body>
    </html>
    <!----------- Lab2ResultA.html ----------------->


    /************* Lab2ResultB.java ****************/
    package cm269.lab2;

    import java.util.Date;

    public class Lab2ResultB extends AbstractResult {

     private static final long serialVersionUID = -5461297645709489576L;

     public Lab2ResultB(String sName, Date dBirth) {
      setName(sName);
      setBirth(dBirth);
      doResult();
     }
     
    }
    /************* Lab2ResultB.java ****************/


    <!----------- Lab2ResultB.html ----------------->
    <html>
     <head>
      <title>Lab2ResultB</title>
     </head>
     <body>
     
     <table border="0">
      <tr>
       <td colspan="2">Dear Miss,</td>
      </tr>
      <tr>
       <td width="20">&nbsp;</td>  
       <td>Your Registration is accepted.</td>
      </tr>
      <tr>
       <td>&nbsp;</td>  
       <td>Name:<span wicket:id="name">joeyta</span></td>
      </tr>
      <tr>
       <td>&nbsp;</td>  
       <td>Date of Birth:<span wicket:id="birth">1980/01/01</span></td>
      </tr>
      
     </table> 
     
     </body>
    </html>
    <!----------- Lab2ResultB.html ----------------->


    項目結構如下圖所示:



    參考資料:

    http://wicket.apache.org/


     

    posted on 2007-09-18 21:52 joeyta 閱讀(777) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 国产精品亚洲一区二区在线观看 | 美女露100%胸无遮挡免费观看| 麻豆视频免费播放| 久久久国产精品亚洲一区| 久久黄色免费网站| 亚洲经典在线观看| 99国产精品永久免费视频| 亚洲电影在线播放| www.黄色免费网站| 亚洲AV无码资源在线观看| 免费h黄肉动漫在线观看| 一区二区在线免费视频| 中文字幕无码精品亚洲资源网| 搡女人免费免费视频观看| 亚洲av之男人的天堂网站| 7m凹凸精品分类大全免费| 亚洲最新中文字幕| 日韩高清免费在线观看| 成人免费观看男女羞羞视频 | 亚洲国产成+人+综合| 拨牐拨牐x8免费| 免费激情网站国产高清第一页| 亚洲欧洲成人精品香蕉网| 最近2022中文字幕免费视频| 亚洲国产精品一区二区三区在线观看| 免费看少妇作爱视频| 中文字幕手机在线免费看电影 | 伊人久久综在合线亚洲2019| 成人毛片免费观看视频| 国产日韩精品无码区免费专区国产 | 亚洲风情亚Aⅴ在线发布| 亚洲男人av香蕉爽爽爽爽| 99久久国产免费-99久久国产免费 99久久国产免费中文无字幕 | 久久精品国产亚洲AV久| 人人狠狠综合久久亚洲高清| 国产精品偷伦视频观看免费| 亚洲综合av一区二区三区| 国产偷国产偷亚洲高清日韩| 日本精品人妻无码免费大全| eeuss影院免费直达入口| 亚洲一区二区三区在线|