Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!

Jeff Ballie

+ Follow
since Jul 02, 2007
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jeff Ballie

Thanks Paul - that helped. I read the tutorial, and it looks like these are called markers rather than pins, which probably explains why my googling was so unsuccessful.. anyway, once I searched on maker, I turned up a tutorial for V3 of maps pretty quickly.

Just in case anyone else is following this thread and wants to know how it worked...

The only difference between this and the hello world sample on the Google Maps tutorial link is that the addition of the var marker stuff (also, I changed the zoom and pointed the map at sproul plaza in berkeley)...

This seems like such an obvious question that I feel I should preface by promising everyone that I really did try to google for the answer...

I was going through the google maps API tutorial (the javascript one)

The example was very simple to use... all you have to do is pass in some coordinates and bingo, you have a map (I'm not going to repost the code here, it's in the "Hello World" example).

Here's my problem - the map centers on the coordinates, but there's no "pin" on the coordinates like you usually get with google maps. I searched around, and I couldn't find any documentation on how to add a pin... it seems like the sort of thing that would be a simple property in the map options


If anyone has managed to do this, please let me know! Thanks.
Yeah, unfortunately I'm still a little confused about what kind of Map is returned from the code you provided (you mentioned a Map<String>, which would contain values selected by the user as the Keys... I'm assuming the keys map to whether the checkbox was selected? I did try to get this to work with a Map<String, Boolean> and a Map<String, Object>, but both gave me casting errors.

Anyway, if only the selected values are contained in the Map, then I don't think I'd get any advantages over a List (because the key would always map to true). The "Map" I was talking about with the kludge is a HashMap that has every field in the list as a key that maps to a "true" or "false" value... this way you would have full information about what was and wasn't selected (as you can see from my code, you actually don't get the hashmap, but you do get a true/false value associated with every element of the list.... I don't think this is any easier than just building a hashmap by iterating through the original list and mapping to true or false based on whether the name is contained in the values returned from the checkboxlist, and it's much kludgier, so I wouldn't recommend it either).

I may try to use the checkboxlist after all, since it seems to provide by far the cleanest solution - it was very easy to get that part working from your example, so the only issue is formatting, which seems pretty well documented (though I'll have to figure out how to implement it in different ways for different pages... if I get this working I'll post back).

10 years ago
Your checkbox solution definitely works. Just in case anyone else is following this thread... you can create a class

then have a struts 2 action class like this:

and then access this list in a jsp via

This works, though there's one minor downside - the resulting list will contain *only* those elements that have been selected. So if your form submission was
Choice A (checked)
Choice B (unchecked)
Choice C (checked)

The results of printing the list in setChoices() would be
Choice A
Choice C

which means that if choice B had been previously selected, and you'd persisted this somewhere, you need to keep track of what *isn't* in the list as well as what is... though that shouldn't be too big a problem, just a bit of extra programming.

(unfortunately, I wasn't able to convert this approach into an iterator that avoids using checkboxlist, and I couldn't find much documentation on the web on how to do this...)

It would be nice to set a map with choice names and a boolean for checked (or even just a list of Choices, ie., public void setChoices(List<Choice>) {}, though I don't think that's possible...

By the way, you *can* get a "map" with some hackery. If you name each field individually (and give up on getting an array) like this:

you can parse the names directly from the parameter list like this (in the struts 2 action class):

This has the advantage of providing a result for all the choices, rather than just listing the ones that were checked. If you've used Stuts 2 much, the disadvantages are pretty obvious (kludgy end-run around the conventions that make a struts 2 action class so useful and clean).

10 years ago
Thanks for the reply, Ankit.

Your solution would be effective for the checkboxlist tag... though I have to admit I'm a little disappointed to be splitting an object into several arraylists for the purpose of using a tag library. My first solution allowed me to just pass the object itself (the downside was that I couldn't read the results back in an array, which was leading to very cludgy code in the struts 2 action...)

I'd also prefer to avoid using the checkboxlist, because I want greater control over the formatting. I've read various methods to override this behavior and customize the formatting, but I need to control layout of checkboxlists on many different pages in different ways, which (I think) means I'd need to override the checkboxlist formatting five or six different times, with no real reuse outside of the page itself. So ultimately, I think it would be better to just do this in the page rather than overriding the tag...

Does anyone know how to modify the

So that it would return an array of choices?

Or, alternatively, how to modify (in the page itself)

So that it uses an iterator rather than the checkboxlist tag?

Thanks for the help.

10 years ago

I'm hoping to get some ideas/technical suggestions on how to handle a task in struts 2.

Here's a brief overview of the functionality I need.... I have a table with a bunch of choices that should be expressed as a checkbox, and I want to keep track of which choices a User has selected. Modeled in a db, it looks like

- name

- name


where selected is a boolean indicating whether a user has or has not selected the particular item (I've left out some obvious things like id's and so forth, since it's pretty standard... choices and Users are in N:1 relationships with the ChoicesUsers table - ie., many to many through ChoicesUsers)

So, I want to pass an object representing a choice and whether it was selected to a jsp, where I can display the choice name and put a checkmark if it was previously selected. If the user edits the choices, the form will submit, updates will be made to the db, and a new page will be rendered. So far, standard enough (I think).

One thing I really like about Struts2 is the convention that if I've named something choiceA in a page, I can have a getter/setter named getChoiceA() or setChoiceA(Boolean choice) and not have to deal with the request parameters directly. But unfortunately, I can't (easily) create on the fly methods called getChoiceA() (what do you think this is, rails? ;) )

I've struggled plenty with the checkboxlist tag, and while I've found lots of basic documentation by googling, I haven't been able to get much in the way of more how to tweak it to do something like this. Another thought was to use an iterator, which seems to work...

Though of course this puts me in a situation where I still either need to have a getter/setter for each choice name, or get parameters and parse the names (circumventing the whole get/set conventions that make Struts2 actions so useful, and creating pretty ugly code).

Another possibility would be to create an array of choices, but after hacking around, I wasn't able to get it to work. This would be the best solution - then I could have a getter/setter for an array (of booleans? strings would be easy enough to deal with as well). If anyone knows how to re-write the above so that I could just have a setChoices(ArrayList<Boolean> choices) method (or something similar), that would be really, really helpful.

Thanks to anyone who put in the time to read this far. Hey, if I'm approaching it all wrong and there's an easier way to do this, feel free to post your ideas!

10 years ago
I'm guessing that this question refers to the possibility of using Java code in a Ruby or Rails app? If so, it appears that you can create a class in Java and access it using Ruby/Rails - there's a tutorial on how to do this in netbeans at:

This does matter to me, because I use some third party software (ILOG Cplex) with a wonderful Java API, but I like Ruby and Rails, so the ability to call Java classes from ruby code in Rails would be useful.

Unfortunately, haven't tried it yet, so this is as far as I can go in this post... if anyone gives it a try, please let us know how it goes.
12 years ago
Thanks Ulf - I checked it out. This could work for me.

I'm a little bummed that Derby doesn't have a purely in-memory db, though, since this is the version that's going into Java 6. Does anyone know if this will still be the case for the version in Java (ie., no purely memory-resident DB)?

I suspect that a lot of model classes out there contain a large number of operations that are duplicating SQL at great expense. Personally, I'd get a lot of use out of an an in-memory database that would allow me to do various joins and sub-selects on data using SQL.
Thanks for the link.

Looks like I misinterpreted what "memory-resident" means. In the derby case, it appears to mean that the entire contents of the database are loaded into memory - so the app doesn't need to read from disk at run time. I was under the impression it meant a database with a lifecycle similar to one of the container classes.

That said, I can actually see a use for a database that only exists as long as the application is running. Like using a linked list or hashmap for a specific purpose, then discarding it later without persisting it to disk.

I'm using Derby for some testing, and I thought it was a completely memory-resident database. However, I'm noticing some files are left behind on my hard drive. I'm not deliberately persisting anything to disk, and I haven't added anything to my code that seems to write to disk. Does anyone know what these files are? Or is Derby not entirely memory-resident?

Thanks for the reply, Jeanne.

I did notice that JUnit with will provide information about execution time, and I'm just looking for a ballpark figure, so I'll probably just write a single unit test that does nothing more than run the app and verify completion.

I've been using NetBeans until recently and I decided to try Eclipse. It's great, but I'm stumped about one thing - I can't figure out how to get the IDE to display the amount of time it took for a program to execute. I've checked help and googled and I'm not finding anything.

In netbeans, after executing a program the console reads something like BUILD SUCCESSFUL (total time: 10 seconds)...

Anyone know how to do this in Eclipse?