java

Organize imports with Maven2, Eclipse-style?

I'm a lone Emacs user in a group that's hung up on Eclipse. Time and again, code diffs are made larger by imports that have been "organized" or "cleaned up" by Eclipse. I don't have a strong opinion on the subject of import style in Java, but I do want to minimize our diffs. What can I do? We use Maven2 for builds; is there a plugin th...

Reading Excel file (.xls) in Java

I want to read text from excel file in J2SE using NetBeans. I found an article here about using Apache POI and JExcelApi, but I'd prefer not depending on external packages. if possible, using only Java built-in packages. This almost worked, but it gives me an exception error: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data ...

Rendering a nested list with JSP

I need to render a 3-level deep list of items via JSP. Let's say I have beans with String properties "Country", "City", "Street". I need to build a heirarchy of UL and LI tags to show streets such that they are listed under the appropriate city, and such that each city is listed under the appropriate country. Example: <ul> <li>United S...

What is a simple example of using Seam's MockExternalContext to unit test?

I'm trying to unit test my seam components, and so far I've been doing pretty well with the EasyMock that my team has been using. However, I have run into a wall with javax.faces.context.ExternalContext. Since it's not an interface, I can't run EasyMock.createMock() on it. Seam has a MockExternalContext, but I have no idea how to use ...

"Missing Body Element" with the Visual Web Pack on Netbeans

I am currently having an issue with the JSF pages that the Visual Web Package for Netbeans 6.7 generates. When I generate a new page it produces a page with the following JSP code: <?xml version="1.0" encoding="US-ASCII"?> <jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:js...

Spring 2.5 Form validation - Dynamic data lost if validator is called?

I have a simple form that has a select box populated by the database. When validation is triggered the select box is empty. I'm new to spring and I seem to be missing something. Any help is appreciated? Thanks in advance. In the controller below sites is the dynamic content. @RequestMapping("/registration/registration.html") public Mo...

Convert between URL and windows filename (Java)?

Is there a standard/good way of converting between urls and windows filenames, in Java? I am trying to download files, but I want the windows filename to be convertible back to the original filename. Note that the query portion of the url is vital, as I will be downloading different pages that differ only in query. My current hacky ...

Is it possible to loop through a classes members in java?

I have a DTO that has a whole bunch of members. I was wondering if Java supports the idea of a for(in) for the class. I don't think it does, but it would save me a ton of grief if it did, so, I figured I'd toss the question out there. ...

Is there such as role as a Java Runtime Administrator?

There are Database Administrators (DBA) and Unix|Windows System Administrators. There are likely soon to be Cloud Administrators. There are hordes of "administrators" who are tasked with administering and managing numerous large-system JVMs running on/in various stacks, yet I've honestly met very few of them who have any real understan...

InputMissMatchException

I want to read data about MMORPG characters from a .txt file and then filter on experience (minimum experience). But I'm getting this exception, which I know the meaning of but I really don't understand what I'm doing wrong. this my code: I'm not good at java, I'm a beginner actually. Can someone please explain this to me. Probably I'm ...

hibernate c3p0 broken pipe

Hi, I'm using hibernate 3 with c3p0 for a program which constantly extracts data from some source and writes it to a database. Now the problem is, that the database might become unavailable for some reasons (in the simplest case: i simply shut it down). If anything is about to be written to the database there should not be any exceptio...

Using Mockito to mock classes with generic parameters

Is there a clean method of mocking a class with generic parameters? Say I have to mock a class Foo<T> which I need to pass into a method that expects a Foo<Bar>. I can do the following easily enough: Foo mockFoo = mock(Foo.class); when(mockFoo.getValue).thenReturn(new Bar()); Assuming getValue() returns the generic type T. But that...

Is there a one-liner or some extremely easy to use tool to create utility jars?

I'd like to show other people how to create jars from their code, so they can share it with others. In the meantime, I'd like to make this as easy as possible for them. What would be the easiest way of doing that? ...

How do you write these loops in a nicer way in Java?

I have a set of objects I'd like to do some operations on, in the order they're iterated. After that operation gets called on them, I'd like to perform other operations on them. Basically, the code will look sort of like this: for(int i = 0;i < myobj.size();i++) { myobj.at(i).doSomething(); } for(int i = 0;i < myobj.size();i++) { ...

How to analyze evenness/oddness of numbers in Java

I have to write a program which reads in 3 numbers (using input boxes), and depending on their values it should write one of these messages: All 3 numbers are odd OR All 3 numbers are even OR 2 numbers are odd and 1 is even OR 1 number is odd and 2 are even This is what I have so far: import javax.swing.JOptionPane; class program3 ...

Can a Jtable save data whenever a cell loses focus?

The high level: I have a JTable that the user can use to edit data. Whenever the user presses Enter or Tab to finish editing, the data is saved (I'm asusming that "saved" really means "the TableModel's setValueAt() method is called".) If the user leaves the cell in any other way after making an edit, the new data is not saved and the v...

NullPointerException when trying to set a jcheckbox

Trying to set it so if a certain condition is met then one of two check-boxes will be checked. However I keep getting a nullpointerexception error. the code is.. //Set the flat rate or hourly billing check boxes. if(flatRateint > 0) { InvoiceUI.jCheckBox1.setSelected(true); } else { InvoiceUI.jCheck...

Java Framework - Using screen scraping to mesh heterogenous server environments

OK. So I have a CMS written in Java that satisfies the needs of several hundred clients. But periodically, a client will need a specialized application: for example, a class registration database application. So let's say that I don't feel like writing it or I'm too busy. So I outsource it to someone else but I don't want his/her code ...

converting a calendar date to a string?

I am trying to get the program to call up the current date, add 30 days to it, and then out put that date as a string. // Set calendar for due date on invoice gui Calendar cal = Calendar.getInstance(); // Add 30 days to the calendar for the due date cal.add(Calendar.DATE, 30); Date dueDate = cal.getTime(); d...

Accessing frames from a video using Java

I have a video file which consists of series of rgb format images, for example: video name : static_camera2.576v frame size : 480x368 frame rate : 12 frames/sec duration : 5 sec I need to access each frame with starting frame as I and need to extract all frames so that I can calculate the Motion Vectors based on the previous frame – ...