ArticlesTutorialsInterview Questions & AnswersCertificationsFree Books & Sample ChaptersTechnical Discussions  Your Account | Advertise with us | Feedback |
Few pages of this site are under construction and we are constantly trying to improve it. If you have any suggestions or ideas about how to improve the site, please Let us know.
Tomahawk CommandSortHeader

 t:commandNavigation2 Tomahawk Tag Home t:dataList 

<t:commandSortHeader>


Contents

  1. Introduction
  2. Tag Attributes
  3. Example

Introduction

The t:commandSortHeader tag generates a clickable sort column header. It must be nested inside a dataTable. This tag extends the JSF commandLink tag and adds two new attributes, columnName and arrow.

Note :In contrast to normal command links, the default for the "immediate" attribute is "true". This is desirable as it avoids validating all input fields in the enclosing form when the column sort order changes. HOWEVER when the table contains input components "immediate" must be set to false; otherwise input fields will render blank after a sort, or will show their old values (ie will not appear to sort though output fields in the table will sort) when sort ordering is changed.

Tag Attributes


AttributeDescription   Type    
accesskey The accesskey attribute is a standard HTML attribute that sets the access key that transfers focus to this element when pressed.String
action A method binding EL expression that identifies an action method to be invoked if this component is activated by the user. An action method must be a public method with no parameters that returns a String,called the action outcome, that identifies the next view displayed. The phase that this event is fired in can be controlled via the immediate attribute. String
actionFor The actionFor attribute expects a comma-separated list of component IDs associated with the component generating the action event. You need to wrap your input components in org.apache.myfaces.custom.subform.SubForm instances for this to work.String
actionListener The actionListener attribute accepts a method-binding expression for a backing bean action listener method that will be notified when this component is activated by the user. An action listener method must be a public method with an javax.faces.event.ActionEvent parameter and a void return type.The phase that this event is fired in can be controlled via the immediate attribute.String
alt The alt attribute is a standard HTML attribute that sets the alternate textual description rendered by this component.String
binding The value-binding expression linking this component tag to a backing bean property.String
charset The charset attribute identifies the character encoding of the resource linked to by this hyperlink.String
columnName(required) The columnName attribute uniquely identifies the column within the parent dataTable component. It is used in association with the sortColumn attribute of the containing extended dataTable tag.String
coords The coords attribute sets the position and shape of the hotspot on the screen when using this link with a client-side image map.String
dir The dir attribute is a standard HTML attribute that overrides the default text directionality for this component. The values accepted for this component are "LTR" (left-to-right) and "RTL" (right-to-left). String
disabled HTML: When true, this element cannot receive focus.String
enabledOnUserRole If user is in given role, this component will be rendered normally. If not, no hyperlink is rendered but all nested tags (=body) are rendered.String
forceId A boolean value;If true, this component will force the use of the specified id when rendering.String
forceIdIndex The forceIdIndex attribute effects the component ID name when this component is rendered at runtime. It expects a boolean value that, when true, causes the component to display an index number in its ID value if the component is in a list. It has a default value of true. String
id The unique identifier value for this component. The value must be unique within the closest naming container (e.g.,h:form or f:subview).This value must be a static value.String
image The URL of an image that renders in place of the button.String
immediate A boolean value that identifies the phase during which action events should fire. During normal event processing, action methods and action listener methods are fired during the "invoke application" phase of request processing. If this attribute is set to "true", these methods are fired instead at the end of the "apply request values" phase.String
relThe rel attribute identifies the relationship from the current document to the anchor specified by this hyperlink. The value of this attribute is a space-separated list of link types.String
renderedA boolean value that indicates whether this component should be rendered.Default value: true.String
revThe rev attribute identifies a reverse link from the anchor specified by this hyperlink to the current document. The value of this attribute is a space-separated list of link types.String
shapeThe shape attribute sets the shape of the hotspot on the screen when using this link with a client-side image map. The valid values for this attribute are: default (entire region), rect (rectangular region), circle (circular region), and poly (polygonal region). String
sizeThe initial width of this control.String
styleThe style attribute sets the CSS style definition to be applied to this component when it is rendered.String
styleClassThe styleClass attribute sets the CSS class to apply to this component when it is rendered.String
tabindextabindex String The tabindex attribute is a standard HTML attribute that sets the order in which this element receives focus when the user cycles through the elements using the TAB key. The value for this attribute must be an integer between 0 and 32767. String
targetThe target attribute identifies the name of a frame into which the resource retrieved by this hyperlink should be displayed.String
titleAn advisory title for this element. Often used by the user agent as a tooltip.String
typeThe type attribute specifies the HTML content type associated with the resource pointed to by this hyperlink.String
valueThe value attribute sets the current value for this component.String
visibleOnUserRoleIf user is in given role, this component will be rendered normally. If not, nothing is rendered and the body of this tag will be skipped. String
onblur, onchange,etc., DHTML EventsString


Example



 As an example suppose we need to have list of car information to some of the entities in our application. First thing to do is to create the SimpleCar class with the id,type and color.


SimpleCar.java

package com.developersBook.tomahawk.examples.listExample;
import java.io.Serializable;
public class SimpleCar implements Serializable
{
private int id;
private String type;
private String color;
public SimpleCar(int id, String type, String color) {
super();
this.id = id;
this.type = type;
this.color = color;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}


PagedSortableCarList.java

package com.developersBook.tomahawk.examples.listExample;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class PagedSortableCarList extends SortableList
private List cars = new ArrayList();
private Map carMap = new HashMap();
public PagedSortableCarList()
{super("type");
for (int i = 100; i < 900; i++)
{
Object car = new SimpleCar(i,
            "Car Type " + i, (i % 2 == 0) ? "blue" : "green");
cars.add(car);
carMap.put(new Integer(i), car);
}
}

public List getCars()
{
sort(getSort(), isAscending());
return cars;
}

public void setCars(List cars)
{
// update the cars from the provided list
for (Iterator iter = cars.iterator(); iter.hasNext();)
{
SimpleCar car = (SimpleCar) iter.next();
SimpleCar oldCar = (SimpleCar) carMap.get(new Integer(car.getId()));
oldCar.setType(car.getType());
oldCar.setColor(car.getColor());
}
}

protected boolean isDefaultAscending(String sortColumn)
{
return true;
}

protected void sort(final String column, final boolean ascending)
{
Comparator comparator = new Comparator()
{
public int compare(Object o1, Object o2)
{
SimpleCar c1 = (SimpleCar) o1;
SimpleCar c2 = (SimpleCar) o2;
if (column == null)
{
return 0;
}
if (column.equals("type"))
{
return ascending ? c1.getType()
           .compareTo(c2.getType()) : c2.getType()
           .compareTo(c1.getType());
}
else if (column.equals("color"))
{
return ascending ? c1.getColor()
           .compareTo(c2.getColor()) : c2.getColor()
           .compareTo(c1.getColor());
}
else
return 0;
}
};
Collections.sort(cars, comparator);
}
}


PagedSortableCarList.jsp

<%@ page session="false" contentType="text/html;charset=utf-8"%>
<%@ 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"%>
<html>
<body>
  <f:view>
<f:loadBundle basename="com.developersBook.example_messages"
    var="example_messages"/>
<h:form>
<t:dataTable id="data"    styleClass="scrollerTable"
    headerClass="standardTable_Header"
    footerClass="standardTable_Header"
    rowClasses="standardTable_Row1,standardTable_Row2"
     columnClasses="standardTable_Column,
standardTable_ColumnCentered,standardTable_Column"
    var="car"
    value="#{pagedSort.cars}"
    preserveDataModel="true"
    rows="10"
    rowId="#{car.type}"
    rowOnClick="alert('rowId: ' + this.id)"
    sortColumn="#{pagedSort.sort}"
    sortAscending="#{pagedSort.ascending}"
    preserveSort="true">
<h:column>
<f:facet name="header">
</f:facet>
<h:outputText value="#{car.id}" />
</h:column>
<h:column>
<f:facet name="header">
    <t:commandSortHeader columnName="type"
        arrow="true" immediate="false">
    <h:outputText value="#{example_messages['sort_cartype']}" />
    </t:commandSortHeader>
</f:facet>
<h:outputText value="#{car.type}" />
</h:column>
<h:column>
<f:facet name="header">
    <t:commandSortHeader columnName="color"
        arrow="true" immediate="false">
     <h:outputText value="#{example_messages['sort_carcolor']}" />
    </t:commandSortHeader>
</f:facet>
<h:inputText value="#{car.color}" >
    <f:validateLength maximum="10"/>
</h:inputText>
</h:column>
</t:dataTable>
<h:panelGrid columns="1" styleClass="scrollerTable2"
        columnClasses="standardTable_ColumnCentered" >
<t:dataScroller id="scroll_1"
    for="data"
        fastStep="10"
        pageCountVar="pageCount"
         pageIndexVar="pageIndex"
         styleClass="scroller"
         paginator="true"
         paginatorMaxPages="9"
         paginatorTableClass="paginator"
         paginatorActiveColumnStyle="font-weight:bold;">
<f:actionListener
type="com.developersBook.tomahawk
        .examples.listExample.DataScrollerActionListener"/>
        <f:facet name="first" >
    <t:graphicImage url="images/arrow-first.gif" border="1" />
        </f:facet>
         <f:facet name="last">
     <t:graphicImage url="images/arrow-last.gif" border="1" />
        </f:facet>
        <f:facet name="previous">
    <t:graphicImage url="images/arrow-previous.gif" border="1" />
        </f:facet>
        <f:facet name="next">
    <t:graphicImage url="images/arrow-next.gif" border="1" />
        </f:facet>
        <f:facet name="fastforward">
    <t:graphicImage url="images/arrow-ff.gif" border="1" />
        </f:facet>
        <f:facet name="fastrewind">
    <t:graphicImage url="images/arrow-fr.gif" border="1" />
</f:facet>
</t:dataScroller>
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
 t:commandNavigation2 Tomahawk Tag Home t:dataList 
Related Links

Tomahawk
t:aliasBean
t:aliasBeansScope
t:buffer
t:checkbox
t:collapsiblePanel
t:column
t:columns
t:commandButton
t:commandLink
t:commandNavigation
t:commandNavigation2
t:commandSortHeader
t:dataList
t:dataScroller
t:dataTable
t:div
t:document
t:documentBody
t:documentHead
t:dojoInitializer
t:graphicImage
t:headerLink
t:htmlTag
t:iconProvider
t:inputCalendar
t:inputDate
t:inputFileUpload
t:inputHidden
t:inputHtml
t:inputSecret
t:inputText
t:inputTextHelp
t:inputTextarea
t:jsValueChangeListener
t:jsValueSet
t:jscookMenu
t:message
t:messages
t:navigationMenuItem
t:navigationMenuItems
t:newspaperTable
t:outputLabel
t:outputText
t:panelGrid
t:panelGroup
t:panelLayout
t:panelNavigation
t:panelNavigation2
t:panelStack
t:panelTab
t:panelTabbedPane
t:popup
t:radio
t:saveState
t:schedule
t:selectBooleanCheckbox
t:selectItems
t:selectManyCheckbox
t:selectManyListbox
t:selectManyMenu
t:selectOneCountry
t:selectOneLanguage
t:selectOneListbox
t:selectOneMenu
t:selectOneRadio
t:stylesheet
t:swapImage
t:tabChangeListener
t:tree
t:tree2
t:treeCheckbox
t:treeColumn
t:treeSelectionListener
t:updateActionListener
t:validateCreditCard
t:validateEmail
t:validateEqual
t:validateRegExpr
Core Tags
f:actionListener
f:attribute
f:converter
f:convertDateTime
f:convertNumber
f:facet
f:loadBundle
f:param
f:selectitem
f:selectitems
f:subview
f:validateDoubleRange
f:validateLength
f:validateLongRange
f:validator
f:valueChangeListener
f:verbatim
f:view
HTML Tags
h:column
h:commandButton
h:commandLink
h:dataTable
h:form
h:graphicImage
h:inputHidden
h:inputSecret
h:inputText
h:inputTextarea
h:message
h:messages
h:outputFormat
h:outputLabel
h:outputLink
h:outputText
h:panelGrid
h:panelGroup
h:selectBooleanCheckbox
h:selectManyCheckbox
h:selectManyListbox
h:selectManyMenu
h:selectOneListbox
h:selectOneMenu
h:selectOneRadio
Tomahawk
t:aliasBean
t:aliasBeansScope
t:buffer
t:checkbox
t:collapsiblePanel
t:column
t:columns
t:commandButton
t:commandLink
t:commandNavigation
t:commandNavigation2
t:commandSortHeader
t:dataList
t:dataScroller
t:dataTable
t:div
t:document
t:documentBody
t:documentHead
t:dojoInitializer
t:graphicImage
t:headerLink
t:htmlTag
t:iconProvider
t:inputCalendar
t:inputDate
t:inputFileUpload
t:inputHidden
t:inputHtml
t:inputSecret
t:inputText
t:inputTextHelp
t:inputTextarea
t:jsValueChangeListener
t:jsValueSet
t:jscookMenu
t:message
t:messages
t:navigationMenuItem
t:navigationMenuItems
t:newspaperTable
t:outputLabel
t:outputText
t:panelGrid
t:panelGroup
t:panelLayout
t:panelNavigation
t:panelNavigation2
t:panelStack
t:panelTab
t:panelTabbedPane
t:popup
t:radio
t:saveState
t:schedule
t:selectBooleanCheckbox
t:selectItems
t:selectManyCheckbox
t:selectManyListbox
t:selectManyMenu
t:selectOneCountry
t:selectOneLanguage
t:selectOneListbox
t:selectOneMenu
t:selectOneRadio
t:stylesheet
t:swapImage
t:tabChangeListener
t:tree
t:tree2
t:treeCheckbox
t:treeColumn
t:treeSelectionListener
t:updateActionListener
t:validateCreditCard
t:validateEmail
t:validateEqual
t:validateRegExpr
Core Tags
f:actionListener
f:attribute
f:converter
f:convertDateTime
f:convertNumber
f:facet
f:loadBundle
f:param
f:selectitem
f:selectitems
f:subview
f:validateDoubleRange
f:validateLength
f:validateLongRange
f:validator
f:valueChangeListener
f:verbatim
f:view
HTML Tags
h:column
h:commandButton
h:commandLink
h:dataTable
h:form
h:graphicImage
h:inputHidden
h:inputSecret
h:inputText
h:inputTextarea
h:message
h:messages
h:outputFormat
h:outputLabel
h:outputLink
h:outputText
h:panelGrid
h:panelGroup
h:selectBooleanCheckbox
h:selectManyCheckbox
h:selectManyListbox
h:selectManyMenu
h:selectOneListbox
h:selectOneMenu
h:selectOneRadio

  ALSO SEE :

About Us | Our Mission | Terms of use | Author Terms |    Search        | Contact Us | Advertise With Us | Link to Us | Sitemap
Copyright © 2016 developersBOOK.COM. All rights reserved.