What’s the effect of adding ‘return false’ to an onclick event?

The return value of an event handler determines whether or not the default browser behaviour should take place as well. In the case of clicking on links, this would be following the link, but the difference is most noticeable in form submit handlers, where you can cancel a form submission if the user has made a mistake entering the information.

I don’t believe there is a W3C specification for this. All the ancient JavaScript interfaces like this have been given the nickname “DOM 0”, and are mostly unspecified. You may have some luck reading old Netscape 2 documentation.

The modern way of achieving this effect is to call event.preventDefault(), and this is specified inthe DOM 2 Events specification.

http://stackoverflow.com/questions/128923/whats-the-effect-of-adding-return-false-to-an-onclick-event

Struts Tip #7 – Use Multibox to manage checkboxes

Many applications need to use a large number of checkboxes to track options or selected items. To help with this, Struts provides the multibox control. It’s quite handy but a little tricky to understand at first.

The multibox leverages the way HTML handles checkboxes. If the box is not checked, the browser does not submit a value for the control. If the box is checked, then the name of the control and its value are submitted. This behavior is the reason there is a reset() method on the ActionForm. Since the browser will never signal that a box has been un-checked, the only solution is to reset all the boxes, and then check the ones that are now present in the request.

The multibox control is designed to use an array of Strings. Each element in the array represents a checked box. To check a box, add a String to the array with the box’s value. To uncheck a box, remove the element from the array. (Sound familiar?)

When passed a value, the multibox control scans the elements of its array to see if there is a match. If so, the box is checked. If not, the box is left unchecked. If the user checks the box and submits the form, the box’s value will be included in the request. The controller will then add that box to the “checked” array. If a box is unchecked, nothing is submitted, and nothing is added to the array. If the ActionForm bean is kept in the session context, in between requests, the reset() method needs to reduce the array to zero length (but not null).

In this example,

<logic:iterate id="item" property="items">
<html:multibox property="selectedItems">
<bean:write name="item"/>
</html:multibox>
<bean:write name="item"/>
</logic:iterate>

The labels for the individual checkboxes is in the items property. The list of selected items is in an array named selectedItems. Items that are not selected are not present in the selectedItems array. The multibox checks the selectedItems array for the current item. If it is present, it writes a checked checkbox. If not, it writes an unchecked checkbox.

Given an ActionForm setup like this

private String[] selectedItems = {};
private String[] items = {"UPS","FedEx","Airborne"};
public String[] getSelectedItems() {
return this.selectedItems;
}
public void setSelectedItems(String[] selectedItems) {
this.selectedItems = selectedItems;
}

The markup in the example would generate three checkboxes, labeled UPS, FedEx, and Airborne.

<input type="checkbox" name="selectedItems" value="UPS">UPS
<input type="checkbox" name="selectedItems" value="FedEx">FedEx
<input type="checkbox" name="selectedItems" value="AirBorne">AirBorne

Initially, the selectedItems array would be empty. If UPS were checked and submitted, it would become the equivalent of

private String[] selectedItems = {"UPS"};

If UPS and Airborne were both checked, it would become the equivalent of

private String[] selectedItems = {"UPS","Airborne"};

And when the checkboxes are rendered, the appropriate elements are automagically checked by the multibox tag.

<input type="checkbox" name="selectedItems" value="UPS" checked="checked">UPS
<input type="checkbox" name="selectedItems" value="FedEx">FedEx
<input type="checkbox" name="selectedItems" value="AirBorne" checked="checked">AirBorne

To provide different sets of labels and values, the standard LabelValueBean class [org.apache.struts.util.LabelValueBean] (since 1.1) can be used with the multibox control.

<logic:iterate id="item" property="items">
<html:multibox property="selectedItems">
<bean:write name="item" property="value"/>
</html:multibox>
<bean:write name="item" property="label"/>
</logic:iterate>

HTH, Ted.

http://www.jguru.com/faq/view.jsp?EID=925277

Convert ArrayList containing Strings to an array of Strings in Java?

List<String> list = ..;
String[] array = list.toArray(new String[list.size()]);

For example:

List<String> list =new ArrayList<String>();
//add some stuff
list.add("android");
list.add("apple");
String[] stringArray = list.toArray(new String[list.size()]);

The toArray() method without passing any argument returns Object[]. So you have to pass an array as an argument, which will be filled with the data from the list, and returned. You can pass an empty array as well, but you can also pass an array with the desired size.

http://stackoverflow.com/questions/4042434/convert-arraylist-containing-strings-to-an-array-of-strings-in-java

What’s the simplest way to print an array?

In Java 5 Arrays.toString(arr) or Arrays.deepToString(arr) for arrays within arrays. and add Note that Object[] version calls .toString() of each object in array. If my memory serves me correct, the output is even decorated in the exact way you’re asking.

Edit: Don’t forget to add import java.util.Arrays; like this:

package packageName;
import java.util.Arrays;
...

http://stackoverflow.com/questions/409784/whats-the-simplest-way-to-print-an-array