|
MyEclipse 下开发JSF教程(11) actionListener="#{bookBean.initBook}"> <h:outputText value="Add a book" /> </h:commandLink> </h:form> </f:view> </body> </html>
<%@ taglib uri="http://Java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://Java.sun.com/jsf/core" prefix="f" %> With directive taglib we include the JSF tag libraries <f:view> Renders a view component. All others tags must be included within this tag. <h:form id="bookList"> Renders a HTML form. <h:dataTable id="books" value="#{bookListBean.books}" var="book" border="1">Renders a HTML table. The tag is used to loop over a list of data like a for loop. The parameter value assign a list of data, in our case the list of books of the library. With the parameter var you define the variable used to Access a element (a book) of the list within the tag (loop). <h:column> <f:facet name="header"> <h:outputText value="Author"/> </f:facet> <h:outputText value="#{book.author}" /> </h:column> Renders a column with a column header. <f:facet name="header"> display the header. <h:outputText value="Author"/> print out a header label. <h:outputText value="#{book.author}" /> refers to the property author of the current element of the list. <h:commandLink id="Edit" action="editBook" actionListener="#{bookBean.selectBook}"> Renders a HTML link, which submits the form. The parameter action define the navigation case, which is processed, after the form submits In our case the navigation case editBook, we have added befor in the faces-config.XML, will be processed. We assign the action listener method to the link with the parameter actionListener. After the user submit the form the method will be processed.
|