<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)  編輯  收藏

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


    網站導航:
     
    主站蜘蛛池模板: 7x7x7x免费在线观看| 亚洲精品免费在线观看| 好大好硬好爽免费视频| 国产v亚洲v天堂a无| 无码区日韩特区永久免费系列 | 免费一级毛片一级毛片aa| 在线亚洲高清揄拍自拍一品区| 日本片免费观看一区二区| 亚洲综合一区二区精品久久| 最近免费中文字幕mv在线电影| 亚洲丝袜中文字幕| 成全高清视频免费观看| 亚洲欧美国产国产一区二区三区| 美女视频黄a视频全免费| 亚洲日本一线产区和二线产区对比| 成人免费激情视频| 亚洲欧美日韩一区二区三区| 国产精品自在自线免费观看| 一区二区免费电影| 亚洲AV无码成人精品区蜜桃| 久久免费看黄a级毛片| 国产精品高清视亚洲一区二区| 欧洲美熟女乱又伦免费视频| 一区二区三区在线观看免费| 久久精品亚洲视频| 日韩欧美一区二区三区免费观看| 亚洲A∨精品一区二区三区下载| 国产91精品一区二区麻豆亚洲 | 羞羞网站免费观看| 国产gv天堂亚洲国产gv刚刚碰| 无码人妻久久一区二区三区免费| 亚洲国产精品美女| 吃奶摸下高潮60分钟免费视频 | 黄色a三级免费看| 亚洲AV无码专区国产乱码电影| 国产成人精品久久免费动漫| 日韩色日韩视频亚洲网站 | 亚洲国产精品乱码在线观看97| 日本视频免费在线| a级毛片免费观看视频| 国产成人精品日本亚洲直接 |