Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Jarno Virta

Greenhorn
+ Follow
since Nov 25, 2013
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jarno Virta

Well now I feel silly. <c:url> does take care of those Äs and Ös, the link is shown in browser as decoded text of course so I thought it did nothing to those. So it was all just a problem with server configuration. How silly. Oh well...
3 years ago
JSP

Stephan van Hulst wrote:Can you show us some of the related code, and describe the exact problem that's being caused?



Well my question was mostly general. Am I supposed to encode those characters? I'm wondering this because <c:url> tag does do encoding but doesn't do anything to characters like Ä or Ö.

I've since tinkered with my code and I got everything to work. I did add encoding for those characters. But the code in the JSP is quite ugly. This is how I got the necessary parameters encoded:



So I used URLEncoder.encode() for encoding the parameter. But I couldn't just put it into <c:url> value attribute or the %'s would get encoded. I got around it using <c:set>. This looks way too complicated, though.

And I'm still wondering if it is generally good practice/recommended to encode those characters? Or is what I just did pointless?

In the end the problems I was having weren't due to me not encoding those characters, I think. The problem was that the production Tomcat server needed to be set to UTF-8 by adding URIEncoding="UTF-8" to the Connector tag in server.xml. This fixed it.

But I'm still wondering if I should keep the characters encoded or if its generally ok to have Ä's and Ö's and such in parameters?
3 years ago
JSP
Hi!

I have a problem with the query part of my URL:s on my website. I need to use Scandinavian alphabet in the query /parameters part (like [mydomain]?name=Räty). When I'm running my server code on my home computer, I have no problem with them. But when deployed to a US based hosting service, they do cause a problem.

I'm using c:url in my JSP:s and it encodes my parameters, but not Scandinavian alphabet. First question is am I supposed to encode them? Google search of URL encoding only produced instructions saying alphanumeric characters don't need to be encoded. But how about non-English alphabet?

Or is this a problem with the character encoding of my Tomcat server? I have a CharacterEncodingFilter set to UTF-8 in my Spring MVC web.xml. Do I need to do something with my Tomcat settings?

If I need to encode non-English alphabet, how do I do this in JSP and what do I need to do on server side in my Spring MVC-server code to decode the query parameters?
3 years ago
JSP
Hi! I'd like to know if there are ready made libraries/plugins that I could use to run ads on my website. That is to say, ads I get directly from advertisers, not Google ads or any other such thing. I'm going to get a few small companies to run ads on my site. The server is in Java, front end is JSP:s. Is there a simple way of doing this or do I have to code this myself? Besides having like a carousel kind of an ad banner on my site, I'd like to keep track times the ad is shown and of clicks. I'd also like for the advertiser to be able to upload images for the ad carousel on their own. This I might have to code myself, I guess.
Yes. And as I said, just switching the place of one of the arguments at random, in both the SELECT query's NEW and the class' constructor arguments, fixes the problem. For that reason I was thinking might the query be cached somehow and maybe there was a change in datatype or something and maybe that might cause a problem with how the constructor call is made...? When I was poking around with this, just removing any of the arguments or adding an argument fixed the problem and switching back to the original argument list made the problem reappear. I also modified the database service method by removing the NEW call and I took the complete reports from the database, then looped through them and called the constructor for ReportQueryObject class for each report instance with the same exact properties as in the original query's argument list. That too worked without any problem. Weird...
Its just the getResultList() call. So when that call is executed, the constructor method of the result class is called as specified in the JPA query and for some reason that call goes wrong. I have copy-pasted below the database service method which causes the exception. The constructor just sets the relevant properties and does nothing more.

What the method below does is it finds the reports the logged-in user has created and returns a list of objects which are used for showing a report list to the user. The objects that are created only certain of the reports' properties bacause the actual report objects are quite large.

Hi,

So I ran into a weird problem with EclipseLink and was wondering if anyone could tell me what may have caused this. I have a JPA query using NEW so I get objects for my query result with just certain of their properties set. Everything worked fine until I noticed something no longer did. That is to say, I started getting an exception with code that I hadn't changed. It may be possible that there has been some change to the datatypes of the relevant properties, although I don't really remember having made such changes. The exception is below.

After a lot of going through stuff, I noticed that removing any of the arguments in the SELECT NEW statement and my class constructor fixed the problem, as did adding an argument. So what I ended up doing is I switched the places of two arguments in my query and the constructor and that too fixed the problem. So what is going on here?? Are these queries cached in a way that might cause EclipseLink to call the constructor with arguments of wrong type if there have been changes to the code?


javax.persistence.PersistenceException: java.lang.IllegalArgumentException: argument type mismatch
at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:479)
at fi.testcenter.service.ReportService.findUserOwnReportList(ReportService.java:269)
at fi.testcenter.service.ReportService$$FastClassBySpringCGLIB$$be91c3cc.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:633)
at fi.testcenter.service.ReportService$$EnhancerBySpringCGLIB$$5435a48.findUserOwnReportList(<generated>)
at fi.testcenter.web.SearchController.setupSearchHomePage(SearchController.java:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.invokeConstructor(PrivilegedAccessHelper.java:389)
at org.eclipse.persistence.queries.ReportQueryResult.buildResult(ReportQueryResult.java:121)
at org.eclipse.persistence.queries.ReportQueryResult.<init>(ReportQueryResult.java:78)
at org.eclipse.persistence.queries.ReportQuery.buildObject(ReportQuery.java:593)
at org.eclipse.persistence.queries.ReportQuery.buildObjects(ReportQuery.java:644)
at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:847)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1114)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:402)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1202)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2894)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1797)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1779)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1744)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:468)
... 78 more

Yeah, I guess its ok. I was thinking of archiving old reports, so thats probably what I'm going to do. It just seems silly and sort of wrong to have scanned documents that are only a few pages but over a megabyte. Then again, we havent found a setting in the scanner to reduce the size. I think I'm just going to let it be since the overall size won't be a problem for database. I'll check with the hosting provider for the total space available to us, but I'm sure it is sufficient. Thanks for your answer!
Hi,

I have a web app for writing reports. The annexes to the reports are scanned documents of a few pages per report, which are stored in the database. My clients scanner is producing scanned documents that are something like 200 kb by page, so many of the annexes are in the 1 - 1.5 Mb range. This somewhat annoys me and I'm worried about how big the db is going to become at this rate. We checked the settings of the scanner and this was the lowest setting that produced acceptable quality (300 dpi, i believe). I dont really know if this file size is normal for a scanner. So my question is does this sound normal to you or should something be done? The client is a very small business and I'd guess once their business really gets up and running, there might be 500-700 reports per year, so the db would grow accordingly.
Sorry for the confusing thread title... I'm not sure how to summarize my question. I'm trying to figure out how to write my Spring mvc controller so that in certain cases the controller returns the user to a previous url instead of the default url/view. So let me explain. I have an app with user accounts and clients for the business I'm creating the app for. So lets say the admin user wants to add a new user account and the new user represents a client that is also new. I'd like the admin to be able to go from editing new user info to editing new client info and then return to editing the user where he could then set the newly created client as the one that the new user represents. The point being that the normal path from editing a new client is to a view showing a list of clients.

I have run into this in several situations, needing to control the flow of the app in this kind of spots. So I'd like to ask whats the default/best option for accomplishing this?

I was thinking I could just use a SessionAttribute like boolean returnToEditUser while going through editing the new client info and if the attribute is set to 'true' the controller method responsible for saving the new client info would redirect to editing the new user. Or maybe set the redirect address as a SessionAttribute so that this would work for redirecting to several urls: However, this would seem to require the attribute to be always present for the methods doing the editing and saving of the client. It would have to be set in all cases where the user edits client info, no? Maybe it isn't a huge issue but it doesn't seem very eloquent. There is a way of making the attribute optional or setting a default value?


Edit: oh wait, SessionAttribute wont work since if the user aborts editing and goes to the home page of the app, the attribute will cause a problem later if he returns to the page for editing client account info...

Edit2: since i used the word 'flow' in my post, is this something that Spring Web Flow is for and if so, could this be relatively simply done with it?
7 years ago
Hi! I'm going to recommend a book I haven't actually read. Its Murach's Java Programming. Latest edition seems to be 2011. The reason I am recommending it is that I have read other Murach's books, one on Javascript and JQuery, one on HTML5 and CSS and one on Java Servlets and JSP's. I absolutely love their step by step approach. The books usually take you through the development of a single example and you take small steps. Everything is explained in a short text, like 1 or 1 1/2 page and on the next page you have very clear examples. Each chapter has exercises if I remember correctly. This small steps approach has worked very well for me. I have also found the examples in those books to be practical and useful for reference later on. I think their Java book would have been better for me too when I started, I got the 1000 page Java Complete Reference, because hey if you are going to learn it, get the biggest brick of a book, right...? I guess the name should have been a hint.

7 years ago
Hi,


I would like to get back to a question I posted here earlier. The old thread is this https://coderanch.com/t/641191/open-source/Converting-dynamic-report-JasperReports. I figured I'd make a new, more brief and specific OP on the question.

So I have a reporting program and I'd like to know if you guys recommend i use iText or JasperReports for generating pdf-reports. The report has a bunch of questions under question groups which are in report parts. The database is JPA 2 (EclipseLink). The way the annotations are set up, i can fetch an entire instance of a filled out report, questions, answers, report part titles and all, in one simple query. So I'm thinking this should be just as easy when working with JasperReports? Basically, the instance of Report has ReportParts which have AnswerGroups which have Answers and Answers. Answers have a reference to the relevant question in a ReportTemplate instance so this is where i get the question for each. These would need to be looped through.

The thing is, there are a few different types of questions and answers (plain text, multiple choice, etc) and these need to be displayed accordingly. I'm not sure if this is something that can be easily done with JasperReports, for example displaying answers to multiple choice questions with checkboxes based on the selection? Can JasperReports be programmed to show data based on the subclass of my Answer class, for example MultipleChoiceAnswer? Right now this is tipping me toward iText as the layout of the report is fairly simple and I think it won't take a huge amount of coding once I get going. Also, pdf's should be enough as output and right now it doesnt seem like other formats will be needed, although I'm not 100% on that. On the other hand I guess JasperReports and iReport and the option of generating in various file formats would be handy and learning to use iReport would be good for future projects.

Thoughts? How easily could this be done with JasperReports? I'm asking so that I would hopefully start on the right path right away.
Hi!

Thanks again for your answer and help! Yeah, I figured I'd make a separate question of the pdf generation side. At the moment I'm just trying to figure out which way to go and what technology could be most useful. I have a few things to fix in my code and then I'll have to start getting into pdf stuff. I have never worked with JasperReports, so I'll have to learn as I go. I have printed the guide to iReport and the library.

The report is not going to be a bunch of answers by a bunch of people like a list of questionnaire answers. Rather, the guys I'm writing the program for will have someone visit a business as a client and observe the quality of service and write a report on that. The businesses are auto repair shops and the clients of my friend will be importers of motor vehicles. So basically they will provide pick an auto repair shop and send someone over with a car with defects and rate the performance. So its one set of answers per report.

Based on the other thread I revamped the class structure of the program. As I mentioned earlier, the questions for each client (importer) will be different. So I have a class called ReportTemplate which has a List of ReportParts, and they in turn have a List of QuestionGroups, which in turn have a List of Questions. Based on the earlier discussion I removed all that relates to answers and made a separate class called Report the instances of which will contain the answers. So Report has a reference to the relevant ReportTemplate and an ArrayList of Answers. When the report is filled out or shown, the parts and groups and questions in ReportTemplate are iterated through. I figured Report doesn't need a Map<Question, Answer> but an ArrayList<Answer> is sufficient and answers will be stored in the order of the questions in ReportTemplate (starting with ReportPart[0], QuestionGroup[0], Question[0]). This may change if need be, but for now I think this is sufficient.

So I think this class structure is ok now and it works fine for filling in and showing the reports. Also, saving the report in database and fetching it works. So when fetching a particular report, I'm going to get the instance of Report which references ReportTemplate and iterate through them as described.

As I said earlier, I'm very much a noob when it comes to ORM. I'm learning as I go. And since I have never used JasperReports, I don't really have an idea of how well it will work for this kind of report and which would be the easiest way of generating a pdf file of the report. So to be honest, I cant really say for now what I can and can't do with JasperReports and SQL.

I'm interested in all ideas as to which way to go. Then, based on any guidance I'll get here, I'll break out my books and guides and learn what I need. It's just that any pointers would be very useful so that I'll hopefully take off on the right path as I'm sure there will be quite a bit to learn and do to get the pdf generation done. For now, I have a working solution to print to pdf using PDFCreator and it produces fairly nice looking reports but it's not a convenient enough solution in the long run.

Hi,


I'm developing a web app for writing reports on the quality of service provided by businesses. Its for a company that does tests, they go to a business as clients and take note of various aspects of the services provided. The report will have parts divided into question groups on particular topics, each of which will have questions. The questions can be of a few different types each of which needs to be printed accordingly (questions with plain text answers, multiple choice questions, etc). The report parts, question groups and questions are dynamic and they will be different for different clients.

So my question is, which would be the best way to go to generate pdf's for such reports? So I need to loop through the report parts, question groups and questions and print the answers. Multiple choice questions should have checkmarks where appropriate. The report should obviously also have headers and footers, a background image, nice front page etc. Will it be feasible to fetch the report parts, question groups and questions from database using JasperReports (the ReportTemplate object will have these as properties) as well as the answers given in a particular report. A Report object will have an ArrayList<Answer> listing the provided answers (plain text answers, multiple choice, etc) in the order that they are iterated in the relevant ReportTemplate. Does this sound feasible and how would you do it?

I could of course first produce xml of the questions and answers if it's not possible to fetch all of these from a database.

So how would you do this? JasperReports or something else?