Sunday, 11 June 2017

THE SORRY STATE OF HINDUSTAN PAPER CORPORATION LIMITED (HPCL)

HINDUSTAN PAPER CORPORATION LIMITED

The current and ex-employees of this organization take pride in the fact that it is one of the "Miniratna Category-I" public sector undertaking (PSU) in India. By definition, it means a firm that "has made profits continuously for the last three years or earned a net profit of Rs. 30 crore or more in one of the three years". 

The reason for blogging about this is because my father has been an employee of this organization for more than 30 years now and he along with almost 2000 current employees are in deep-deep trouble. So, the reason which got me to get back to this blog and post something here after almost a year, is that Hindustan Paper Corporation (HPCL) is in the middle of a serious crisis where a lot of lives are at stake. The two paper mills - Nagaon Paper Mill and Cachar Paper Mill are not operational and employees are not getting their salaries. Cachar Paper Mill was last operational in October whilst Nagaon Paper Mill is shutdown since February. All employees have been crying for their salaries for months as they struggle to run their households, pay their EMIs, pay their children's education fees, get medical assistance and thousands of other basic tasks. Money drives every basic thing in the world that we currently live in. So now that we have established the fact, that not getting salary regularly is a huge problem for every middle-class man, we can talk about the plight of the industry.

1.     The mills are not operational. The reason being, there is no money to pay the vendors and bring in the raw-material. The situation arose because of mismanagement/corruption at top and mid-level and CBI investigations are on. This in turn led to losses and drying up of the reserve funds and eventually the mill did not have any money to pay the dues of the vendors and hence they stopped supplying the raw-materials, which ultimately meant ZERO production.
2.     When the downfall started, and company started incurring intermittent losses, employees stopped getting the extra-benefits of a typical PSU and everybody thought it’s just normal cost-cutting that happens everywhere. The maintenance activities started happening less regularly, occasional late salary disbursements, renovations stopped and many similar things followed.
3.     Then slowly there came a time, when the mills had to wait for the raw-materials to arrive, run for a month or two, produce the paper and then wait for it to get sold off in the market and use that money for further purchase of raw-materials. Ultimately, when the mills could no longer sustain and couldn't bear its own cost of running with the sales it was making, the mills stopped and couldn't pay the salary dues of its employees.
4.     Currently, around 2000 employees have not received their salaries for the past 7 months and the employees are asking for a revival package from the Government to make the mills operational and bring it to a profitable position.
5.     The families of these employees are facing a serious crisis as they are struggling to run their households without any salary. Children of most of the employees are studying, somebody has a house loan on his/her name, somebody bought a car on loan, and somebody has dependent parents.
6.     Then the location of these mills, Panchgram and Jagiroad are still very remote and the livelihood of the people living here is through these paper mills. Some work as contractors, some as temporary labour, some are shopkeepers, fruit & vegetable vendors, milkmen, gardeners, servants are also struggling. The whole economy of these two areas is still dependent in a huge way on these two mills and its employees.

There have been protests going on, by the labour-union, by the employees, by the "children of HPC" but I feel these protests will die out over time as till now their voices have not fallen into the ears of neither the "Heavy Industry Ministry", not the central government. All we have received till now is an occasional nod by the Ministers saying that we will definitely revive the two mills. As I went through the news related to this issue over the past one year, I came to know that a revival strategy is being prepared to not just make the mills operational but profitable in a short-period of time, the revival package is under a vetting process, Assam state government is talking with the Center. The way things are moving, it could take another 6-7 months before anything substantial happens. This could completely break-down a lot of employees and their families. We need to act now and hence I thought of listing down a few reasons as to what may have gone wrong:
1.     There are multiple agendas. A section of the organization (management) is asking for a revival package from the government (1350 crores to be somewhere near precise, although last year September the state government issued a statement with a figure of 800 crores). Then there is a section who is protesting for the employee salaries to be disbursed immediately which has been due for months now. Then, there are people who are local residents of Jagiroad and Panchgram area who have been affected indirectly as their source of income is through the living expenditures of the employees of HPCL. So, all in all the raised voices of these separate sections are to some extent cancelling out echoes of each other thus reducing the overall impact of the protests.
2.     There is weak/less significant leadership in terms of bringing this protest in the eye of the public. For any protest to be successful, it has to come into the eyes of the public. With, coverage only on the local newspapers and news channels, hardly anybody has noticed the current fate of the HPCL. This has been the story of North-East India for the past 70 years, never really getting the attention of Mainland India or so to say, the Parliament located at heart of our nation's capital. There is a need to make this issue a national one, to get every concerned minister's undivided attention. Let us get Arnab Goswami to conduct a debate on his channel Republic TV, at least let us try to get this issue on one of the National level TV Channels.
3.     God helps only those who help themselves- Let us stage a demonstration where we do not just sit on a strike and do nothing, but actually do something about our own situation. Let us unite every one, bring in as much bamboo as we can and start the production even if it is on a very minute scale. I don't even know if it is possible or not, only my dad and his colleagues know whether it is feasible or not. Let us put in the hard-work, demonstrate the strength of the HPCL family to everyone, may be it will grab the attention of the nation that could give a strong push to our agenda. While people try to run the mill, others can contribute by cleaning the residential colonies which have undergone tremendous damage due to lack of funds.
4.     Somebody needs to find a source directly to either Our Chief Minister, respected Sri Sarbananda Sonowal, or our Heavy Industry Ministers Sri Anant G Geete & Sri Babul Supriyo (who might be a good friend of Abhijeet Bhattacharya, Zubin Garg or may be Shaan). We need people who can skip the regular process and get in touch directly with these people of influence.
5.     Let’s resolve internal conflicts and internal politics. As long as we are wasting our energy in internal politics or looking for personal gains, nobody is going to benefit out of it. A united front, a united voice, a united display of anger and disappointment is the need of the hour.
I want to use this platform to reach out to everybody and tell them the struggle that these 2000 individuals and their families are currently undergoing and my parents are one of them. I take great pride in being part of the HPCL family, which took care of my childhood, enabled my father to take care of my college education and played a huge part in making me the man I am today and I know a lot of my school-mates share the same feeling. I cannot and will not just sit back and watch it die. I want to reach out to my fellow school-mates to join in, every present and past member of the HPCL family (may not even be impacted at all by this), every single person who thinks that everybody should get what’s rightfully theirs. Let us join hands, move the Government to get their undivided attention, and help out these 2000 odd families along with preserving our glorious past.

Tuesday, 3 May 2016

Programmatic InputComboboxListOfValues - Stuff of Legends!!!

Lolz !!! Apologies for the over-exaggerated title of the post. But, I was so happy to get it working :P

Recently, I had this requirement where I had to create inputComboboxListOfValues on the JSFF, but its values were dependent on certain fields already entered by the user on the form. And the lookup values were present in one single lookup table. If I had just 1 or 2 such use-cases, I would have created separate view objects for them and dragged and dropped them on the form in a declarative fashion. But I had almost 10 such LOVs that needed to be implemented in the similar fashion. So, I ran around searching for a way to bind the inputComboboxListOfValues component with a Java List or a Java array. There is documentation available for it online and I was able to make it work successfully. So here's how I did it:
As per the documentation, you need to extend the following classes and you are free to tweak with it as per your requirement:
  1. AttributeCriterion
  2. AttributeDescriptor
  3. ConjunctionCriterion
  4. CollectionModel
  5. ListOfValuesModel
  6. QueryDescriptor
  7. QueryModel
  8. TableModel
As per the design I followed, you would need to create two more Java Classes, preferably inside the same package:
  1. FileData
  2. LOVUtil
We would be creating an object of the LOVUtil class and calling the constructor, passing the java list to populate the ListOfValuesModel and the collection model. The source code for the constructor looks like this:

    public LOVUtil(List _DIR_DATA) {
        for (int i = 0; i < _DIR_DATA.size(); i++) {
            String item1 = _DIR_DATA.get(i).toString();
            String item7 = new Integer(i).toString();
            FileData _curRow = new FileData(item1, item7);
            _values.add(_curRow);
        }
        _filteredList.addAll(_values);
    }

The way, I have been calling it in my managed bean inside a valueChangeListener is shown below:

LOVUtil creditRatingUtil=new LOVUtil(creditRatingInputList);

In this case creditRatingInputList is a java array list which has been populated by iterating the lookup view object (obviously after executing the view criteria based on the "changed value").

That's it, worked like a charm for me!!!

P.S - I am unable to attach the java files here. So, I would request you guys to post your email ids in the comments section and I would be more than happy to send across the java files to you all :) :)
Link to the files

Sunday, 24 April 2016

10 common myths about North East India

I hail from the beautiful north-eastern part of our nation and feel really offended when people have so many misconceptions about the land, believe in so many myths and are so ignorant about certain text-book facts. I believe it has a lot to do because of the isolated geography of the location as well as the education curriculum of our country. All my friends would laugh at most of them, as I have already busted most of them already for them. But I thought I would take this opportunity to bust some very common myths about the north-east India for people in general. Here are so facts which are exactly opposite of all the myths about the great North-East India


  1.  There is a reason it is called North-East India: Many people don't know that "North-East" is a part of India. Yes, its a fact. It happened with one of my friends who hails from the state of Tripura, he was asked by a Delhite if he requires a VISA to come to Delhi and which country does it belong to and how does he know Hindi. Just because we have Mongoloid features, doesn't mean that we do not belong to the dominion of India. Guys, it is not a part of Nepal or China which is a common notion. We have been a part of India since our independence and are very proud of it.
  2. We all are not Tribal: The north-east is a diverse land with thousands of different races, dialects and cultures. North-East is a land where people from different cultures and backgrounds live in harmony. Almost each state has a sustainable Marwari population as well as there are "Brahmans" everywhere (we obviously know that they are not SC/STs). The reservation model is followed in the North-East like any other part of the country. The castes and tribes which were left behind due to certain historical and cultural events are given reservations just like the rest of the India.
  3. We are neither Cannibals nor Savages: We don't eat anything and everything. Every region has its own traditional cuisine. Although some might include dogs and snakes, but it is their culture and has been followed for centuries now. The North-Eastern cuisines are one of the most nutritionally balanced and healthy food in the country. Each state has their own specialization in terms of meat and vegetable preparation. In fact, Bengali cusisine has borrowed heavily from Assamese cooking and most tribal delicacies are closer to the Southeast Asian cuisines. And FYI, we don't eat every moving thing!!!
  4. "Chinki" women are NOT loose and NOT easy to get: Sorry guys, I had to break it for you, but it is true. Just because some cultures adopted a more westernized dressing sense, doesn't make them sluts or loose character. It is a shame that the north-eastern women are thought to be vulnerable. I sometimes feel that it comes as shock to the so-called "Mainland India" when they see people of North-East dressed better than them because they think that we are backward as compared to the rest of the country. And thus their conclusion, that these are women are sluts. Instead, the North-Eastern societies have been more liberal towards Sorry, but you are so wrong.
  5. The region is safer than most parts of the country: Most people think that it would be unsafe to travel to the North-East and the people over there would be hostile to them. I don't blame their thinking, I blame their ignorance about the people of North-East. We are fun-loving people and like having guests just like everybody else. It is a shame, that despite being one of the most beautiful places in the country, it still doesn't attract as much tourists as the other popular destinations. There are so many Marwaris, Punjabis, Gujaratis and Bengalis to put you at ease here. So just chill here when you visit.
  6. It doesn't SNOW everywhere in the North-East and its not COLD: Most people think that the climate over here is cold and it snows everywhere in the winters. I wish it did (snows only in Tawang and certain other parts of Arunachal Pradesh), but a major portion enjoys humid tropical climate. Yes, you can say that it rains heavily and the temperatures are moderate throughout the year. We have cold winters but not chilling winters like "Delhi".
  7. We are neither illiterate nor poor: Tripura(shares borders with eastern Bangladesh) and Mizoram(adjoining state of Tripura, borders with Myanmar as well) are among the most literate states in the country. And we are not poor either, 5 out of 8 North-Easter states(Yes, there are 8 states- google it, if u don't believe) have lower poverty percentage than the national average.
  8. Aha!! We do speak Hindi: Surprised? Yes most of us can communicate effectively in Hindi. Yes, we have our own dialects and accents in Hindi which is a common thing across India. People are stunned when they see a North-Eastern speak Hindi. But my dear fellow countrymen, our schools like any other school in India has Hindi as a subject in their curriculum plus a major chunk of the population have their roots in "Mainland India".
  9. North-East "≠" ASSAM: Many people feel that there is only one state in the North-East and that is Assam. They don't even know the name of the states - Assam,Arunachal Pradesh, Manipur, Meghalaya, Mizoram, NagaLand, Tripura and Sikkim. It has a lot to do with the educational curriculum we have, not much is written about the Seven Sisters and Sikkim in the text-books. If we study about these states in detail, that would probably help in creating a permanent memory inside your brain.
  10. We all are not Christians: No, we all are not Christians. Out of 8 states, only 3 states have Christian "Majority" - Meghalaya, Mizorma and Nagaland. Assam and Tripura consists mostly of Hindus and Muslims, Arunachal Pradesh has Hindus, Buddhists and others follow their own native animist faiths. Manipur has a very rich Vaishanvite (Vaishnava Dharma) tradition dating back centuries.
I hope most of you know these already, but the point was to stop stereotyping and generalizing the North-East people because we are not all alike. I think stereotyping as a concept fails terribly when you apply it on the North-East as the culture is so diverse.
I know many of you do want to visit North-East as the only conception that is not a myth about it is its natural beauty. From the snowy himalayas of the Tawang Valley, to the dense forest of the Brahmaputra plains, to the green hills of Mizoram are a treat to watch, a God created spectacle for the human race to adore. Do visit, it is a heavenly abode!

Saturday, 23 April 2016

The Joy Of Sledging in Cricket :)

Most of us would be aware of the meaning of this word which according to some people has plagued the cricketing world for a long time, and according to some has added spice to an on-field rivalry and provided entertainment to everyone and according to some doesn't affect the gentlemen's game at all. I belong to the second category and though the general Indian consensus is that its mean, breaks concentration of the players and is against the spirit of the game, I prefer to view it as something which adds to the entertainment the game of cricket is providing. So, here I am trying to make you laugh with some of the most hilarious, witty, jocular and amusing on-field sledges as well as amazing display of wit and humor in response to the former.
Indian fans have come to terms with this concept of sledging very recently after the advent of television and live coverage but the historic Ashes series has been an eye-witness to this word play on the cricketing pitch for a very long time now. Here are some of the selected ones:

1.     Aussie fast bowler Merv Hughes beat outside edge of the England star batsman Graham Gooch a lot of times, after which he joked "I’ll get you a piano instead — see if you can play that.”
2.     Aussie wicket-keeper Rod Marsh asked Ian Botham as he was coming in to bat ‘So, how’s your wife and my kids?’, to which Botham replied “The wife’s fine but the kids are retarded.".
3.     Eccentric England batsman Derek Randall after being hit on the head by a Dennis Lillee bouncer :“It’s no good hitting me there, mate, there’s nothing to damage.”
4.     Steven Waugh asks Ricky Ponting to field at silly point 'Right under Nasser Hussain's nose', to which Ian Healey responded by saying “That’s anywhere inside a three-mile radius.”
5.     Shane Warne bowled Mike Gatting with the ball of the century on which Graham Gooch punned "If it had been a cheese roll, it wouldn’t have got past him.”
6.     England captain Douglas Jardine came up to the Aussie skipper Bill Woodfull and complained that he is being sworn at by the Aussie slip fielders. He walks up to them and asks “Which one of you bastards called this bastard a bastard?”
7.     Remember the charming twin brother of Steve Waugh, yeah Mark Waugh tells England bowler Jimmy Ormond that he is not good enough to play for England to which he replied “But at least I’m the best player in my family.”
8.     Justin Langer was playing as the 12th man and got real excited when the whole team was sledging Nasser Hussain and joined in. Hussain quicky reacted “Look, I don’t mind the others chirping at me but you’re just the bus driver of this team.”

Now some of the best Non-Ashes sledging moments:

1.     Malcom Marshall was giving a hard time to David Boon with the ball and asked: "Now David, are you going to get out or am I going to have to come round the wicket and kill you?"
2.     Another one of Merv Hughes moment, the guy was an entertainer. Javed Miandad wanted to get under his skin and called him a fat, fat bus conductor. After a few deliveries, Merv dismissed Miandad and ran past him and shouted "Tickets, please!"
3.     An Australian batsman was walking onto the field, opened the gate and before he could shut it, Fred Trueman remarked "Don't bother shutting it son, you won't be there long enough".
4.     Mike Whitney was on the field as a sub fielder while Shastri was batting. Shastri hits the ball to Whitney and contemplates a single. Whitney throws the ball in and says: "Stay in your crease or I'll break your fucken head". Shastri replies: "If you could bowl as well as you talk you wouldn't be the fucken 12th man!"
5.     Shane Warne was bowling when South African Daryl Cullinan came on to bat. Warne couldn't resist heckling him: "I've been waiting two years for another chance at you". Cullinan got him back with a ripper: "Looks like you spent it eating...". It even left the Aussie fielders ROFL.
6.     Sunil Gavaksar dropped himself to no. 4 for one test against the West Indies. Malcom Marshall dismissed Gaekwad and Vengsarkar for a score of 0, and when Gavaskar came on to bat, Marshall said  "Man it don't matter where you come in, the score is still zero!"
7.     In a county match in England, Thomas was bowling to Richards and getting a few to whizz past the bat. After Richards played and missed another one, Thomas said: "It's red, it's round. Now fucken hit it!". This obviously angered Richards who proceeded to hit the next ball out of the ground. Richards: "You know what it looks like now go and get it."
8.     A frustrated Glen McGrath asked Zimbabwean Eddo Brandes why he is so fat to which he replied “Because every time I make love to your wife, she gives me a biscuit .” Even the Aussie slip fielders were in hysterics.
9.     Once during a tour game in South Africa Hughes was bowling to Hansie Cronje . It was an especially flat wicket and Cronje was hitting Hughes for fours and sixes all over the place.After the umpteenth boundary, Hughes headed down the pitch, stood near Cronje, let out a fart and said: “Try hitting that for six .”
10. A 19-year old Parthiv Patel was bantering the 38-year old Steve Waugh during his last match trying to unsettle him " Come on, just one more of the famous slog-sweeps before you finish". Steve Waugh replied ‘Look, show a bit of respect. You were in nappies when I debuted 18 years ago’. Even the Indian fielders burst into laughter.
11. A young West Indian bowler was trying to sledge experienced Sunil Gavaskar, Gavaskar retorted, “Son, don’t waste time sledging at me. I have been sledged at more often than you have taken a piss”.
12. Trueman bowls. Batsman is trapped plumb LBW. Trueman appeals. Not out. Next ball. Trueman ever-so-slightly irritated.  Trueman bowls.  Audible snick, ball deflects and sails upward, caught behind.  Trueman appeals.  Not out.Third ball. Trueman a little more irritated now. Trueman bowls. Through the gate, stumps spread-eagled, middle stump uprooted and cartwheeling. Trueman turns to the umpire and says with a wry smile, ‘We nearly had him that time, didn’t we?’

Even the great great WG Garce never shied away from having a fun chatter with the players and umpires:

Once in an exhitbition match given out leg-before, he refused to walk and told the umpire: “They came to watch me bat, not you bowl “. And the innings continued.

Once, when the ball knocked off a bail, he replaced it and told the umpire: ”Twas the wind which took thy bail off, good sir.” (It was the wind which took the bail off)
The umpire replied: “Indeed, doctor, and let us hope thy wind helps the good doctor on thy journey back to the pavilion .”

Charles Kortright had dismissed him four or five times in a county game – only for the umpires to keep turning down his appeals. Finally, he uprooted two of Grace’s three stumps. Grace stalled, as though waiting for a no-ball call or something, before reluctantly walking off with Kortright’s words in his ears: ” Surely you’re not going, doctor? There’s still one stump standing.”

I hope you had fun reading this one. There is nothing better to watch than a fierce competition with funny sledges and funnier comebacks. I feel it adds a little something special to the gracious game!!!


Saturday, 16 April 2016

Cleanliness fundas for all bachelors (I mean the ones who don't live with their parents)

With all the "Swacch Bharat" buzz gripping the country, you can observe a gradual change in the masses' attitude. Still a lot has to be done. What has changed over the last year or two is that people have stopped littering in public, they have started thinking before they spit and this hesitation is so evident on the face of an individual doing such a petty thing in public.
So, earlier it used to be just houses from the inside that were clean, now the people and government are trying to keep the outside of the houses clean as well.
In between, there is an intersection - flats/apartments/row houses/PGs/hostels filled with bachelors. The problem is that the general awareness that is spreading is about keeping the outside clean. And our bachelor community is not used to cleaning the inside because they have been living with their parents up till then, so obviously they don't have the etiquette or mannerisms to keep their habitat (Yes habitat, since it cannot be called home/house because of the rowdy life style that is led there) neat, tidy and clean. So, I thought I would come up with these 8 simple rules (they might be made up, but they work) to achieve the same. Don't worry its not very difficult to follow these rules and also it will not work from day 1 as is the case with our Swacch Bharat Abhiyaan. People especially "bachelors" need time to change habits and their innate nature (which is throwing a wrapper anywhere they want to inside their "Habitat").

So, here are my cleanliness fundas for bachelors broken down into 8 simple rules:

  1. Zero Displacement Law: For me its the mother of all cleanliness laws. If you are picking up a thing or an object from somewhere, place it back to its original position when you are done using it. This way, the things will be always arranged in your "Habitat". The only exception to this law is when the thing you picked no more exists (like something edible) or when the thing is no more useful  (in which case you need to throw it down the trash).
  2. Clean up after yourself: If you spilled something, or littered in the process of doing something productive (which is a rare scenario in this case), clean/wipe/mop/broom whatever you need to do to make the surface clean.
  3. Do not use the Refrigerator for Storage: Use it to keep your meal/snack/leftovers cold for that day only or max till the next morning until you eat it. No one likes to see a rotting fruit/yogurt/decaying food in there.
  4. Keep your shoes/sandals/stilettos/chappals outside: The house is as clean as the floors of the house. You bring in a lot of dust and pebbles along with you when you are coming from somewhere outside. Yeah, the maids/bais will do it but they don't come everyday and even if they do they are not 100 percent efficient implying that ultimately you will be piling up dust in your house incrementally.
  5. Keep all your stuff above sea-level: The surroundings look cleaner when there is less/no stuff placed on the floor and everything is placed either in some shelf or on top of a table. It makes your place looks spacious.
  6. Appliances don't clean themselves up: The usual maids/bais do not clean/wipe dust of the appliances installed in your place. So, make sure that every now and then you clean one or the other appliance (TV, Refrigerator, Washing Machine, Microwave, kitchen stove). For a bachelor, the frequency of clean each appliance could be a month.
  7. Washing Machine manual says it can wash bed-sheets and curtains as well: Bachelors tend to wash the clothes they wear regularly (at least I do) but forget to wash the curtains and bed-sheets. Washing them once in a blue-moon will bring out fascinating colors out of them, trust me on this one.
  8. Empty your trash regularly: Nobody likes to see an overflowing dustbin vomiting out splatters/crumbs/fungus. Its important that a strong waste disposal system is in place. As soon, the dustbin has reached its threshold (from my experience, don't let it reach the threshold otherwise you would get your hands really messy while clearing it out), either throw it out or wrap it up in the garbage bag and wait for the garbage guy to come pick it up in the morning.
In my opinion, these 8 rules cover every aspect of the place you live in (excluding the maid/bais territory). I feel following these rules will make your "Habitat" look cleaner and might even get the certificate of a "House/Home". Everybody loves to live in a neat, tidy and well-organized place.

P.S - Certain personal references have been used above, but no hard feelings folks!!

An interesting feature to have for your Input Text Box on the JSPX - "The Character Counter"

Yes, The Character Counter - sounded like a really cool name to me and that's why I chose it.
First let me give u a bit of a background for the need to create this component.

So, I had this weird use case where I was asked to restrict the user to 2000 characters. So, I created an ADF input text box and set the maximum length to 2000 as is obvious.
I was surprise to see a defect logged by one of the testers that it is allowing more than 2000 characters to be entered and during commit, is throwing a JBO exception saying the actual length:2048 is greater than the column length:2000.
I tested it with random strings of length more than 2000 characters and it was working fine. It used to truncate the string entered till 2000 characters and then save the rest into the database. Then, I noticed something strange with the string used by the tester. It had bullets, new lines and other special characters. I immediately checked the table structure and found out that the column was defined as VARCHAR2(2000), but it was in bytes. Yes my ADF folks, the problem was because the size was 2000 bytes and not 2000 characters. Now, I didn't have the luxury to just go and alter the table. I played the whole thing in my mind and came up with this idea that I would restrict the user to 2000 bytes and not 2000 characters. So, here is what I did.

There is no way we can make the maximumLength attribute of the af:inputText understand the string in bytes. It only understands one language, which is characters. So, I created a custom validator in my managed bean inside which I was first converting the string entered into a byte array and then checking its length and throwing the appropriate message to the user if it exceeded. Here is the code snippet:

<af:inputText label="Add Notes" autoSubmit="true" maximumLength="#{bindings.Notes.hints.precision}" rows="4" columns="100" value="#{pageFlowScope.AddNotesMB.notes}" id="it1"
            validator="#{pageFlowScope.AddNotesMB.notesValidator}">
</af:inputText>

    public void notesValidator(javax.faces.context.FacesContext facesContext,
                               UIComponent uIComponent, Object object) {
        // Add event code here...
        FacesContext fc = facesContext;
        if(object!=null){
            String notes = (String)object;
            byte[] b = notes.getBytes(Charset.forName("UTF-8"));
                if(b.length>2000){
                    FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR,null,"Entered text is greater than the allowed limit, Please enter a smaller text");
                    fc.addMessage(null, fm);
                    ((RichInputText)uIComponent).setValid(false);
                }
        }
    }

Now, this worked fine and I pushed the code into the QA environment. The tester again fails the defect fix (we all know how mean the Tester Community is!!!) saying that it is stopping the user before even he has entered 2000 characters, that's because some characters use up more than one byte. And what really messed up the situation for me was every editor was returning a different character count for the same text viz. Word and Notepad++.
So, I thought may be if I myself tell the user that how many more characters he is allowed to enter, would make things easy for the user (but not for me, the developer). So, I thought of putting up a counter over the input text which would change as the user types, or copy pastes, or right-click & copy. I surrounded the input text with a panel box and inserted an output text in the toolbar facet of the panel box. And then called a javascript using the clientListener attribute which would count the number of bytes (not characters) remaining. I had to create a separate javascript method to convert the char sequence into a byte array. Here is the snippet after implementing that:

<af:panelBox id="pgl0" clientComponent="true">
        <af:inputText label="Add Notes" autoSubmit="true" clientComponent="true" maximumLength="#{bindings.Notes.hints.precision}" rows="4" columns="100" value="#{pageFlowScope.AddNotesMB.notes}" id="it1"
            validator="#{pageFlowScope.AddNotesMB.notesValidator}">
            <af:clientListener method="charChecker" type="keyDown"/>
        </af:inputText>
    </af:panelBox>

The javascript, Your Highness, goes like this:
    <af:resource type="javascript">
        function charChecker(evt){
             textfield = evt.getCurrentTarget();
             textfield_current_content = textfield.getSubmittedValue();
             textfield_current_content_length =getByteLen(textfield_current_content);
             vGREEN = textfield.getMaximumLength();
             vORANGE = vGREEN/2;
             vRED = vORANGE/4;
             vBACKGROUND_COLOR ='white';
             vCOLOR ='black';
             counter = AdfPage.PAGE.findComponentByAbsoluteId("pt1:r1:0:r2:0:out1");  
             counter_value = counter.getValue();
             if (vGREEN - textfield_current_content_length &lt;= vGREEN &amp;&amp; vGREEN - textfield_current_content_length &gt;= 0){
                 if(vGREEN - textfield_current_content_length &lt;= vRED){
                    vBACKGROUND_COLOR ='red';
                    vCOLOR='white';
                 } else{
                    if(vGREEN - textfield_current_content_length &lt;= vORANGE){
                        vBACKGROUND_COLOR ='orange';
                        vCOLOR='black';
                    }else{
                        vBACKGROUND_COLOR ='green';
                        vCOLOR='white';
                    }
                 }
             }
             counter.setInlineStyleProperty("background-color",vBACKGROUND_COLOR);counter.setInlineStyleProperty("color",vCOLOR);
             counter_value = vGREEN - textfield_current_content_length;
             counter.setValue(counter_value);
        }
        function getByteLen(str) {
            var utf8 = [];
            for (var i=0; i &lt; str.length; i++) {
                var charcode = str.charCodeAt(i);
                if (charcode &lt; 0x80) utf8.push(charcode);
                else if (charcode &lt; 0x800) {
                    utf8.push(0xc0 | (charcode >> 6), 
                              0x80 | (charcode &amp; 0x3f));
                }
                else if (charcode &lt; 0xd800 || charcode &gt;= 0xe000) {
                    utf8.push(0xe0 | (charcode >> 12), 
                              0x80 | ((charcode>>6) &amp; 0x3f), 
                              0x80 | (charcode &amp; 0x3f));
                }
                else {
                    // let's keep things simple and only handle chars up to U+FFFF...
                    utf8.push(0xef, 0xbf, 0xbd); // U+FFFE "replacement character"
                }
            }
            var length=utf8.length;
            return length;
        }
    </af:resource>

Notice, the id used to find the element "out1" and stored into the variable counter is because my input text was on a taskflow which was being invoked from another taskflow which was present on a certain JSPX (Too much encapsulation I guess :P :P :P). So, I couldn't get it to work with just "out1". I had to use "pt1:r1:0:r2:0:out1" instead which is the Id of the component in the HTML version. The various colors are used just to give user an idea of how many characters (ergo bytes) are left. So, the counter value comes with a green background till 1000 characters are left. 1000 to 250 is Orange and after that its all Red.

Like I always say, its insignificant but it matters. Hope you guys liked it.

Wednesday, 13 April 2016

North-East - The Foster Child Of India

Time and again, I am made to realize this political fact of India. I hail from the beautiful region of north-east India and feel really bad when I see that our people are neglected time and again by the Central Govt of India. One such issue that has always grabbed my attention is the deplorable condition of the NH 44 which connects the people of Guwahati to Agartala.

This is an article (I was able to find this needle in the haystack, somehow!) describing the poor condition of the road:

Lower Powa, Oct 03 (ANI): Locals in Assam expressed dismay over the slow pace of repair work on a stretch of a national highway in the state, which had virtually turned into a paddy field since April following incessant rains. The condition of roads on a 15-kilometre long stretch of National Highway-44 between Lower Powa in Assam and Churaibari in neighbouring Tripura state has left locals worried and angry. The locals fear that if the pace of the repair work does not improve and it rains again the situation will become worse. However, according to the supervisor of the highway project, Pallab Dey, they were working hard. At least 200 lorries carrying petroleum products and around 250 lorries carrying perishable items like fish, fruits and vegetables have been stranded at Lower Powa village of Karimganj district due to the blockage as roads turned muddy after torrential rain. The consignments in the Tripura-bound trucks started decaying, contaminating the surrounding area. The lorry drivers and their assistants have been passing days without proper access to food, water and sanitation facilities.

Very little has been done in the last 10-15 years and it seems to be deteriorating everyday. Here are some recent pics from the troubled patches of the National Highway:



If the roads are not repaired before the monsoon season starts, Tripura will be deprived of basic amenities for a very long time.

It is time that people hailing from the region should start making noise to gain the authorities' attention. We already have to deal with a lot of natural calamities like floods, thunderstorms, earthquakes. We can do very little about these but we can do at least something significant to avoid these man-made calamities. This is just one of the instances of the authorities negligence towards the people of North-East India.

Hoping that things change soon :) :) :)