初试JSF(2)

xml 代码
  1. Listing 3-8. Example of How to Convert a Text Value to a Date/Time Format   
  2. <h:outputText value="#{user.startDate}">  
  3. <f:convertDateTime type="date" dateStyle="medium"/>  
  4. 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页面:

xml 代码
  1. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>  
  2. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>  
  3. <f:view>  
  4. <h:dataTable var="house" value="#{houses}" rendered="#{houses.rowCount>0}">  
  5. <h:column>  
  6. <f:facet name="header">  
  7. <h:outputText value="Address"/>  
  8. f:facet>  
  9. <h:outputText value="#{house.address}"/>  
  10. h:column>  
  11. h:dataTable>  
  12. f:view>  

注:<h:datatable> 标记data table,为我们显示一个Table; <f:facet>可以命名一个header or footer. #{houses}中的houses不是一个list 而是Data Model</f:facet></h:datatable>

它所生成的Jsp代码(假设有2条数据.)

xml 代码
  1. Listing 3-14. The Generated Output of the Code from Listing 3-13   
  2. <table>  
  3. <thead>  
  4. <tr><th>Addressth>tr>thead>  
  5. <tbody id="_id0:tbody_element">  
  6. <tr><td>Our New Housetd>tr>  
  7. <tr><td>Our 2nd Housetd>tr>tbody>table>  

 

 An Example Using Quotations

value = "#{houses.name.equals('test')}"
or
value = '#{houses.name.equals("test")}'

相比之下,我更喜欢前者,因为他看上去更标准化.

Jsf的导航系统中,支持最匹配原则.

xml 代码
  1. Listing 3-20. The JSP for the Add Page   
  2. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>  
  3. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>  
  4. <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>  
  5. <f:view>  
  6. <h1>Add a garage sale to your areah1>  
  7. <div class="entry errors"><h:messages globalOnly="true"/>div>  
  8. <h:form>  
  9. <h:panelGrid columns="2" cellpadding="5" border="0">  
  10. <h:outputText value="Address:"/>  
  11. <h:inputText value="#{garageSale.house.address}" size="25"/>  
  12. CHAPTER 3 n JSF FUNDAMENTALS 79   
  13. <h:outputText value="City:"/>  
  14. <h:inputText value="#{garageSale.house.city}" size="25"/>  
  15. <h:outputText value="State:"/>  
  16. <h:inputText value="#{garageSale.house.state}" size="25"/>  
  17. <h:outputText value="Start Time:"/>  
  18. <t:inputDate value="#{garageSale.house.startTime}" type="both"/>  
  19. <h:outputText value="End Time:"/>  
  20. <t:inputDate value="#{garageSale.house.endTime}" type="both"/>  
  21. <f:facet name="footer">  
  22. <h:commandButton type="submit" value="Add House" action="#{garageSale.addHouse}"/>  
  23. f:facet>  
  24. h:panelGrid>  
  25. h:form>  
  26. f:view>  

其中就用到了tomahawk 包中的日期标签.

 

 

你可能感兴趣的:(xml,jsp,F#,JSF,sun)