當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
2. JSF---托管Bean
生活随笔
收集整理的這篇文章主要介紹了
2. JSF---托管Bean
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
托管Bean是JSF中重要的組件,JSF框架對托管Bean沒太多要求,因此托管Bean是一個POJO,通常一個托管Bean與一個應用頁面,托管Bean定義了與頁面自檢關聯(lián)的屬性和方法。
托管Bean成分:
- 托管Bean的屬性可以綁定到對象
- 組建值
- 組件實例(本身)
- 轉換器實現(xiàn)
- 校驗器實現(xiàn)
- 方法可以完成以下功能
- 完成導航處理
- 處理Action事件
- 處理ValueChanged事件
- 完成組件驗證值
托管Bean分類
BackBean、Controller托管Bean、模型Bean、Utily托管Bean
face-config.xml
<managed-bean><managed-bean-name>bookBean</managed-bean-name><managed-bean-class>com.test.bean.BookBean</managed-bean-class><managed-bean-scope>request</managed-bean-scope> </managed-bean>com.test.bean.java
/** To change this license header, choose License Headers in Project Properties.* To change this template file, choose Tools | Templates* and open the template in the editor.*/ package com.test.bean;import static javafx.scene.paint.Color.color; import javax.faces.component.html.HtmlInputText;/**** @author Administrator*/ public class BookBean {private String bookname; // 綁定組件值private HtmlInputText priceInputText; // 綁定組件本身public String guess(){if ("Java".equals(bookname)){priceInputText.setValue(100);priceInputText.setStyle("background-color:green");}else{priceInputText.setValue(0.0);priceInputText.setStyle("background-color:red");}return null;}public String getBookname() {return bookname;}public void setBookname(String bookname) {this.bookname = bookname;}public HtmlInputText getPriceInputText() {return priceInputText;}public void setPriceInputText(HtmlInputText priceInputText) {this.priceInputText = priceInputText;}}index.xhtml
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"xmlns:h="http://xmlns.jcp.org/jsf/html"><h:head><title>圖書猜價</title></h:head><h:body><p>666</p><h:form>圖書名:<h:inputText value="#{bookBean.bookname}"/><br/>價格:<h:inputText binding="#{bookBean.priceInputText}"/><br/><h:commandButton value="猜價" action="#{bookBean.guess}" /></h:form></h:body> </html>總結
以上是生活随笔為你收集整理的2. JSF---托管Bean的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: netbean创建jsf项目
- 下一篇: java 操作txt文件