javabeans

Deep-Initialising Java Bean properties

Do you bother initialising java bean values? Say, for example: ([g|s]etters omitted) public class SomeClass { private String foo; private Date bar; private Baz someObject; } (Yes, this is a POJO being used as a bean rather than a Java Bean in the strictest sense) In the empty constructor, do you initialise these memb...

Immutable beans in Java

I am very curious about the possibility of providing immutability for java beans (by beans here I mean classes with an empty constructor providing getters and setters for members). Clearly these classes are not immutable and where they are used to transport values from the data layer this seems like a real problem. One approach to th...

JavaBeans alternatives?

I hate the JavaBeans pattern with a passion that burns like the fire of a thousand suns. Why? Verbose. It's 2009. I shouldn't have to write 7 LOC for a property. If they have event listeners then hold on to your hat. No type-safe references. There is no type-safe way to reference a property. The whole point of Java is that it is type s...

Java date and calendar controls

Does anybody have any recommendations of good date pickers (either drop down calendars or small calendar components) for use in a Java Swing application - either beans or source code? They need to be robust enough for commercial applications. ...

List<Map<String,Object>> to org.json.JSONObject?

List<Map<String,Object>> list = new ArrayList<Map<String,Object>>(); Map<String, Object> map = new HashMap<String, Object>(); map.put("abc", "123456"); map.put("def", "hmm"); list.add(map); JSONObject json = new JSONObject(list); try { System.err.println(json.toString(2)); } catch (JSONExce...

How can I serialise a javabean to be loaded by Spring's DataBinder?

I need to serialise a javabean (with arbitrary nested beans) to plain text, and then later restore as an Object graph. For the purposes of this question I am not interested in XML, JSON, etc. but rather name/value pairs. The Spring DataBinder is great for turning a list of name/value pairs into a real Object. For example we can supply:...

Monitor changes to a collection

Say you have the following java bean: public class MyBean { private List<String> names = new ArrayList<String>(); public void addName(String name) { names.add(name); fireNamesPropertyChange(name); } } How would you normally implement a property change event for a collection? Do you try and use the inde...

How to convert a Java object (bean) to key-value pairs (and vice versa)?

Say I have a very simple java object that only has some getXXX and setXXX properties. This object is used only to handle values, basically a record or a type-safe (and performant) map. I often need to covert this object to key value pairs (either strings or type safe) or convert from key value pairs to this object. Other than reflecti...

Creating immutable objects from javabean

Hi All, I am involved in this project where we are building on good bit of legacy code. I have a particular situation about one big java bean object which has to be transferred over wire. So my first thought was to make it immutable and serializable to do the trick .At this point I am faced with a few difficult choices :- 1> Ideally ...

Valid java bean names for booleans

I know most variable names will work with "is", such as isBlue, but is "has" also a valid prefix, like hasProperty? ...

Reading contents of a managed bean with reflection in a JSF application

Hey, I want to print out the contents of a backing bean in an auto-generated way. So all the contents appear on a JSP. Is this possible anyhow? Thanks in advance, Daniel ...

Handling a complex Bean-tree in JSF

Hey, Let's take a look at this bean structure for example: public class Abean { private Bbean b; } public class Bbean { private ArrayList<Cbean> c; } public class Cbean { private ArrayList<Dbean> d; } public class Dbean { .... } So basically Abean containts everything. Now I want to make JSPs for all of these beans, w...

How to copy properties from one Java bean to another ?

I have a simple Java POJO that I would copy properties to another instance of same POJO class. I know I can do that with BeanUtils.copyProperties() but I would like to avoid use of a third-party library. So, how to do that simply, the proper and safer way ? By the way, I'm using Java 6. ...

Passing a backing bean instance as parameter for another backing bean method

Hey, After the user fills my backing bean with info through the forms, I want to process the instance in Java code (such as JAXB marshalling). So at the moment i'm doing this like so: <% OtherBean.method(myBackingBean); %> which is - if i'm right - not quite an up to date solution :) So how can I make this happen in a 'better' way? ...

way to initialize a javabean to random values

I was looking for some utility class/code that would take a java bean and initialize all its values to random values. It could be done via reflection as some libraries already create the toString() or equals() methods. Is is useful while developing the UI to have some data for example. Other possible nice to haves: recursively initia...

Most effective way to process a string containing XML, in JAVA

Hello, I have a String which contains XML nodes within it, and am seeking to use DOM parsing to process this string to extract node values and store them in local variables. The XML which is stored in a String variable: <carGarage> <car> <make>Chrysler</make> <color>Red</color> </car> <car> <make>Musano</make...

JSP useBean scope question

Hi there, I have 4 JSP pages index.jsp - default index webpage. Index.jsp includes the build.jsp to initialize the web service as well as the header.jsp (to display the form with the dropdown element. Users can select a value from this form and submit the form to formControl.jsp.) build.jsp - This jsp is included in index.jsp before th...

JSP useBean Request scope question

Hi there, I am setting the values of a java bean from a jsp page which has the useBean scope of request. Does this mean that the java beans will lose their value once a user navigates away from this page? ...

JasperReports JRBeanCollectionDataSource still confused...

So I do now have my working and filling reports. The users of my program can now pass objects from the program to a report object and fill it using the JRBeanCollectionDataSource and that does work. However I can't get all the data in the report I want. I am just very confused about this, how the fields that I declare with a name and...

Sorting an collecton of java beans by field

Hi, I have an collection of java beans that populate a JSF DataTable I'm trying to implement column sorting. I'd like to sort the array/collection depending on the field selected. I have using Reflection in the past for this, but wanted to find a neater way of doing it, using Commons BeanUtils and/or Collections but can't seem to find...