MyFaces¤ÇDerby¤ÎÆâÍƤò¥Æ¡¼¥Ö¥ëɽ¼¨¤ò¥Ù¡¼¥¹¤Ë¥Æ¡¼¥Ö¥ë¤ò°ìÍ÷ɽ¼¨¤·¤¿¤È¤³¤í¤«¤é£±ÌÀºÙ¤Î¤ß¤Îɽ¼¨¥Ú¡¼¥¸¤Ë°ÜÆ°¤¹¤ë¤È¸À¤¦¥¢¥×¥ê¤òºîÀ®¤·¤Þ¤¹¡£
package bean.primula.jp; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import javax.annotation.Resource; import javax.faces.FacesException; import javax.sql.DataSource; public class ItemListBean { @Resource(name = "TestDB") private DataSource ds; ArrayList<Item> items = new ArrayList<Item>(); public ItemListBean() { } private void execSQL() { Connection con = null; Statement stmt = null; ResultSet resultSet = null; items.clear(); try { con = this.ds.getConnection(); stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String sql = "select * from ITEM"; resultSet = stmt.executeQuery(sql); while (resultSet.next()) { items.add(new Item(resultSet.getInt(1), resultSet.getString(2), resultSet.getBigDecimal(3))); } resultSet.close(); stmt.close(); con.close(); } catch (Exception ex) { throw new FacesException(ex); } } public ArrayList<Item> getItems() { execSQL(); return items; } public void setItems(ArrayList<Item> items) { this.items = items; } }
package bean.primula.jp; import java.math.BigDecimal; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import javax.annotation.Resource; import javax.faces.FacesException; import javax.sql.DataSource; public class ItemDspBean { @Resource(name = "TestDB") private DataSource ds; private int id; private String name; private BigDecimal price; private void execSQL(String key) { Connection con = null; Statement stmt = null; ResultSet resultSet = null; try { con = this.ds.getConnection(); stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String sql = "select * from ITEM where id=" + key ; resultSet = stmt.executeQuery(sql); if (resultSet.next()) { this.setId(resultSet.getInt(1)); this.setName(resultSet.getString(2)); this.setPrice(resultSet.getBigDecimal(3)); } resultSet.close(); stmt.close(); con.close(); } catch (Exception ex) { throw new FacesException(ex); } } public String doDetail() { this.execSQL(Integer.toString(id)); return "Dsp"; } public ItemDspBean() { } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } }
<navigation-rule> <from-view-id>/DataTableSample01.jsp</from-view-id> <navigation-case> <from-outcome>Dsp</from-outcome> <to-view-id>/itemDsp.jsp</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/itemDsp.jsp</from-view-id> <navigation-case> <from-outcome>DataTableSample01</from-outcome> <to-view-id>/DataTableSample01.jsp</to-view-id> </navigation-case> </navigation-rule>
@CHARSET "UTF-8"; .table-01 { width: 320px; border: 1px #E3E3E3 solid; border-spacing: 0; background: #D5F0F0; } .th { padding: 5px; border: #98DCDC solid; border-width: 0 0 1px 1px; background: #73CECE; color: #FFFFFF; font-weight: bold; line-height: 120%; text-align: center; } .td { padding: 1px; border-style: solid; border-width: 1px; border-color: #FFFFFF #8ED9D9 #8ED9D9 #FFFFFF; color: #1A4444; text-align: center; white-space: nowrap; }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>¥Æ¡¼¥Ö¥ë°ìÍ÷¤Î¥µ¥ó¥×¥ë</title> <link rel="stylesheet" type="text/css" href="jsf.css"> </head> <body> <f:view> <h:dataTable border="1" value="#{itemList.items}" var="item" styleClass="table-01" rowClasses="td" headerClass="th"> <h:column id="column1"> <f:facet name="header"> <h:outputText value="ID"></h:outputText> </f:facet> <h:form> <h:commandLink action="#{itemDsp.doDetail}"> <h:outputText value="#{item.id}"></h:outputText> <t:updateActionListener property="#{itemDsp.id}" value="#{item.id}" /> </h:commandLink> </h:form> </h:column> <h:column id="column2"> <h:outputText value="#{item.name}"></h:outputText> <f:facet name="header"> <h:outputText value="̾Á°"></h:outputText> </f:facet> </h:column> <h:column id="column3"> <h:outputText value="#{item.price}"></h:outputText> <f:facet name="header"> <h:outputText value="ÃÍÃÊ"></h:outputText> </f:facet> </h:column> </h:dataTable> </f:view> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>ITEM¤ÎÌÀºÙɽ¼¨</title> <link rel="stylesheet" type="text/css" href="jsf.css"> </head> <body> <f:view> <h:panelGrid border="1" columns="2" styleClass="table-01"> <h:outputText value="ID"></h:outputText> <h:outputText value="#{itemDsp.id}"></h:outputText> <h:outputText value="̾Á°" ></h:outputText> <h:outputText value="#{itemDsp.name}"></h:outputText> <h:outputText value="²Á³Ê"></h:outputText> <h:outputText value="#{itemDsp.price}"></h:outputText> </h:panelGrid> <h:form> <h:commandButton value="°ìÍ÷¤ËÌá¤ë" action="DataTableSample01"></h:commandButton> </h:form><br> </f:view> </body> </html>
¤³¤Î¥Ú¡¼¥¸¤Ø¤Î¥³¥á¥ó¥È
MGXTRM This is one awesome post.Really thank you! Cool.
jygd9x Thank you ever so for you blog post.Really thank you! Really Great.
7K15xY <a href="http://kzrvjgzndatj.com/">kzrvjgzndatj</a>, [url=http://zobphxbwrurt.com/]zobphxbwrurt[/url], [link=http://ullepwlqtvtr.com/]ullepwlqtvtr[/link], http://ofakqnycnbac.com/
UhmoRH <a href="http://tvggybcecgnm.com/">tvggybcecgnm</a>, [url=http://kmygxdtznmew.com/]kmygxdtznmew[/url], [link=http://mpxnktwnydut.com/]mpxnktwnydut[/link], http://xnenbfjnrzdu.com/