posts - 0,comments - 0,trackbacks - 0
           

          圖片按鈕,HTML中的一個(gè)特例.在規(guī)范中說明,瀏覽器會(huì)把圖片按鈕當(dāng)成一個(gè)image map對待.這就意味的不像其它的按鈕會(huì)返回一個(gè)String類型的value.圖片按鈕會(huì)返回一個(gè)XY的坐標(biāo). 像下面:

          myImageButton.x=200

          myImageButton.y=300

           

          Struts,對于很多控件,我們可以創(chuàng)建在ActionForm中一個(gè)簡單String的屬性.但對圖片按鈕不行.因?yàn)閳D片按鈕提交的不在是簡單的 name=value的形式.

          幸運(yùn)的事,Struts中提供了ActionForm嵌套bean的能力.就是說ActionForm中的屬性可以是另外一個(gè)bean的類型.比如我們有一個(gè)MyForm:

           

           1class MyForm extends ActionFrom{
           2
           3         MyBean myBean;
           4
           5      public MyForm(){
           6
           7            init();
           8
           9         }

          10
          11public void init(){
          12
          13      myBean = new MyBean();
          14   }

          16
          17public MyBean getMyBean(){
          18        return this.myBean;
          20   }

          22
          23}
           
          24

           

          注意,一定要初始化myBean,因?yàn)椴皇欠?/span>String和本地類型的 類的實(shí)體域,默認(rèn)是為null.如果不初始化在jsp頁面第一次加載時(shí)會(huì)試圖用ActionForm的值設(shè)置表單的值.這時(shí)就會(huì)有空指針異常.

          對應(yīng)的MyBean可以是:

          class MyBean{

                String name;

                public void setName(String name){

                this.name=name;  
          }

          public String getName(){

                return this.name;

          }

          }

          這樣我們在JSP頁面中表單中可以有:

          <html:text property=" myBean.name"/>

          這樣實(shí)際會(huì)調(diào)用 getMyBean().setName(value),getMyBean().getName().

           

          這樣對于圖片按鈕我們就可以用一個(gè)ImageButtonBean的類型(struts中已經(jīng)提供了).在我們的ActionForm中可以寫為:

           

              private ImageButtonBean logonButton = new ImageButtonBean();

                private ImageButtonBean cancelButton = new ImageButtonBean();

           

              public void setLogonButton(ImageButtonBean button) {

                  this.logonButton = button;

              }

           

              public ImageButtonBean getLogonButton() {

                  return this.logonButton;

              }

           

             

              public void setCancelButton(ImageButtonBean button) {

                  this.cancelButton = button;

              }

           

              public ImageButtonBean getCancelButton() {

                  return this.cancelButton;

              }

           

           

          Action中可以簡單的用

          Boolean selected = ((myForm) form). getCancelButton().isSelecte();

          判斷按鈕是否被按下.

          posted on 2007-04-21 11:02 炎涼 閱讀(99) 評(píng)論(0)  編輯  收藏

          只有注冊用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 克山县| 报价| 邮箱| 大同市| 太仆寺旗| 巴林右旗| 高雄市| 肇源县| 成武县| 南岸区| 阜新| 策勒县| 吴江市| 西乌珠穆沁旗| 临高县| 邓州市| 中牟县| 明水县| 佳木斯市| 固镇县| 新河县| 中超| 平南县| 铜鼓县| 崇文区| 石阡县| 临江市| 平山县| 徐闻县| 吕梁市| 鹿邑县| 宁陕县| 冀州市| 屏南县| 大新县| 金华市| 湘潭市| 南江县| 西昌市| 神木县| 绥德县|