tomahawk JSF组件扩展组件(二)

tomahawk JSF组件扩展组件(二)

tomahawk JSF组件扩展组件(二)

关键字: t

九.使用DataModel作为table的列或数据。

Java代码
  1. List headerList = new ArrayList();  
  2.         headerList.add(new ColumnHeader("Index","100",false));  
  3.         headerList.add(new ColumnHeader("Type","200",true));  
  4.         headerList.add(new ColumnHeader("Model","300",true));  
  5.         columnHeaders = new ListDataModel(headerList);  
  6.   
  7. List rowList = new ArrayList();  
  8.         for (int i = 100; i <= 999; i++)  
  9.         {  
  10.             List colList = new ArrayList();  
  11.             colList.add(new Integer(i));  
  12.             colList.add("Car Type " + i);  
  13.             colList.add((i%2==0) ? "blue" : "green");  
  14.             rowList.add(colList);  
  15.         }  
  16.         data = new ListDataModel(rowList);  
  17.   
  18. public void setColumnValue(Object value)  
  19.     {  
  20.       if (data.isRowAvailable() && columnHeaders.isRowAvailable())  
  21.       {  
  22.           ((List)data.getRowData()).set(columnHeaders.getRowIndex(), value);  
  23.       }  
  24.     }  
  25.   
  26.     public String getColumnWidth()  
  27.     {  
  28.         String columnWidth = null;  
  29.         if (data.isRowAvailable() && columnHeaders.isRowAvailable())  
  30.         {  
  31.             columnWidth = ((ColumnHeader)columnHeaders.getRowData()).getWidth();  
  32.         }  
  33.         return columnWidth;  
  34.     }  
List headerList = new ArrayList();
headerList.add(new ColumnHeader("Index","100",false));
headerList.add(new ColumnHeader("Type","200",true));
headerList.add(new ColumnHeader("Model","300",true));
columnHeaders = new ListDataModel(headerList);
List rowList = new ArrayList();
for (int i = 100; i <= 999; i++)
{
List colList = new ArrayList();
colList.add(new Integer(i));
colList.add("Car Type " + i);
colList.add((i%2==0) ? "blue" : "green");
rowList.add(colList);
}
data = new ListDataModel(rowList);
public void setColumnValue(Object value)
{
if (data.isRowAvailable() && columnHeaders.isRowAvailable())
{
((List)data.getRowData()).set(columnHeaders.getRowIndex(), value);
}
}
public String getColumnWidth()
{
String columnWidth = null;
if (data.isRowAvailable() && columnHeaders.isRowAvailable())
{
columnWidth = ((ColumnHeader)columnHeaders.getRowData()).getWidth();
}
return columnWidth;
}

 再动态地在<t:datatable>中生成列与行数据:

Java代码
  1. <t:columns id="columns" value="#{openDataList.columnHeaders}"   
  2.                   var="columnHeader" style="width:#{openDataList.columnWidth}px">  
  3.     <f:facet name="header">  
  4.         <t:commandSortHeader columnName="#{columnHeader.label}" arrow="false" immediate="false">  
  5.             <f:facet name="ascending">  
  6.                 <t:graphicImage value="images/ascending-arrow.gif" rendered="true" border="0"/>  
  7.             </f:facet>  
  8.             <f:facet name="descending">  
  9.                 <t:graphicImage value="images/descending-arrow.gif" rendered="true" border="0"/>  
  10.             </f:facet>  
  11.             <h:outputText value="#{columnHeader.label}" />  
  12.         </t:commandSortHeader>  
  13.     </f:facet>  
  14.     <!-- row is also available -->  
  15.     <h:inputText rendered="#{openDataList.valueModifiable}" value="#{openDataList.columnValue}" />  
  16.     <h:outputText rendered="#{!openDataList.valueModifiable}" value="#{openDataList.columnValue}" />  
  17. </t:columns>  
<t:columns id="columns" value="#{openDataList.columnHeaders}"
var="columnHeader" style="width:#{openDataList.columnWidth}px">
<f:facet name="header">
<t:commandSortHeader columnName="#{columnHeader.label}" arrow="false" immediate="false">
<f:facet name="ascending">
<t:graphicImage value="images/ascending-arrow.gif" rendered="true" border="0"/>
</f:facet>
<f:facet name="descending">
<t:graphicImage value="images/descending-arrow.gif" rendered="true" border="0"/>
</f:facet>
<h:outputText value="#{columnHeader.label}" />
</t:commandSortHeader>
</f:facet>
<!-- row is also available -->
<h:inputText rendered="#{openDataList.valueModifiable}" value="#{openDataList.columnValue}" />
<h:outputText rendered="#{!openDataList.valueModifiable}" value="#{openDataList.columnValue}" />
</t:columns>

 十.<t:panelTabbedPane>的使用

Java代码
  1. <t:panelTabbedPane bgcolor="#FFFFCC" >  
  2.     <!-- 所有tab都有组件写在panelTab组件的前面-->  
  3.     <f:verbatim><p></f:verbatim>  
  4.     <h:outputText value="#{example_messages['tabbed_common']}"/>  
  5.     <f:verbatim></p></f:verbatim>  
  6.     <t:panelTab id="tab1" label="#{example_messages['tabbed_tab1']}"   
  7.                     rendered="#{tabbedPaneBean.tab1Visible}">  
  8.         <h:selectBooleanCheckbox id="testCheckBox" value="#{testCheckBox.checked}"/>  
  9.         <h:outputLabel for="testCheckBox" value="A checkbox"/>  
  10.         <f:verbatim><br/><br/></f:verbatim>  
  11.         <h:inputText id="inp1"/><f:verbatim><br></f:verbatim>  
  12.         <h:inputText id="inp2" required="true" />  
  13.         <h:message for="inp2" showSummary="false" showDetail="true" />  
  14.     </t:panelTab>  
  15.     <f:subview id="tab2" >  
  16.         <jsp:include page="tab2.jsp"/>  
  17.     </f:subview>  
  18. </t:panelTabbedPane>  
<t:panelTabbedPane bgcolor="#FFFFCC" >
<!-- 所有tab都有组件写在panelTab组件的前面-->
<f:verbatim><p></f:verbatim>
<h:outputText value="#{example_messages['tabbed_common']}"/>
<f:verbatim></p></f:verbatim>
<t:panelTab id="tab1" label="#{example_messages['tabbed_tab1']}"
rendered="#{tabbedPaneBean.tab1Visible}">
<h:selectBooleanCheckbox id="testCheckBox" value="#{testCheckBox.checked}"/>
<h:outputLabel for="testCheckBox" value="A checkbox"/>
<f:verbatim><br/><br/></f:verbatim>
<h:inputText id="inp1"/><f:verbatim><br></f:verbatim>
<h:inputText id="inp2" required="true" />
<h:message for="inp2" showSummary="false" showDetail="true" />
</t:panelTab>
<f:subview id="tab2" >
<jsp:include page="tab2.jsp"/>
</f:subview>
</t:panelTabbedPane>

十一.js日期弹出式组件<t:inputCalendar>

Java代码
  1. <t:inputCalendar monthYearRowClass="yearMonthHeader" weekRowClass="weekHeader"  
  2.                 currentDayCellClass="currentDayCell" value="#{calendarBean.secondDate}"   
  3.                 renderAsPopup="true" popupTodayString="#{example_messages['popup_today_string']}"   
  4.                 popupWeekString="#{example_messages['popup_week_string']}"  
  5.                 renderPopupButtonAsImage="true" />  
<t:inputCalendar monthYearRowClass="yearMonthHeader" weekRowClass="weekHeader"
currentDayCellClass="currentDayCell" value="#{calendarBean.secondDate}"
renderAsPopup="true" popupTodayString="#{example_messages['popup_today_string']}"
popupWeekString="#{example_messages['popup_week_string']}"
renderPopupButtonAsImage="true" />

 十二.jscookmenu的使用。

Java代码
  1. <t:jscookMenu layout="hbr" theme="ThemeOffice">  
  2.     <%/* Availaible jscookMenu themes: ThemeIE, ThemeMiniBlack, ThemeOffice, ThemePanel 
  3.              Availaible jscookMenu layout: hbr, hbl, hur, hul, vbr, vbl, vur, vul 
  4.              respect to Heng Yuan http://www.cs.ucla.edu/~heng/JSCookMenu 
  5.     */%>  
  6.     <t:navigationMenuItem id="nav_1"  
  7.             itemLabel="#{example_messages['nav_Home']}" action="go_home" />  
  8.     <t:navigationMenuItem id="nav_2"  
  9.             itemLabel="#{example_messages['nav_Examples']}">  
  10.             <t:navigationMenuItem id="nav_2_1"  
  11.                    itemLabel="#{example_messages['nav_Sample_1']}" action="go_sample1" />  
  12.     </t:navigationMenuItem>  
  13.  </t:jscookMenu>  
<t:jscookMenu layout="hbr" theme="ThemeOffice">
<%/* Availaible jscookMenu themes: ThemeIE, ThemeMiniBlack, ThemeOffice, ThemePanel
Availaible jscookMenu layout: hbr, hbl, hur, hul, vbr, vbl, vur, vul
respect to Heng Yuan http://www.cs.ucla.edu/~heng/JSCookMenu
*/%>
<t:navigationMenuItem id="nav_1"
itemLabel="#{example_messages['nav_Home']}" action="go_home" />
<t:navigationMenuItem id="nav_2"
itemLabel="#{example_messages['nav_Examples']}">
<t:navigationMenuItem id="nav_2_1"
itemLabel="#{example_messages['nav_Sample_1']}" action="go_sample1" />
</t:navigationMenuItem>
</t:jscookMenu>

 十三.<t:panelNavigation2>组件:

Java代码
  1. <t:panelNavigation2 id="nav1" layout="list" itemClass="mypage"   
  2.                                  activeItemClass="selected" openItemClass="selected" >  
  3.   <t:commandNavigation2 value="#{example_messages['panelnav_products']}" action="" >  
  4.             <t:commandNavigation2 action="go_panelnavigation_1" >  
  5.                 <f:verbatim>› </f:verbatim>  
  6.                 <t:outputText value="#{example_messages['panelnav_serach1']}" />  
  7.             </t:commandNavigation2>  
  8.             <t:commandNavigation2 action="go_panelnavigation_1" >  
  9.                 <f:verbatim>› </f:verbatim>  
  10.                 <t:outputText value="#{example_messages['panelnav_serach_acc1']}" />  
  11.             </t:commandNavigation2>  
  12.             <t:commandNavigation2 action="go_panelnavigation_1" >  
  13.                 <f:verbatim>› </f:verbatim>  
  14.                 <t:outputText value="#{example_messages['panelnav_search_adv1']}" />  
  15.             </t:commandNavigation2>  
  16.         </t:commandNavigation2>  
  17.         <t:commandNavigation2 value="#{example_messages['panelnav_shop']}" action="" />  
  18.   
  19. </t:panelNavigation2>  
<t:panelNavigation2 id="nav1" layout="list" itemClass="mypage"
activeItemClass="selected" openItemClass="selected" >
<t:commandNavigation2 value="#{example_messages['panelnav_products']}" action="" >
<t:commandNavigation2 action="go_panelnavigation_1" >
<f:verbatim>› </f:verbatim>
<t:outputText value="#{example_messages['panelnav_serach1']}" />
</t:commandNavigation2>
<t:commandNavigation2 action="go_panelnavigation_1" >
<f:verbatim>› </f:verbatim>
<t:outputText value="#{example_messages['panelnav_serach_acc1']}" />
</t:commandNavigation2>
<t:commandNavigation2 action="go_panelnavigation_1" >
<f:verbatim>› </f:verbatim>
<t:outputText value="#{example_messages['panelnav_search_adv1']}" />
</t:commandNavigation2>
</t:commandNavigation2>
<t:commandNavigation2 value="#{example_messages['panelnav_shop']}" action="" />
</t:panelNavigation2>

 也可以动态地生成navigationMenuItem:

Java代码
  1. <t:panelNavigation2 id="nav1" layout="list" itemClass="mypage" activeItemClass="selected" openItemClass="selected" >  
  2.         <t:navigationMenuItems value="#{navigationMenu.panelNavigationItems}" />  
  3.     </t:panelNavigation2>  
  4.   
  5. panelNavigationItems方法:  
  6.   
  7. public List getPanelNavigationItems() {  
  8.         List menu = new ArrayList();  
  9.         // Products  
  10.         NavigationMenuItem products = getMenuNaviagtionItem("#{example_messages['panelnav_products']}"null);  
  11.         menu.add(products);  
  12.         products.add(getMenuNaviagtionItem("#{example_messages['panelnav_serach']}""#{navigationMenu.getAction2}"));  
  13.         products.add(getMenuNaviagtionItem("#{example_messages['panelnav_serach_acc']}""#{navigationMenu.getAction2}"));  
  14.         NavigationMenuItem item = getMenuNaviagtionItem("#{example_messages['panelnav_search_adv']}""#{navigationMenu.getAction2}");  
  15.         item.setActive(true);  
  16.         item.setOpen(true);  
  17.         item.setTarget("_blank");  
  18.         products.add(item);  
  19.         // Shop  
  20.         menu.add(getMenuNaviagtionItem("#{example_messages['panelnav_shop']}""#{navigationMenu.getAction2}"));  
  21.         // Corporate Info  
  22.         NavigationMenuItem corporateInfo = getMenuNaviagtionItem("#{example_messages['panelnav_corporate']}"null);  
  23.         menu.add(corporateInfo);  
  24.         corporateInfo.add(getMenuNaviagtionItem("#{example_messages['panelnav_news']}""#{navigationMenu.getAction2}"));  
  25.         item = getMenuNaviagtionItem("#{example_messages['panelnav_investor']}""#{navigationMenu.getAction3}");  
  26.         //item.setIcon("images/arrow-first.gif");  
  27.         item.setDisabled(true);  
  28.         corporateInfo.add(item);  
  29.         // Contact  
  30.         menu.add(getMenuNaviagtionItem("#{example_messages['panelnav_contact']}""#{navigationMenu.getAction2}"));  
  31.         // External Link  
  32.         item = getMenuNaviagtionItem("#{example_messages['panelnav_contact']}"null);  
  33.         item.setExternalLink("#{example_messages['external_link']}");  
  34.         item.setTarget("_blank");  
  35.         menu.add(item);  
  36.         return menu;  
  37.     }  
<t:panelNavigation2 id="nav1" layout="list" itemClass="mypage" activeItemClass="selected" openItemClass="selected" >
<t:navigationMenuItems value="#{navigationMenu.panelNavigationItems}" />
</t:panelNavigation2>
panelNavigationItems方法:
public List getPanelNavigationItems() {
List menu = new ArrayList();
// Products
NavigationMenuItem products = getMenuNaviagtionItem("#{example_messages['panelnav_products']}", null);
menu.add(products);
products.add(getMenuNaviagtionItem("#{example_messages['panelnav_serach']}", "#{navigationMenu.getAction2}"));
products.add(getMenuNaviagtionItem("#{example_messages['panelnav_serach_acc']}", "#{navigationMenu.getAction2}"));
NavigationMenuItem item = getMenuNaviagtionItem("#{example_messages['panelnav_search_adv']}", "#{navigationMenu.getAction2}");
item.setActive(true);
item.setOpen(true);
item.setTarget("_blank");
products.add(item);
// Shop
menu.add(getMenuNaviagtionItem("#{example_messages['panelnav_shop']}", "#{navigationMenu.getAction2}"));
// Corporate Info
NavigationMenuItem corporateInfo = getMenuNaviagtionItem("#{example_messages['panelnav_corporate']}", null);
menu.add(corporateInfo);
corporateInfo.add(getMenuNaviagtionItem("#{example_messages['panelnav_news']}", "#{navigationMenu.getAction2}"));
item = getMenuNaviagtionItem("#{example_messages['panelnav_investor']}", "#{navigationMenu.getAction3}");
//item.setIcon("images/arrow-first.gif");
item.setDisabled(true);
corporateInfo.add(item);
// Contact
menu.add(getMenuNaviagtionItem("#{example_messages['panelnav_contact']}", "#{navigationMenu.getAction2}"));
// External Link
item = getMenuNaviagtionItem("#{example_messages['panelnav_contact']}", null);
item.setExternalLink("#{example_messages['external_link']}");
item.setTarget("_blank");
menu.add(item);
return menu;
}

你可能感兴趣的:(tomahawk JSF组件扩展组件(二))