- Listing 3-8. Example of How to Convert a Text Value to a Date/Time Format
- <h:outputText value="#{user.startDate}">
- <f:convertDateTime type="date" dateStyle="medium"/>
- h:outputText>
Jsf 关于日期的格式
Table 3-1. All the Built-in Types for Converting a Date/Time
short 8/24/06
medium August 24, 2006
long August 24, 2006
full Thursday, August 24, 2006
在JSF中 有4中基本类型的事件:
• Value-change events
• Action events
• Data model events
• Phase events
他的生命周期
1. Restore view
2. Apply request values
3. Process validations
4. Update model values
5. Invoke application
6. Render response
一个JSF页面:
- <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
- <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
- <f:view>
- <h:dataTable var="house" value="#{houses}" rendered="#{houses.rowCount>0}">
- <h:column>
- <f:facet name="header">
- <h:outputText value="Address"/>
- f:facet>
- <h:outputText value="#{house.address}"/>
- h:column>
- h:dataTable>
- f:view>
注:<h:datatable> 标记data table,为我们显示一个Table; <f:facet>可以命名一个header or footer. #{houses}中的houses不是一个list 而是Data Model</f:facet></h:datatable>
它所生成的Jsp代码(假设有2条数据.)
- Listing 3-14. The Generated Output of the Code from Listing 3-13
- <table>
- <thead>
- <tr><th>Addressth>tr>thead>
- <tbody id="_id0:tbody_element">
- <tr><td>Our New Housetd>tr>
- <tr><td>Our 2nd Housetd>tr>tbody>table>
An Example Using Quotations
value = "#{houses.name.equals('test')}"
or
value = '#{houses.name.equals("test")}'
相比之下,我更喜欢前者,因为他看上去更标准化.
Jsf的导航系统中,支持最匹配原则.
- Listing 3-20. The JSP for the Add Page
- <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
- <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
- <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
- <f:view>
- <h1>Add a garage sale to your areah1>
- <div class="entry errors"><h:messages globalOnly="true"/>div>
- <h:form>
- <h:panelGrid columns="2" cellpadding="5" border="0">
- <h:outputText value="Address:"/>
- <h:inputText value="#{garageSale.house.address}" size="25"/>
- CHAPTER 3 n JSF FUNDAMENTALS 79
- <h:outputText value="City:"/>
- <h:inputText value="#{garageSale.house.city}" size="25"/>
- <h:outputText value="State:"/>
- <h:inputText value="#{garageSale.house.state}" size="25"/>
- <h:outputText value="Start Time:"/>
- <t:inputDate value="#{garageSale.house.startTime}" type="both"/>
- <h:outputText value="End Time:"/>
- <t:inputDate value="#{garageSale.house.endTime}" type="both"/>
- <f:facet name="footer">
- <h:commandButton type="submit" value="Add House" action="#{garageSale.addHouse}"/>
- f:facet>
- h:panelGrid>
- h:form>
- f:view>
其中就用到了tomahawk 包中的日期标签.