日期:2014-05-16 浏览次数:20524 次
?
先来看看JSF的组成:
| 
 
  | 
  | 
?
Template的例子:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
<html><head><title>Items</title></head><body>
<h:form id="items">
   <h:dataTable id="itemlist” value="#{JsfBean.allItems}” var="entry">
      <h:column>
         <f:facet name="header">
            <h:outputText value=""/>
         </f:facet>
         <h:selectBooleanCheckbox id="itemSelect" value="#{entry.selected}" 
	rendered="#{entry.canDelete}"/>
         <h:outputText value="" rendered="#{not entry.canDelete}"/>
      </h:column>
</h:form>
</body></html>
</f:view>
?
faces-config.xml的例子 :
<faces-config>
   <navigation-rule>
    <from-view-id>/jsf/JsfItems.jsp</from-view-id>
    <navigation-case>
        <from-outcome>newItem</from-outcome>
        <to-view-id>/jsf/JsfAddItem.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-outcome>*</from-outcome>
        <to-view-id>/jsf/JsfItems.jsp</to-view-id>
    </navigation-case>
   </navigation-rule>
   <managed-bean>
        <managed-bean-name>JsfBean</managed-bean-name>
        <managed-bean-class>org.example.jsf.JsfBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
        <property-name>logic</property-name>
        <value>#{someLogicBean}</value>
    </managed-property>
   </managed-bean>
</faces-config>
<h:commandButton id="submit" action="newItem" value="Submit" /> 
<h:commandButton id="submit" action="#{JsfAppBean.processActionNew}" value="Submit" /> 
?其中,JsfAppBean.processActionNew返回"newItem"public String processActionNew() {
   currentItem = null;
   itemText = TEXT_DEFAULT;
   itemHidden = HIDDEN_DEFAULT;
   return "newItem";
}
?<h:dataTable id="itemlist” value="#{JsfBean.allItems}” var="entry">...
FacesContext context = FacesContext.getCurrentInstance();
ValueBinding binding = context.getApplication().createValueBinding("#{JsfBean}");
UserBean user = (UserBean) binding.getValue(context);
?