JSF學(xué)習(xí)日志

          1.Bean中這樣寫,頁面上直接調(diào)用
          @Named("bean1") // or @ManagedBean(name="bean1") or 不指定名字,默認(rèn)Bean的名,sampleBean
          @SessionScoped
          public class SampleBean {
              public int getLuckyNumber() {  }
              public void setLuckyNumber(int value) {  }
              public String login() {
              if () return "success"; else return "error";
              }
          }
          頁面這樣寫,直接調(diào)相應(yīng)的方法
          <h:commandButton value="press me" action="#{bean1.login}"/>
          2.超鏈接
          <h:link outcome="#{custVM.gotoDetail}" includeViewParams="true" target="_blank">
                <f:param name="scmNo" value="#{warr.project_no}"/>
                <f:param name="custNo" value="#{warr.cust_no}"/>  
                <f:param name="custName" value="#{warr.cust_name}"/>  
                <h:outputText value="#{warr.accrued_amt}">
                     <f:convertNumber currencySymbol="$" type="currency" />
                </h:outputText>
          </h:link>
          在目標(biāo)頁面寫下面這個,這樣就可以傳過來了
          <f:metadata>
               <f:viewParam name="scmNo" value="#{custVM.scmNo}" />
               <f:viewParam name="custNo" value="#{custVM.custNo}" />
               <f:viewParam name="custName" value="#{custVM.custName}" />
          </f:metadata>
          3.下拉菜單寫法:
          private List<SelectItem> monthItems; //它有自己的SelectItem 類,用來存鍵值對。
              
              @PostConstruct
              public void init() {
                  Calendar now = Calendar.getInstance();
                  date = now.getTime();
                  monthItems = new ArrayList<SelectItem>();
                  try {
                      List<Date> monthList = amoritizateService.getMonthList();
                      for(Date month:monthList){
                          monthItems.add(new SelectItem(month, DateUtil.format(month, "yyyy - MM")));
                      }
                  } catch (Exception e) {
                      LOG.error("ERROR!",e);
                  }
                  
              }
          頁面可以直接這樣寫:
          <p:selectOneMenu value="#{amoritizateVM.date}" converter="monthItemConverter" style="width:145px">
                <f:selectItems value="#{amoritizateVM.monthItems}"></f:selectItems>
          </p:selectOneMenu>
          這里面用到了另外一個知識點Converter,用來轉(zhuǎn)換類別,比如這里是用來Date和String的互轉(zhuǎn),所以要寫上這個類
          /**
          只要實現(xiàn)它的接口,它會自動完成轉(zhuǎn)換,還是很方便的
          */
          @FacesConverter("monthItemConverter")
          public class MonthItemConverter implements Converter {

              private static final Logger LOG = LoggerFactory.getLogger(MonthItemConverter.class);


              @Override
              public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
                  return DateUtil.parseDate(arg2);
              }


              @Override
              public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
                  return DateUtil.format((Date)arg2);
              }

          }

          4.表單提交的話,用這個
          <p:commandButton value="Query" update="dataForm"/>
          這里面的update要對應(yīng)這個頁面里的form的id
          <h:form id="dataForm">


          眼鏡蛇

          posted on 2014-11-26 13:38 眼鏡蛇 閱讀(218) 評論(0)  編輯  收藏 所屬分類: JavaJSF

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 罗源县| 高唐县| 图们市| 阿坝县| 丹东市| 丰县| 房产| 汝南县| 奉化市| 雅江县| 哈密市| 汤阴县| 乌兰察布市| 聂拉木县| 南皮县| 延寿县| 普格县| 石渠县| 湖南省| 民丰县| 天祝| 达拉特旗| 通河县| 桦甸市| 乌兰县| 资源县| 周宁县| 临沧市| 宁阳县| 乌海市| 马尔康县| 汝南县| 惠水县| 沾化县| 都江堰市| 石林| 昌图县| 祁东县| 蒲城县| 乳山市| 永州市|