| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 891 人关注过本帖
标题:[求助]一个使用JSF框架的程序至少要包含哪几个Bean
只看楼主 加入收藏
一个人上路
Rank: 1
等 级:新手上路
帖 子:124
专家分:0
注 册:2006-8-21
收藏
 问题点数:0 回复次数:2 
[求助]一个使用JSF框架的程序至少要包含哪几个Bean
请解释一下各自的作用。谢谢

[此贴子已经被作者于2006-11-24 1:07:20编辑过]


搜索更多相关主题的帖子: JSF Bean 框架 
2006-11-23 22:22
hanshengchua
Rank: 1
等 级:禁止访问
威 望:2
帖 子:174
专家分:0
注 册:2006-5-8
收藏
得分:0 

不太明白什么意思。

JavaBean的类型只有三个:
控键Bean
容器Bean
不可见的Bean

不可见的Bean使用在jsp中。

2006-11-23 23:33
renlong1333
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-5-6
收藏
得分:0 

一个关于课题Subject的JAVABean:
package com.jsfdemo.beans;

public class SubjectBean {
private String sb_id;
private String sb_name;
private String sb_desc;
private String t_name;
private String sb_state;
//--------------------------
public SubjectBean(){

}
//--------------------------
public String getSb_desc() {
return sb_desc;
}
public void setSb_desc(String sb_desc) {
this.sb_desc = sb_desc;
}
public String getSb_id() {
return sb_id;
}
public void setSb_id(String sb_id) {
this.sb_id = sb_id;
}
public String getSb_name() {
return sb_name;
}
public void setSb_name(String sb_name) {
this.sb_name = sb_name;
}
public String getSb_state() {
return sb_state;
}
public void setSb_state(String sb_state) {
this.sb_state = sb_state;
}
public String getT_name() {
return t_name;
}
public void setT_name(String t_name) {
this.t_name = t_name;
}
public SubjectBean(String sb_id,String sb_name,String sb_desc,String t_name,String sb_state ){
this.sb_id = sb_id;
this.sb_name = sb_name;
this.sb_desc = sb_desc;
this.t_name = t_name;
this.sb_state = sb_state;

}
}


一个数据库连接池的类:
package com.jsfdemo.beans;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.sql.*;
import javax.sql.DataSource;
public class DBConnection {

static public Connection dataSource() {
try{
Context ctx = new InitialContext();
if(ctx==null)throw new NamingException ("no initial context");
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/dbtest");
if(ds==null) throw new NamingException ("no dataSource ");
// Connection con = ds.getConnection();
}catch (NamingException e){

//}catch (SQLException e){

}
return null;
}
}

一个操作数据库的JAVABean:
package com.jsfdemo.beans;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.Vector;
import javax.servlet.jsp.jstl.sql.ResultSupport;
import javax.servlet.jsp.jstl.sql.Result;
import java.sql.SQLException;

public class SbDB {
// private Result AllSubject;
//********************************************
public void addSubject(SubjectBean subject) throws Exception,SQLException{
try{
Connection con =DBConnection.dataSource();
PreparedStatement pst = null;
//try{
pst = con.prepareStatement("insert into subjectInfo(sb_id,sb_name,sb_desc,t_id,sb_state) values(?,?,?,?,?)");
pst.setString(1, subject.getSb_id());
pst.setString(2, subject.getSb_name());
pst.setString(3, subject.getSb_desc());
pst.setString(4, subject.getT_name());
pst.setString(5, subject.getSb_state());
pst.executeUpdate();
//}catch(Exception e){
// e.printStackTrace();
//}
con.close();

}catch(Exception e){
e.printStackTrace();
}

}
}
// ********************************************

一个和JSP界面及JAVABean交互的类:
package com.jsfdemo.beans;
import javax.faces.event.ActionEvent;
import javax.servlet.jsp.jstl.sql.Result;


public class SbManager {

private SubjectBean subjectB = new SubjectBean();
private SbDB sbdb = new SbDB();
//*************************************

public SbManager(){

}
//*************************************

public SubjectBean getSubjectB() {
return subjectB;
}
public void setSubjectB(SubjectBean subjectB) {
this.subjectB = subjectB;
}
public SbDB getSbdb() {
return sbdb;
}

public void setSbdb(SbDB sbdb) {
this.sbdb = sbdb;
}
public String add(){
try{
sbdb.addSubject(subjectB);
}catch(Exception e){
e.printStackTrace();
}
return "addOK";
}

JSP界面:
<%@ page language = "java" contentType = "text/html;charset = gb2312"%>
<%@ taglib uri = "http://java.sun.com/jsf/core" prefix = "f"%>
<%@ taglib uri = "http://java.sun.com/jsf/html" prefix = "h"%>
<html>
<center>
<f:view>
<h:form>

<head>
<title>
add the subject
</title>
</head>
<body>
<h:panelGrid columns = "2">
<h:outputText value = "subjectID"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.sb_id}"></h:inputText>
<h:outputText value = "subjectName"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.sb_name}"></h:inputText>
<h:outputText value = "subjectDesc"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.sb_desc}"></h:inputText>
<h:outputText value = "teacher'sName"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.t_name}"></h:inputText>
<h:outputText value = "subject'sState"></h:outputText>
<h:inputText value = "#{SbManager.subjectB.sb_state}"></h:inputText>
<h:commandButton value = "submit..." action = "#{SbManager.add}"></h:commandButton>
</h:panelGrid>
<h:dataTable value = "#{SbManager.subjectB}" var = "sb" border = "1">
<h:column>
<f:facet name="header">
<h:outputText value = "subjectID"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.sb_id}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value = "subjectName"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.sb_name}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value = "subjectDesc"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.sb_desc}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value = "teacher'sName"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.t_name}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value = "subject'sState"></h:outputText>
</f:facet>
<h:outputText value = "#{sb.sb_state}"></h:outputText>
</h:column>
</h:dataTable>

</body>
</h:form>
</f:view>
</center>
</html>

其他配置正确(因为我做了测试),我先是把这些代码全部写在一个类里,能实现其功能,但是那样感觉太乱了,所以我把这些代码给分别写在了类里,结果是:
提交后,不显示错误,也不往数据库里插入信息,我已经是到了“山穷水尽”的地步了,实在解决不了这个问题,希望高手帮帮忙,谢谢啊!!!

2007-05-06 15:49
快速回复:[求助]一个使用JSF框架的程序至少要包含哪几个Bean
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023768 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved