Sorting Column - Case Insensitive but Lower should be first
Hi all,
Lets assume we have am EMployee table :
create table Emp (Empname varchar2(20));
It has following records :
Insert into EMP (EMPNAME) values ('A');
Insert into EMP (EMPNAME) values ('a');
Insert into EMP (EMPNAME) values ('b');
Insert into EMP (EMPNAME) values ('c');
Insert into EMP (EMPNAME) values ('D');
Insert into EMP (EMPNAME) values ('e');
Insert into EMP (EMPNAME) values ('E');
Insert into EMP (EMPNAME) values ('F');
i.e
Empname
A
a
b
c
D
e
E
F
I need output as below : ( Sort by Ascending, case insensitive meaning I don't want all Capital first and then Lower letters. The results should be in alphabetical order it shouldn't matter whether its capital or small. More important is that small letter should come first then the Capital letter). Is this possible?.
Empname
a
A
b
c
D
e
E
F
Select * from emp order by Lower(empname) Asc;
Doesn't do the job, because 'A' comes before 'a'.
Regards,
Bhaskar
select empname from emp order by upper(empname),ascii(empname) desc;
EMPNAME
a
A
b
c
D
e
E
F
Cheers,
Manik.
Similar Messages
-
Is it possible to sort items by kind but always show folders first?
Hi,
In column view, is it possible to sort items by kind but always show folders first? There's a hack explained here: http://www.bece.org/Home/tabid/36/EntryID/5/Default.aspx but by using this hack, in list view, the kind for folders is displayed as ~Folder instead of Folder.
Thanks in advance,
BehrangBehi wrote:
It's still hacky and adds a left padding to the kind name of folders...
that hack is with using space instead of ~ is the absolute best you can do. -
Sort Order: Case insensitive... move NULL to end of list
Hello All,
I am trying to sort a set a values, and NULL is a possible value. In the report I am displaying the NULL as EMPTY (I cannot leave that as NULL). I was wondering if there is a way to display this 'EMPTY' value as the last element in the list.
I tried to append various ASCII characters in front of it, but nothing seems to work. Even is if enclose it in parenthesis, is does alphabetical sort.
Is there a work around ?
Thanks for your time !Nemi, Deborah,
According to SAP Note 1200528 - Web Intelligence does not utilize special characters when sorting, this 'issue' is by design and not by design.
The following is a copy-paste from the note:
Symptom
When attempting to sort a Web Intelligence document on a particular column, special characters such as "-" or "." are not respected. For example, add the following into a database and then create a Web Intelligence report.
a-Austria
a-Austrailia
a-Belgium
a B-Argentina
a B-Brazil
a B-Egypt
When you sort this data in Web Intelligence it appears as:
a-Austria
a-Austrailia
a B-Argentina
a B-Brazil
a B-Egypt
a-Belgium
Cause
This behavior is by design. For Enterprise XI Release 2, the Lexicographical order of the International components of Unicode has been implemented. This order sorts with respect to the language set for a data source. This means that if we modify the sort order for English, other languages that we support will also have changes in their sort order. In this case we must do our best to respect all the languages that we support.
For more information please go to http://icu.sourceforge.net/
Resolution
To work around this behavior, complete one of the following:
Workaround 1:
Create a formula on the field such as
"=Replace([Col001];"-";" ")"
This will replace the - with a space although for this example the sort will be in the same "wrong" order, it will look much nicer.
- or-
Workaround 2:
Create a custom sort:
1. Select the section cell or table cells you want to sort.
2. Click the down arrow next to the Apply/Remove Sort button on the Report toolbar then select Custom... from the drop-down list.
Best,
Srinivas -
Symbol & Text Substitution Is Case Insensitive But "Forgets" Case
For example, when mistyping "The Republic" as "Teh Republic", text substitution will replace "Teh" with "the" in lower case, "forgetting" the original case. An understandable response from the software, but definitely not the best one. At very least I would have thought having it remember your case for each letter position would be optional.
Would very much like to see this fixed / added at a later update.There is no guarantee that any Apple programmers read these use-to-user forums. The only way to make sure your voice is heard is to leave feedback.
-
OK, Im using a select statement and all the works, but when i try to order by a column, it sorts it using the ascII values of the text, so "CAPS" comes before "caps" or even "apples"... is there a way to sort strings case-insensitively?
Thanks
EdI think using the "lower" function on the column in the order by clause solves the problem.
-
Case insensitive ordering in an interactive report
How would I alter the interactive report so that the inbuilt ordering will order alphabetically, regardless of case?
the default behaviour seems to be that it orders using lower a-z and then upper a-z.a long time ago (...) I created a solution where I modified the column headers. If you hover over a column header with the mouse, you see that it is a generated link. I also created a hidden column, but modified the header of the visible link so that it refers to the hidden column.
Not too sure if it's easy to als make it sort asc/desc alternating, but you should be able to do at least an asc sorting with not much trouble. -
Specifying Case-Insensitive Element Names in XML Schema
Hope someone knows this!
Is it possible to define an an XML Schema Definition so that Element names in the target XML File can be case insensitive.
At the moment my Parser throws an error if the element names in the XML file do not have the exact same case as the definition in the XML schema.
E.g
In Schema i have:
<xsd:element name="HOSTINVENTORYLINE" type="HostInventoryLineType" maxOccurs="unbounded" minOccurs="0"/>
but in xml file i have
<HostInventoryLine field=""/>
or
<hostinventoryline field=""/>
Does anyone know anyway to get around this, so that the parser accepts the HostInventoryLine element in the xml as an instance of the HOSTINVENTORYLINE element defined in the schema.
Thanks in Advance
JJ
Message was edited by:
[email protected]You could use substitution groups to handle this. You would need an entry in the schema for each valid capitalization. This won't scale well if you want to be completely case insensitive, but if you only support lower case, upper case, and camel case it should do the trick.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="HostInventoryLineType">
<xs:sequence>
<xs:element name="an-element" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="HostInventoryLine" type="HostInventoryLineType"/>
<xs:element name="HOSTINVENTORYLINE" type="HostInventoryLineType" substitutionGroup="HostInventoryLine"/>
<xs:element name="hostinventoryline" type="HostInventoryLineType" substitutionGroup="HostInventoryLine"/>
</xs:schema>-Blaise -
Case-insensitive -- what's a scriptor to do?
Here's my delima: (from a tcsh)
% ls
file1.txt file2.TXT file3.txt
% ls file{1,2,3}.TXT
file1.TXT file2.TXT file3.TXT
% ls *.TXT
file2.TXT
% rm *.txt
I've written hundreds of unix (csh,tcsh, perl) scripts since around 1988. I never considered that some day UNIX would ignore case in filenames.
As you can imagine, I'm going to have to re-write dozens of scripts, now that I have this case-insensitive "feature".
QUESTION 1: Is there some way to turn off the ignore-case in Apple unix? What are the consequences of such a bold act?
QUESTION 2: Is there a simple variable, switch, or something, that tells the shell (tcsh) that files are case-sensitive (e.g. *.TXT would match *.txt)? Same request goes for telling filec that is should ignore case.
PowerBook G4 Mac OS X (10.3.9)Hi Bill,
I see what you're saying. When the shell passes information to the filesystem, case ceases to matter. However, C Webber is talking about the reverse situation. HFS+ is case-insensitive but it is case-preserving. Whatever case is used in the naming of a file is reproduced faithfully in read operations and shells are by default case-sensitive. C Webber's example was filename globbing. The shell reads the names of the files and looks for matches in a case-sensitive fashion. In that case, case will matter.
I can see where this would cause problems. You might test for the existence of a file in a case-sensitive fashion, find out that it doesn't, write to the filesystem and blow away a file even though you were careful. You know that something like that happened with the Perl install script, causing it to blow away dozens of its own man pages.
C. Webber,
I did a search of the tcsh man page and found nothing suggesting that you can turn off case-sensitivity in globbing. You can do so in completion but it appears that rewrites will be necessary. I encourage you to view this as an opportunity and switch to a more powerful shell. I agree with you that this issue is unique to Mac OS X but every flavor of UNIX has its own issues. We've all had to make changes to migrate scripts. I've certainly had to do that to migrate some of my scripts to Linux and some won't migrate at all. (I use AppleScript in many of my scripts)
Gary
~~~~
"The glory of creation is in its infinite diversity."
"And in the way our differences combine to create meaning and beauty."
-- Dr. Miranda Jones and Spock, "Is There in Truth No Beauty?",
stardate 5630.8 -
Casi insensitive while inserting
I have seen a new feature in oracle10G where we can make oracle case insensitive but it works at select but not at insert.
For example
SQL> create table a(name varchar2(10) primary key);
Table created.
SQL> create table b(name varchar2(10) references a)
2 ;
Table created.
SQL> insert into a values('Pan');
1 row created.
SQL> insert into b values('pan');
insert into b values('pankaj')
ERROR at line 1:
ORA-02291: integrity constraint (DBO.SYS_C00673363) violated - parent key not
found
If i write p in lower case it gives me error in referential integrity.Is there any way where we can insert without checking the case.I dont want to use upper function.I wouldn't work through a reference constraint.
Maybe through a trigger "instead of" as I show here below, but you have to think about the business rule of such thing :
SQL> create table a(name varchar2(10) primary key);
Table created.
SQL>
SQL> create table b(name varchar2(10) references a);
Table created.
SQL>
SQL> insert into a values('Pan');
1 row created.
SQL>
SQL> insert into b values('pan');
insert into b values('pan')
ERROR at line 1:
ORA-02291: integrity constraint (SYSADM.SYS_C00465443) violated - parent key
not found
SQL>
SQL> drop table b;
Table dropped.
SQL> create table b_tbl(name varchar2(10));
Table created.
SQL> create or replace view b as select * from b_tbl;
View created.
SQL> create or replace trigger trg_bi_b
2 instead of insert on b
3 begin
4 insert into b_tbl
5 select :new.name
6 from a
7 where upper(name)=upper(:new.name);
8 if sql%rowcount = 0 then
9 raise_application_error(-20001,'Name doesn''t exists into a table');
10 end if;
11 end;
12 /
Trigger created.
SQL> insert into b values('pan');
1 row created.
SQL> insert into b values('Pan');
1 row created.
SQL> insert into b values('pAn');
1 row created.
SQL> insert into b values('PAN');
1 row created.
SQL> insert into b values('paN');
1 row created.
SQL> insert into b values('pankaj');
insert into b values('pankaj')
ERROR at line 1:
ORA-20001: Name doesn't exists into a table
ORA-06512: at "SYSADM.TRG_BI_B", line 7
ORA-04088: error during execution of trigger 'SYSADM.TRG_BI_B'
SQL> select * from a;
NAME
Pan
SQL> select * from b;
NAME
pan
Pan
pAn
PAN
paN
SQL> You have to create same one for update.
Nicolas. -
In my library I have keyworded many pictures with case-sensitive keywords, e.g. "david" and "David". How can I convince Aperture 1.1.2 that these should be treated as if they were identical? (without retyping them manually). If I add "David" to all photos and then try to remove "david" using the shift-return trick, it removes "David", i.e. the wrong one!
iMac G5 21" Mac OS X (10.4.7)Hi Tim,
the 0.8 stream of Xtext allows to specifiy ignoreCase="true" similar to
backtracking="true" in the workflow that generates your languages. This
should do the trick. Note that this feature is currently considered to
be experimental, but we are working on it to improve its overall usability.
Regards,
Sebastian
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Tim Geisler schrieb:
> What is the preferred way to handle case-insensitive keywords in an
> Xtext grammar?
>
> The special problem in our case is that not all parts of the language
> are case-insensitive, but just some keywords.
>
> Of course content assist is desired also for case-insensitive keywords
> (content assist should then suggest only one alternative for the
> keyword, e.g., with all letters in upper case).
>
> With some experimentation, I found out that from the approaches
> described in the ANTLR Wiki
> (http://www.antlr.org/wiki/pages/viewpage.action?pageId=1782) the first
> approach partially works:
>
> SELECT : ('S'|'s')('E'|'e')('L'|'l')('E'|'e')('C'|'c')('T'|'t') ;
>
> The Xtext-generated lexer/parser then recognizes case-insensitive
> keywords, but there is neither a completion proposal nor lexical
> highlighting of the case-insensitive keyword in the editor.
>
> This can be solved by extending DefaultAntlrTokenToAttributeIdMapper for
> lexical highlighting and extending
> AbstractContentProposalProvider.completeRuleCall().
>
> The not-so-nice issue with this approach are that the lexical structure
> of the case-insensitive tokens is distributed over several classes and
> that enums cannot be used anymore.
>
> Best regards,
>
> Tim -
Case insensitive NSS volume on cluster
We are trying to migrate from Apache2 running on a Netware server to a OES2 Linux server running on a two node cluster. The Cluster Volume is NSS and when Apache runs we appear to have a case sensitivity issue. I have read on the Forums that NSS can be configured to be case insensitive but I am unsure how I change the cluster to mount NSS case insensitive.
Can anyone assist? (It would sure help because trying to change all of the folders and files to lowercase and change all of the .php scripts to load the lowercase folders has been a nightmare!)
Thanks for any information that you can provide!
Charlie
~~~Originally Posted by utman
I found an OES 1 doc that says if you add the long namespace it will make it case insensitive.
Novell Documentation
Any idea if I LOSE anything by mounting it with Long Namespace? I have never been quite sure WHY you would want it to be Case Sensitive in Linux. It just seems to make for a lot of confusion. (HOME vs. home) -
How to make a sortable column in a table to do a case insensitive sort ?
Hi :
I am using Jdeveloper Studio Edition Version 11.1.1.1.0 and my table columns are sortable but i want to make sure that it case insensitive sort ,for example if i have following column values :
abc,def,ABC,ghi
Sorted results should not be likes this : abc,def,ghi,ABC
instead of this it should be like this : abc,ABC,def,ghi
Please let me know more about it.
Thanks
ANDear,
I'm using the same configuration, Could u tell me how did u done the sort in a column in any case.
Regards,
RengarajR
Edited by: Rengaraj Rengasamy on Oct 19, 2009 1:34 AM -
Case INSENSITIVE Columns on Oracle
Hello Friends,
Good Monday for everyone....
I would like to ask you guys if there is a way to create a case INSENSITIVE Columns on Oracle. I used on Sqlserver before the COLLATE sintax, and I was able to make a columns (just that one) INSENSITIVE.
I'm using oracle 10gr2 on Windows plataform and herte is my nls_parameters. My ideia is to search on this column without the need of performing a function UPPER and LOWER and etc...
NLS_LANGUAGE BRAZILIAN PORTUGUESE
NLS_TERRITORY BRAZIL
NLS_CURRENCY Cr$
NLS_ISO_CURRENCY BRAZIL
NLS_NUMERIC_CHARACTERS ,.
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD/MM/RR
NLS_DATE_LANGUAGE BRAZILIAN PORTUGUESE
NLS_CHARACTERSET WE8MSWIN1252
NLS_SORT WEST_EUROPEAN
NLS_TIME_FORMAT HH24:MI:SSXFF
NLS_TIMESTAMP_FORMAT DD/MM/RR HH24:MI:SSXFF
NLS_TIME_TZ_FORMAT HH24:MI:SSXFF TZR
NLS_TIMESTAMP_TZ_FORMAT DD/MM/RR HH24:MI:SSXFF TZR
NLS_DUAL_CURRENCY Cr$
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
tks a lot
KeenAPC wrote:
No, they mean a setting which makes "APC" or "apc" match "Apc".
There is nothing to be done on 10g, other than building a function based index on the column in question, so that any UPPER() searches are optimized.
Well, as Kamran Agayev already noted CI is available in 10g too. It also worth mentioning FBI creates a hidden column. Also, your statement
In 11g we have the option to set the NLS_SORT parameter so that any searches are case-insensitive (or indeed accent insensitive). Find out more.
is incomplete. NLS_SORT affects nothing but sort:
SQL> connect scott
Enter password: *****
Connected.
SQL> select * from v$version
2 /
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 order by name
12 /
NAM
Joe
Max
Sam
joe
max
sam
6 rows selected.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name = 'max'
12 /
NAM
max
SQL> alter session set nls_sort = binary_ci
2 /
Session altered.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 order by name
12 /
NAM
Joe
joe
max
Max
Sam
sam
6 rows selected.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name = 'max'
12 /
NAM
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name like 'm%'
12 /
NAM
max
SQL> select 'Max' name from dual union
2 select 'max' name from dual
3 /
NAM
Max
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select distinct name
10 from t
11 /
NAM
sam
Joe
joe
max
Sam
Max
6 rows selected.
SQL> As you can see, NLS_SORT alone works on sort but not on "searches". We also need to set NLS_COMP, which by default is BINARY. Prior to 10g R2 (I am not 100% sure, it could be prior 10g), the only NLS_COMP choice, besides BINARY, was ANSI. However, ANSI does not work with all comparison operators (e.g. does not work for LIKE, UNION, DISTINCT):
SQL> alter session set nls_sort = binary_ci
2 /
Session altered.
SQL> alter session set nls_comp=ansi
2 /
Session altered.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 order by name
12 /
NAM
Joe
joe
max
Max
Sam
sam
6 rows selected.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name = 'max'
12 /
NAM
Max
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name like 'm%'
12 /
NAM
max
SQL> select 'Max' name from dual union
2 select 'max' name from dual
3 /
NAM
Max
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select distinct name
10 from t
11 /
NAM
sam
Joe
joe
max
Sam
Max
6 rows selected.
SQL> Starting 10g R2 NLS_COMP can be set to LINGUISTIC, which will also work for LIKE and UNION but not for DISTINCT:
SQL> alter session set nls_sort = binary_ci
2 /
Session altered.
SQL> alter session set nls_comp=linguistic
2 /
Session altered.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 order by name
12 /
NAM
Joe
joe
max
Max
Sam
sam
6 rows selected.
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name = 'max'
12 /
NAM
Max
max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select name
10 from t
11 where name like 'm%'
12 /
NAM
Max
max
SQL> select 'Max' name from dual union
2 select 'max' name from dual
3 /
NAM
Max
SQL> with t as (
2 select 'Max' name from dual union all
3 select 'sam' name from dual union all
4 select 'Joe' name from dual union all
5 select 'max' name from dual union all
6 select 'joe' name from dual union all
7 select 'Sam' name from dual
8 )
9 select distinct name
10 from t
11 /
NAM
sam
Joe
joe
max
Sam
Max
6 rows selected.
SQL> However even LINGUISTIC does not work with:
• CLOB or NCLOB data types
• Object data types
• Table partitions
• Index-organized tables
SY. -
LC_COLLATE with dotfiles at top, then case-insensitive sorting
Hello,
I would like to have the following sort order in file managers or when using the "ls" command:
1. dotfiles should be on top
2. other files should follow but case-insensitive
For (1) LC_COLLATE=C works, but it then sorts the remaining file case-sensitive
For (2) e.g. LC_COLLATE="en_US.UTF-8" or de_DE.UTF-8 works.
Is there a locale that fits to my needs? If not, is it possible to edit a locale or create custom rules?
Thank you!Y = Opportunity Revenue
X = Month
The report is a 4-month forecast, but not using built-in Forecasting that CRMOD uses; this report uses the Forecast checkbox in an opportunity to determine if the oppty should be on the forecast report, then grabs the overall Oppty Revenue from that same region of the Oppty (not using line/Product level revenue field).
The report uses a table and above that a chart with 3D cylindrical output where each press model (derived from a field in the Oppty header) is a different color (I'm letting Analysis defaults set the colors for each product).
My boss wants to sort the colors from smallest model size to largest model size for consistency sake and to make the chart easier to comprehend with a glance.
Is this even possible? I could see sorting by revenue size, but that's not always the best indicator (as some used larger presses may sell for less than new smaller ones).
Any ideas?
Thanks,
Andy -
ADF table: case-insensitive sorting
I have an <af:table> that uses a SortableModel as it's data source. I have sorting enabled on the table, but it's sorted according to case sensitivity.
My data source has mixed case, and I'd like to be able to sort regardless of case. Is there anyway to change the behavior so it does a case-insensitive sort instead?
ThanksIn case anyone else is looking for this, I went ahead and wrote an extension of CollectionModel that performs a case insensitive sort on String objects. I'm posting it here in the hopes it will help others in the same jam I was. It would really have been helpful if Oracle had made the source code to SortableModel available. I hope I did things properly with the rowKey stuff since there are no examples to work from.
Anyway, here it is:
package com.fhm.mwb.ui.model;
import oracle.adf.view.faces.model.CollectionModel;
import oracle.adf.view.faces.model.SortCriterion;
import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.collections.comparators.ComparableComparator;
import org.apache.commons.collections.comparators.ComparatorChain;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.faces.FacesException;
import javax.faces.model.DataModelEvent;
import javax.faces.model.DataModelListener;
* This class provides a sortable data model that uses case insensitive sort order when processing
* String objects. All other objects in the data must implement Comparable and are sorted using
* Comparable.compare().
public class CaseInsensitiveSortableModel extends CollectionModel {
private static BasicComparator _comparator = new BasicComparator();
* Default constructor.
public CaseInsensitiveSortableModel() {
* Construct on top of a list of data.
* @param list List of data to wrap in the model
public CaseInsensitiveSortableModel(List list) {
setWrappedData(list);
* Set the sort criteria for this model
* @param criteria List of SortCriterion objects
public void setSortCriteria(List criteria) {
_sortCriteria = criteria;
if((criteria != null) && (criteria.size() > 0)) {
// Sort our model data using this new criteria
ComparatorChain chain = new ComparatorChain();
for(int i = 0; i < criteria.size(); i++) {
SortCriterion crit = (SortCriterion) criteria.get(i);
chain.addComparator(new BeanComparator(crit.getProperty(), _comparator),
!crit.isAscending());
List list = (List) getWrappedData();
Collections.sort(list, chain);
setWrappedData(list);
} else {
// Clear out our sort order
_sortCriteria = new ArrayList();
* Get the current sort criteria.
* @return List of sort criteria
public List getSortCriteria() {
return _sortCriteria;
* Determine if a given column is sortable.
* @param column Name of the column to test
* @return boolean true if the column is sortable
public boolean isSortable(String column) {
return true; // Everything is sortable for now
* Sets up a value at a particular rowKey to be the current value. The current value
* is returned by calling {@link #getRowData}.
* @param rowKey the rowKey of the value to make current. Use null to clear the current value.
public void setRowKey(String rowKey) {
if(rowKey == null) {
setRowIndex(-1);
} else {
setRowIndex(Integer.valueOf(rowKey).intValue());
* Gets the rowKey of the current value. The current value is returned by
* calling {@link #getRowData}.
* @return the rowKey of the current value, or null if there is no current value
public String getRowKey() {
return isRowAvailable() ? String.valueOf(_rowIndex) : null;
* Set the list data we are wrapping
* @throws ClassCastException if data is
* non-null and is not a List
public void setWrappedData(Object data) {
_wrappedList = (List) data;
if(_wrappedList == null) {
setRowIndex(-1);
* Return the object representing the data wrapped by this model, if any.
public Object getWrappedData() {
return _wrappedList;
* Return true if there is wrappedData
* available, and the current value of rowIndex is greater
* than or equal to zero, and less than the size of the list. Otherwise,
* return false.
* @exception FacesException if an error occurs getting the row availability
public boolean isRowAvailable() {
return ((_rowIndex < 0) || (_rowIndex > getRowCount())) ? false : true;
* If there is wrappedData available, return the
* length of the list. If no wrappedData is available,
* return -1.
* @exception FacesException if an error occurs getting the row count
public int getRowCount() {
return (_wrappedList == null) ? (-1) : _wrappedList.size();
* If row data is available, return the list element at the index
* specified by rowIndex. If no wrapped data is available,
* return null.
* @exception IllegalArgumentException if now row data is available
* at the currently specified row index
public Object getRowData() {
if(_wrappedList == null) {
return null;
} else if(!isRowAvailable()) {
throw new IllegalArgumentException("No row data available");
} else {
return wrappedList.get(rowIndex);
* Return the zero-relative index of the currently selected row. If
* we are not currently positioned on a row, or no wrappedData
* is available, return -1.
* @exception FacesException if an error occurs getting the row index
public int getRowIndex() {
return _rowIndex;
* Set the zero-relative index of the currently selected row, or -1
* to indicate that we are not positioned on a row. It is
* possible to set the row index at a value for which the underlying data
* collection does not contain any row data. Therefore, callers may
* use the isRowAvailable() method to detect whether row data
* will be available for use by the getRowData() method.
* If there is no wrappedData available when this method
* is called, the specified rowIndex is stored (and may be
* retrieved by a subsequent call to getRowData()), but no
* event is sent. Otherwise, if the currently selected row index is
* changed by this call, a {@link DataModelEvent} will be sent to the
* rowSelected() method of all registered
* {@link DataModelListener}s.
* @param rowIndex The new zero-relative index (must be non-negative)
* @exception FacesException if an error occurs setting the row index
* @exception IllegalArgumentException if rowIndex
* is less than -1
public void setRowIndex(int rowIndex) {
if(rowIndex < -1) {
throw new IllegalArgumentException("Row index must be >= 0");
int old = _rowIndex;
_rowIndex = rowIndex;
if(_wrappedList == null) {
return;
DataModelListener[] listeners = getDataModelListeners();
if((old != _rowIndex) && (listeners != null)) {
Object rowData = null;
if(isRowAvailable()) {
rowData = getRowData();
DataModelEvent event = new DataModelEvent(this, _rowIndex, rowData);
int n = listeners.length;
for(int j = 0; j < n; j++) {
if(null != listeners[j]) {
listeners[j].rowSelected(event);
private List _wrappedList = new ArrayList();
private List _sortCriteria = new ArrayList();
private int _rowIndex = -1;
* Internal class to provide a general Comparator that treats Strings in a case
* insensitive manner. All other types are assumed to be instances of Comparable
* and handled as such.
private static class BasicComparator implements Comparator, Serializable {
private static final Comparator INSENSITIVE_COMPARATOR = String.CASE_INSENSITIVE_ORDER;
private static final Comparator NORMAL_COMPARATOR = ComparableComparator.getInstance();
public BasicComparator() {
public int compare(Object o1, Object o2) {
if(o1 instanceof String && o2 instanceof String) {
return INSENSITIVE_COMPARATOR.compare(o1, o2);
} else {
return NORMAL_COMPARATOR.compare(o1, o2);
}
Maybe you are looking for
-
How do you correct the installation problems?
-
Hi Friends, The users want to generate the Vendor's Aging Analysis that would give the summarized position of the Overdues as per the interval days specified, for each of the vendor codes that are selected and for which the summarized position is req
-
Off-Topic: Open Source Wiki/Forum/Knowledge Sharing?
Did not really have another forum to post this to, so I thought I would so here. We are looking to set up a mini-portal accessible on our intranet. The idea would be to share best practices, standards, designs, results of continuous integration (test
-
Hi , How to find the number of times the particular t-code has been accessed over a user defined period? If the user didn't access the T.code, the report would show a 0 or a 2 if the user had accessed the report twice. Do we have any standard table o
-
GRC 10 Not able to search roles in Access Request Creation
Hello Experts, I am unable to search for roles while creating access request by giving system name. I am able to search with any other search criteria except system. When I look for valid entries for System I get the following connector group values: