hi

Let's consider this class :
class Container {
        String string = "foo";

        List<String> strings = Arrays.asList(new String[]{"test"});
    }

This would work:
new PropertyModel<String>(container, ".string").getObject()
=> returns "foo"

but this doesn't:
new PropertyModel<String>(container, ".strings[0]").getObject()
it fails with
org.apache.wicket.WicketRuntimeException: no get method defined for class: 
class org.demo.PropertyModelTest$Container expression: strings

Similarly, this doesn't work:
new PropertyModel<Container>(container, ".").getObject()
exception is :java.lang.StringIndexOutOfBoundsException: String index out of 
range: 0


In the end, should the dot being allowed for self reference ? It's already used 
as the property separator, so it would be quite misleading.

I've attached some proper junit test for these points.

++
joseph
package org.demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import junit.framework.TestCase;

import org.apache.wicket.model.PropertyModel;

public class PropertyModelTest extends TestCase {

	static class Container {
		String string = "test";

		List<String> strings = Arrays.asList(new String[]{"test"});
	}

	public void testDotNavigationOnSelf() throws Exception {
		Container container = new Container();
		assertEquals(container, new PropertyModel<Container>(container, ".")
				.getObject());
	}

	public void testDotNavigationOnNonCollection() throws Exception {
		Container container = new Container();
		String test = "foo";
		container.string = test;
		assertEquals(test, new PropertyModel<String>(container, ".string")
				.getObject());
	}
	
	public void testDotNavigationOnCollection() throws Exception {
		Container container = new Container();
		container.strings = new ArrayList<String>();
		String test = "foo";
		container.strings.add(test);
		assertEquals(test, new PropertyModel<String>(container, ".strings[0]")
				.getObject());
	}
	
	public void testNavigationOnCollection() throws Exception {
		Container container = new Container();
		container.strings = new ArrayList<String>();
		String test = "test";
		container.strings.add(test);
		assertEquals(test, new PropertyModel<String>(container, "strings[0]")
				.getObject());
	}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to