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

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


    網站導航:
     
    主站蜘蛛池模板: 伊人久久免费视频| 久久精品国产大片免费观看| 最近的免费中文字幕视频 | 久久国产精品国产自线拍免费| 国产一区在线观看免费| 伊人久久五月丁香综合中文亚洲| 5g影院5g天天爽永久免费影院| 亚洲AV无码乱码在线观看富二代| 成人精品一区二区三区不卡免费看| 在线亚洲精品自拍| 最近国语视频在线观看免费播放| 国产专区一va亚洲v天堂| 国产大片免费天天看| 亚洲伊人久久综合中文成人网| 91成人免费观看在线观看| 国产亚洲一区二区在线观看 | 免费A级毛片av无码| 亚洲一区二区在线免费观看| 我们的2018在线观看免费高清 | 色视频色露露永久免费观看| 亚洲国产成人久久精品大牛影视 | 亚洲综合无码无在线观看| 精品免费国产一区二区| 黄色片网站在线免费观看| 亚洲人成影院在线观看| 成人精品一区二区三区不卡免费看| 亚洲av永久无码精品漫画| 91久久精品国产免费直播| 久久精品国产亚洲av品善| 亚洲精品无码久久不卡| 久久久99精品免费观看| 国产AV旡码专区亚洲AV苍井空| 国产成人免费ā片在线观看| 一区二区三区免费看| 亚洲狠狠久久综合一区77777| 日韩版码免费福利视频| 男女猛烈无遮掩视频免费软件| 亚洲AV无码专区电影在线观看| 国产乱码免费卡1卡二卡3卡| 国产亚洲综合久久| 亚洲av丰满熟妇在线播放|