<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 閱讀(243) 評論(0)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 精品无码专区亚洲| 久久国产亚洲精品无码| 2020国产精品亚洲综合网| 亚洲人成人网站在线观看| 成人性生免费视频| 伊人久久大香线蕉亚洲| 91麻豆国产自产在线观看亚洲| 亚洲成色在线影院| 亚洲国产精品日韩av不卡在线| 国产日韩精品无码区免费专区国产 | 亚洲免费人成在线视频观看| 亚洲人成网站色在线观看| 久久亚洲sm情趣捆绑调教| 亚洲国产精品无码久久一线| 亚洲中文字幕无码中文字在线| 亚洲黄色网址大全| 国产在线观看免费观看不卡| 91麻豆国产自产在线观看亚洲 | 一个人免费观看日本www视频 | 午夜精品在线免费观看| 毛片免费观看的视频| 亚洲春色在线视频| 免费观看激色视频网站(性色)| 免费精品国产日韩热久久| 亚洲精品字幕在线观看| 久久精品国产亚洲av日韩| 亚美影视免费在线观看| 丁香花在线视频观看免费| 又黄又大又爽免费视频| 久久亚洲av无码精品浪潮| 亚洲成a人片在线不卡一二三区| 无码av免费网站| 亚洲色中文字幕在线播放| 久久一区二区三区免费| 在线观看免费国产视频| 亚洲日韩中文在线精品第一| 亚洲精品无码永久在线观看你懂的| 亚洲av日韩综合一区二区三区| 性短视频在线观看免费不卡流畅 | 久久精品国产精品亚洲艾草网| 新最免费影视大全在线播放|