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

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

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

    soufan

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      22 隨筆 :: 0 文章 :: 0 評論 :: 0 Trackbacks

    使用backing bean來添加UIComponents 到頁面中?

    下面是一個例子:

    jsp1.jsp:

    <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <html>
    <f:view>
    <head>
    <title>jsp1</title>
      <link rel="stylesheet" type="text/css" href="./style.css" title="Style"/>
    </head>
    <body bgcolor="#ffffff">  TESTING...
      <h:form id="form1">
        <h:panelGrid id="panelgridtest" binding="#{jsp1Bean.component}"/>
      </h:form>
    </body>
    </f:view>
    </html>
    

    ?

    Jsp1Bean.java:

    package?test;
    ?
    import?javax.faces.application.Application;
    import?javax.faces.component.UIComponent;
    import?javax.faces.component.UIPanel;
    import?javax.faces.component.UIViewRoot;
    import?javax.faces.component.html.HtmlInputText;
    import?javax.faces.component.html.HtmlOutputText;
    import?javax.faces.context.FacesContext;
    ?
    public?class?Jsp1Bean
    {
    ????UIComponent?component?=?null;
    ????FacesContext?facesContext?=?FacesContext.getCurrentInstance();
    ????UIViewRoot?uIViewRoot?=?facesContext.getViewRoot();
    ????Application?application?=?facesContext.getApplication();
    ?
    ????public?Jsp1Bean()
    ????{
    ????}
    ?
    ????public?UIComponent?getComponent()
    ????{
    ????????if?(component?==?null)
    ????????{
    ????????????component?=?new?UIPanel();
    ????????}
    ????????return?component;
    ????}
    ?
    ????public?void?setComponent(UIComponent?component)
    ????{
    ????????this.component?=?component;
    ????}
    ?
    ?????//initialization?block
    ????{
    ????????try
    ????????{
    ????????????//outputText1
    ????????????HtmlOutputText?outputText1?=?(HtmlOutputText)?
    ??????????????facesContext.getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
    ????????????outputText1.setValue("---the?outputText1?value---");
    ????????????//inputText1
    ????????????HtmlInputText?inputText1?=?(HtmlInputText)
    ????????????????facesContext.getApplication().createComponent(HtmlInputText.COMPONENT_TYPE);
    ????????????inputText1.setValue("---the?inputText1?value---");
    ?
    ????????????//add?outputText1?and?inputText1?to?component?("UIPanel")
    ????????????this.getComponent().getChildren().add(outputText1);
    ????????????this.getComponent().getChildren().add(inputText1);
    ????????}
    ????????catch?(java.lang.Throwable?t)
    ????????{
    ????????????System.out.println("java.lang.Throwable?exception?encountered...t.getMessage()="?+?t.getMessage());
    ????????????t.printStackTrace();
    ????????}
    ????}
    ?
    ????public?String?doAction()
    ????{
    ????????return?"submit";
    ????}
    }

    ?

    faces-config.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
                                  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config>
      <navigation-rule>
        <from-view-id>/jsp1</from-view-id>
        <navigation-case>
          <from-action>submit</from-action>
          <to-view-id>/jsp1</to-view-id>
          <redirect/>
        </navigation-case>
      </navigation-rule>
      <managed-bean>
        <managed-bean-name>jsp1Bean</managed-bean-name>
        <managed-bean-class>test.Jsp1Bean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>
    </faces-config>
    
    posted on 2006-12-19 16:14 soufan 閱讀(239) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 免费高清av一区二区三区| 国产乱子精品免费视观看片| 麻豆国产VA免费精品高清在线| 亚洲天天做日日做天天欢毛片| 中文字幕在线免费播放| 中文字幕亚洲电影| 国产成人无码免费网站| 亚洲精品成人无码中文毛片不卡| 国产99视频精品免费视频76| 国产亚洲色婷婷久久99精品91| 人成午夜免费大片在线观看 | 久久精品国产免费观看| 亚洲美免无码中文字幕在线| 国产在线观看麻豆91精品免费| 亚洲视频日韩视频| 在线看片v免费观看视频777| 国产 亚洲 中文在线 字幕| 日韩精品免费电影| 人人鲁免费播放视频人人香蕉| 亚洲av无码成人精品区| 久久久久久久国产免费看| 99久久亚洲精品无码毛片| 性生交片免费无码看人| 无人视频在线观看免费播放影院| 久久夜色精品国产亚洲av| 色欲A∨无码蜜臀AV免费播| 中文字幕亚洲综合小综合在线| 国产精品无码免费视频二三区| 91在线免费视频| 久久久久亚洲精品无码蜜桃 | 四虎永久免费网站免费观看| 精选影视免费在线 | 亚洲成a人片在线网站| 美女被免费视频网站a国产| 一个人看的免费高清视频日本| 亚洲AV乱码久久精品蜜桃| 成人激情免费视频| 中文字幕永久免费| 亚洲一区二区三区成人网站| 青青草原亚洲视频| 欧美男同gv免费网站观看|