Tuesday, August 19, 2008

Error on File output Stream in Jboss Seam application

The Sessin Bean mthod as follows
public void file(){
       HttpServletResponse response = (HttpServletResponse)facesContext.getResponse();
       response.setContentType("application/rtf");
       response.addHeader("Content-disposition", "attachment; filename=Direct.rtf");

       try{
          ServletOutputStream os = response.getOutputStream();
          File file = new File("c:\\Direct.rtf");
          FileInputStream fis = new FileInputStream(file);
          byte bytes[]=new byte[1000];
          int read=0;
          while((read = fis.read(bytes)) != -1){
              os.write(bytes,0,read);
          }

          os.flush();
          facesContext.responseComplete();
          os.close();

          log.info("\nSuccess\n");
       }catch(Exception e){
          log.info("\nFailure : " + e.toString() + "\n");
       }
    log.info("Completed");
   }

The tag as follows.
Open file

But I am getting the following exception
SEVERE: Error Rendering View[/testTable.xhtml]
java.lang.IllegalStateException: Servlet response already use stream, Writer not possible
at org.ajax4jsf.webapp.FilterServletResponseWrapper.getWriter(FilterServletResponseWrapper.java:226)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
at com.sun.facelets.FaceletViewHandler.createResponseWriter(FaceletViewHandler.java:414)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:571)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:189)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:256)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:362)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:488)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)

Wednesday, August 6, 2008

Kerala:How the mindset of young Muslims is changing

"Muslims in Malappuram believe that they can use education as a tool to change their lives for the better," says Malappuram native Dr Husain Randathani, who is into the final stages of his book Mappila Muslims: Society and Struggle.
"The liberalisation of the Indian economy has triggered a growing belief in education, because they -- especially the younger Muslims -- believe they too can join the economic bandwagon, they can be a part of it and benefit from it."

"We tell our students that religion is a must," says Abdul Hakim, a teacher at Baitul-Huda, a private school at Kozhichana in Malappuram, the Muslim-dominated district in north Kerala.
"But we also tell them that religious education is in itself not enough -- they need to learn English, they need to learn regular subjects, and they need to excel in these studies in order to hold their own, and to compete, with the rest of the world."

Taken together, those two statements encapsulate a dramatic change that is sweeping across a district that is over 90 per cent Muslim in population: The younger generation increasingly believes in education as the panacea for their ills, and the elder generation is willing to break the mindset of a lifetime, and concede that a Koran-centric education will no longer suffice.

P P Abdul Rasheed has been closely associated with this changing landscape, first as a professor at Farookh College, Kerala's first exclusively Muslim college, and more recently, as principal of a newly established private educational institution in Malappuram.

"I remember some seven years ago, we did a sample survey in Farookh College," Professor Rasheed recalls. "We asked the students what they wanted to be when they grew up -- and an overwhelming majority said they wanted to go to the Gulf."

"They didn't say what they wanted to do there -- just going there was an end in itself. Becoming a cricket player was second on the list, then came doctors, engineers and such. No one wanted to go for the IAS and other competitive exams; no one, not one single respondent, wanted to be a scientist."
A similar survey a little over a year ago produced radically different results, Rasheed says: The number of Gulf aspirants dropped below the 50 per cent mark; careers in information technology came out of nowhere and moved into the second slot; a sizeable number opted for science and related areas of specialisation -- and not one single respondent mentioned cricket as a career goal.

"Aspirations are changing, and very clearly, as you can see from the interest in IT, the increased opportunities within India are driving that change," Professor Rasheed suggests.
He isolates two factors that are acting as catalysts: "One, till the turn of the century, a vast majority of the girls in our college and in fact in our community looked on education merely as a stop gap, a way of improving their matrimonial prospects. In the last five to six years, however, girls -- and their parents -- have realised that they can have rich, rewarding careers in various fields, especially science, IT, the medical and engineering streams, and government service. Significantly, the girls don't see the Gulf as a career goal."

"Ten years ago, even six years ago, the goal of the average young Muslim was escape -- from the stifling poverty of this district to the Gulf, or into marriage, depending on sex. Today, they aspire, they dare to dream, and that is a very significant change, the real implications of which will be felt only a decade or so down the line."

The other key factor, Professor Rasheed believes, is in how the community has been using what in local parlance they call 'Gulf money' -- the sizeable remittances that come from the Diaspora.
Estimates indicate that remittances from abroad amount to 21 per cent of Kerala's GDP; in Malappuram, which boasts with some justification that every family has at least one member working abroad, mostly in the Gulf countries, they estimate that over between 55 to 60 per cent of the district's GDP comprises remittances.

"There is a change in how we are spending that money," Rasheed says. "The trend used to be towards wasteful expenditure -- those who were settled in the Gulf sent money home, which their families used to buy land, put up fancy homes, and fill it with all kinds of electronic gadgetry. It was all about conspicuous consumption."

That, says the professor, is changing, albeit gradually. "I am not suggesting we don't go in for ostentatious expenditure any more -- if anything, it has gotten worse, since more goods are available in the market. But the good thing is, there is a trend towards doing something for the community, of giving something back, of contributing to the larger welfare."

This emerging mindset manifests in an increasing number of private schools; in growing numbers of scholarships that are set up for the benefit of poor, but deserving, students from the community. "Earlier, buying a fancy car or building a posh house was the biggest status symbol; today, it is putting your name to a scholarship," Professor Rasheed says.

A Abdul Wahab, director, scholarship programme, Islamic Youth Centre, says, "There has been a gradual change in the Muslim society of Kerala for the last seven years, as many more young people are educating themselves and excelling in their respective fields."

"Places like Malappuram, Kozhikode, Kannur, Kasargode and Waynad in Kerala have seen the trend of Muslim students taking education very seriously, and they are ready to compete on any platform with anyone. It is a sign that things are changing for the better in our society."
As with any quantum societal shift, the one among Malappuram's Muslim population is producing its own share of problems. 'Problem' might in fact be an odd descriptor for a trend that has seen Muslim students significantly increase their pass percentages, but consider this:
In 2007, Kannur district registered a pass percentage of 90.79 per cent in the SSC exams; Malappuram soared from 51 per cent to 76.62 per cent; Kasargode's figures rose from 68.6 per cent to 80.1 per cent, and Kozhikode also registered 80.6 per cent.

All these districts have significant Muslim populations, and while there are no ready figures available to break the pass percentages down by community, Muslim educationists tell us that by extrapolating the evidence from their own schools, they believe that the increased interest in education shown by the Muslim youth is one of the factors driving this uptick. And the figures for Malappuram seem to bear out that assessment.
Therein lies the catch: Educationists estimate that a one per cent uptick in pass percentages add, in each district, between 500 to 800 additional students seeking admission in colleges each academic year

Courtesy: Syed Firdaus Ashraf and Prem Panicker at Rediff.com