Jon Baxter

Greenhorn
+ Follow
since Dec 03, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jon Baxter

I have a text box where the client can enter a $ amount. Whats the industry standard for text entry in these fields, does one allow specifying
characters such as "$" and ",".

I mean is the industry standard to entry either a,b,c below in a text box for a $ amount.

a) 10000.45
b) 10,000.45
c) $10,000.45

For b,c the server side would have to have extra logic for removing $ and , for
18 years ago
JSP
In the manifest.mf file of a jar file. There is a Class-Path attribute.
Is it mandatory to enumerate each and every jar in the value of the Class-Path attribute. I cannot do a

Class-Path: mylib/*.jar
but have to instead

Class-Path: mylib/1.jar mylib/2.jar mylib/3.jar and so on..

This is tedious. Is there an ant task that will generate the classpath
attribute?
18 years ago
Since JSF builds the view of the page, wires event handlers and validators to components in the view, and saves the view in the FacesContext instance
during the restore view phase, how does it handle view components dynamically added on the view using JS/DHTML. i.e.,

if I have a page where I add/delete rows to a table using DHTML/JS (in order to avoid a server trip) would those modified rows be registered in
the JSF view tree?
19 years ago
JSF
I know JSTL has been pushed around to reduce scriptlet code in JSPs.
But can JSTL variables be used in Javascript method calls. For example

19 years ago
JSP
Modified the Bean class to maintain the order in a TreeMap.


public class Bean {

private TreeMap _items = new TreeMap();

public ArrayList getItems() {
ArrayList l = new ArrayList();
for (Iterator ii = _items.entrySet().iterator(); ii.hasNext() {
l.add(ii.next());
}
return l;
}

public void setItems(ArrayList items) {
for (int i = 0; i < items.size(); ++i) {
_items.put(new Integer(i), items.get(i));
}
}

public Item getItem(int index) {
System.out.println("Getter called " + index);

Integer ii = new Integer(index);
if (!_items.containsKey(ii)) {
_items.put(new Integer(index), new Item());
}
return (Item) _items.get(ii);
}


public String toString() {
return _items.toString();
}

}

This looks like it fixed it.
19 years ago
It looks like the problem is deep within BeanUtils.populate(..) method which
is what is called ultimately for mapping request parameters to bean properties.

The BeanUtils.populate(..) method is called in the processPopulate() method
of the RequestProcessor class (See Struts src) and well before the execute(..) method of the action is called. This populate method is what calls your indexed getter/setter on your form.


Yes, the order of the parameters submitted is random, and this random order
throws off BeanUtils.populate(..). To illustrate..


<pre>

public class BeanUtilTest extends TestCase {

private int INPUT_NUM = 10;
public void testPopulateMethod() {

HashMap p = new HashMap();

for (int i = 0; i < INPUT_NUM; ++i) {
String key = "item[" + i + "].test";
String[] val = new String[] { String.valueOf(i) };
p.put(key, val);
}

System.out.println(p);

Bean bean = new Bean();
try {
BeanUtils.populate(bean, p);
} catch (Exception e) {
e.printStackTrace();
}

System.out.println(bean);
}

}


public class Bean {

private ArrayList items = new ArrayList();

public ArrayList getItems() {
return items;
}

public void setItems(ArrayList items) {
this.items = items;
}

public Item getItem(int index) {
if (index >= items.size()) {
Object o = new Item();
items.add(o);
return (Item)o;
}
return (Item) items.get(index);
}

public void setItem(int index, Object o) {
items.add(o);
}

public String toString() {
return items.toString();
}


public class Item {

private String test;

public Object getTest() {
return test;
}
public void setTest(Object test) {
this.test = (String)test;
}

public String toString() { return test; }
}

</pre>

When you run this the result is..[0, 1, 2, 7, 4, 5].

When you convert HashMap p = new HashMap() to

LinkedHashMap p = new LinkedHashMap() to

the result is..[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] (as you would expect).

The thing is the Apache code uses java.util.HashMap for storing the request parameters.

At this point.. the behaviour of BeanUtils.populate(..) is erratic. I don't
see how modifying the indexed getter/setters in your form is going to make
any difference.

List based indexed properties in Struts are broken period.!
19 years ago
<logic:iterate name="multiForm" id="foo" property="keys" indexId="index" >
<tr><td>
<html:text name="multiForm" property='<%="keysIndexed["+index+"]"%>' />
</td></tr>
</logic:iterate>


public class MultiFieldForm extends ValidatorForm {

private List keys = new ArrayList();

public List getKeys() {
return keys;
}
public void setKeys(List keys) {
this.keys = keys;
}
public String getKeysIndexed(int index) {
return (String) keys.get(index);
}

public void setKeysIndexed(int index, String value) {
keys.add(index,value);
}
}


The above code throws an ArrayIndexOutofBoundException after 3 entries
19 years ago
Struts does not support "id" attribute on the html element tags?

Is this true?
19 years ago
I have my build file generating the struts-config.xml file just fine (it even does the merging). However the XDoclet creates an empty validation.xml
file.

Snippet...

<webdoclet destdir="${project.build}/WEB-INF"
force="true"
mergedir="${project.java.conf}/struts/merge">
<fileset dir="${project.java.src}"> <include name="**/*.java"/> </fileset>

<strutsconfigxml validatexml="true"
version="1.1"
mergedir="${project.java.conf}/struts/merge"
/>

<strutsvalidationxml />
</webdoclet>


Java code..

/**
* @struts.form name="testForm"
*/
public class TestForm extends ValidatorForm {

private String lastName = "Bond";

public String getLastName() {
return (this.lastName);
}
/**
* @struts.validator type= "required" msgkey="error.required" arg0value="Last name"
*
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}

}
19 years ago