Jin,
I can make a couple suggestions...
> Visit visit = (Visit) getPage().getVisit();
> DataContext context = visit.getDataContext();
What I normally do in my Tapestry projects is have a wedge class that
extents BasePage. All of my page classes in the project extend it. In
there you can add a bunch of conveniences like:
public DataContext getDataContext() {
Visit visit = (Visit) getVisit();
return visit.getDataContext();
}
This way in your action code you can just call getDataContext() instead
of the two lines above.
> List persons = context.performQuery(q);
> context.commitChanges();
> return new PersonModel(persons);
There is no need to call context.commitChanges() here, you're just
running a select query, not committing anything to the db.
> Unable to resolve expression 'primaryInvestigators' for
> assr.objects.NewASSR$Enhance_4..d5534[NewASSR].
Are you using an Object of type CayenneDataObject for the property
model's value binding? If you're using a string, that won't work.
Here's a helpful class that we use for our dropdowns of DataObjects:
public class DataObjectSelectionModel implements
IPropertySelectionModel, Serializable {
protected String noSelectionLabel;
protected List dataObjects;
protected String labelKey;
public DataObjectSelectionModel() {
}
public DataObjectSelectionModel(List dataObjects, String labelKey) {
this(dataObjects, labelKey, null);
}
public DataObjectSelectionModel(
List dataObjects,
String labelKey,
String noSelectionLabel) {
this.noSelectionLabel = noSelectionLabel;
this.dataObjects = dataObjects;
this.labelKey = labelKey;
}
public int getOptionCount() {
int size = dataObjects.size();
return (noSelectionLabel != null) ? size + 1 : size;
}
public Object getOption(int index) {
if (noSelectionLabel != null) {
if (index == 0) {
return null;
}
index--;
}
return dataObjects.get(index);
}
public String getLabel(int index) {
Object obj = getOption(index);
if (obj == null) {
return noSelectionLabel;
}
return String.valueOf(
((CayenneDataObject) obj).readNestedProperty(labelKey));
}
public String getValue(int index) {
return Integer.toString(index);
}
public Object translateValue(String value) {
return getOption(Integer.parseInt(value));
}
/**
*..eturn List
*/
public Iterator getModelIterator() {
return dataObjects.iterator();
}
}
Hope that helps,
e.
On Jan 14, 2005, at 3:34 PM, Jin Lee wrote:
> Hey all,
>
> I've run into an error in Tapestry and I've narrowed it down somewhat
> and was wondering if I could get anyone's insight on how to resolve
> the problem.
>
> To start off, I have cayenne.jar, tapestry.jar, and all the
> dependencies in tomcat_home/shared/lib. Is this okay, or should it be
> in the context's path?
>
> The problem lies in Tapestry's IPropertySelection. I have this method:
>
> public IPropertySelectionModel getPrimaryInvestigators() {
> Visit visit = (Visit) getPage().getVisit();
> DataContext context = visit.getDataContext();
> SelectQuery q = new SelectQuery(Person.class);
> List persons = context.performQuery(q);
> context.commitChanges();
> return new PersonModel(persons);
> }
>
> which return this error:
>
> Unable to resolve expression 'primaryInvestigators' for
> assr.objects.NewASSR$Enhance_4..d5534[NewASSR].
>
> but when I change the body of the method to this it runs fine:
>
> public IPropertySelectionModel getPrimaryInvestigators() {
> return new
> org.apache.tapestry.form.StringPropertySelectionModel(new String[]
> {"Hi", "its", "working!"});
> }
>
>
> My PersonModel looks like this:
>
> public class PersonModel implements IPropertySelectionModel {
>
> private List persons;
>
> public PersonModel(List persons) {
> this.persons = persons;
> }
> public int getOptionCount() {
> return persons.size();
> }
> public Object getOption(int index) {
> Person person = (Person)persons.get(index);
> return person;
> }
> public String getLabel(int index) {
> Person person = (Person)persons.get(index);
> return person.getPersonLastName() + ", " +
> person.getPersonFirstName();
> }
> public String getValue(int index) {
> Person person = (Person)persons.get(index);
> return person.getObjectId().toString();
> }
> public Object translateValue(String value) {
> int i;
> for (i=0; i<persons.size(); i++) {
> Person person = (Person) persons.get(i);
> if (person.getObjectId().toString().equals(value)) {
> return person;
> }
> }
> return null;
> }
> }
>
> So since a StringPropertySelectionModel works, I'm thinking its either
> 1) I set up cayenne wrong, or 2) my implementation of PersonModel is
> just totally off.
>
> Any help would be greatly appreicated. Trying to learn both tapestry
> and cayenne at the same time so it's been quite a learning process.
>
> Thank you very much,
>
> Jin Lee
>
This archive was generated by hypermail 2.0.0 : Fri Jan 14 2005 - 15:51:33 EST