On Mon, 29. Jun 2009, Stephan Windmüller wrote:
> The site is used to assign users to jobs. Each job has a java.util.List
> of users assigned to it. Of course a user should not be assigned twice
> to a job.
To clarify this I modified the example from
http://wiki.apache.org/tapestry/Tapestry5HowtoSelectWithObjects-----
SelectTest.java
package de.ls5.ocs.webclient.tapestry.pages;
import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.services.PropertyAccess;
import de.ls5.ocs.backend.ConferenceController;
import de.ls5.ocs.backend.User;
import de.ls5.ocs.webclient.tapestry.services.GenericSelectModel;
import de.ls5.ocs.webclient.tapestry.util.ASO;
public class SelectTest {
@Persist
private List<User> assignments;
@Inject
private PropertyAccess _access;
@Persist
@Property
private User selectedUser;
@Inject
private ConferenceController conferenceController;
private GenericSelectModel<User> selectableUsers;
void onActivate() {
System.out.println("OnActivate");
if (assignments == null) {
User emptyUSer = new User("None", "Undecided", "none");
System.out.println("Filling List");
assignments = new ArrayList<User>();
assignments.add(emptyUSer);
assignments.add(emptyUSer);
assignments.add(emptyUSer);
} else {
System.out.println("List was already filled with " + assignments.size() + " elements.");
}
// Getting NullPointerException if this is missing. Why?
if (selectedUser == null) {
System.out.println("Setting selectedUser");
selectedUser = new User("bla");
}
}
public SelectTest(){
selectableUsers = new GenericSelectModel<User>(DAO.getAllUsers(),User.class,"fullName","id",_access);
}
public List<User> getAssignments(){
return assignments;
}
public void setAssignments(List<User> assignments){
this.assignments = assignments;
}
public GenericSelectModel<User> getSelectableUsers(){
return selectableUsers;
}
}
SelectTest.tml
<html xmlns:t="
http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Select test</title>
</head>
<body style="font-family:Courier new">
<form t:type="Form">
<table>
<tr t:type="loop" t:source="assignments" t:encoder="selectableUsers" t:value="selectedUser">
<td>
<t:select model="selectableUsers" encoder="selectableUsers" value="selectedUser"/>
</td>
</tr>
</table>
<t:submit/>
</form>
value: ${assignments}
</body>
</html>
-----
As long as I do not use a List to store the objects, all works fine. But
when I submit the form above, it always resets and the list consists of
"undecided" users.
Regards
Stephan