No there's definitely a lot more to it. I was just cutting it down to the
interesting parts that appeared to be the problem. In reality it looks more
like:
public class Create extends BasePage
{
@ApplicationState
private User user;
private boolean userExists;
@ApplicationState
private DBConnection dbconn;
@ApplicationState
private Object lastPage;
private boolean lastPageExists;
@InjectPage
private Redirect redirectPage;
// The following are used for form parameters
@Persist
private int numAccounts;
@Persist
private String userName;
@Persist
private String password;
@Persist
private String firstName;
@Persist
private String lastName;
@Persist
private String motd;
@Persist
private String disabledMods;
@Persist
private int difficulty;
@Persist
private boolean isActive;
@Persist
private int acctType;
@Persist
private java.util.List<Classroom> classes;
@Component(id = "userForm")
private Form form;
private ClassroomVE classVE;
private HashMap<Classroom,String> classModel;
private HashMap<String,String> activeModel;
private HashMap<String,String> acctTypeModel;
Object onActivate()
{
// If user is not logged in, send them to login page
if(!userExists)
{
lastPage = "Users/Create";
return "Login";
}
// If user is not at least a teacher, send them to main menu
if(user.getType() < UserType.TEACHER)
{
redirectPage.setMessage("You do not have permission
to access this page");
redirectPage.setRedirect("MainMenu");
return redirectPage;
}
return null;
}
/**
* This function is called before the page is rendered
*/
@SetupRender
void setupRender()
{
// Set defaults
numAccounts = 1;
userName = "TEst";
password = "booo";
firstName = "Boo";
lastName = "Big";
motd = "Hello";
disabledMods = "piaget";
difficulty = 1;
isActive = true;
acctType = 0;
classVE = new ClassroomVE(dbconn);
ClassroomFactory classFac = new ClassroomFactory(dbconn);
classModel = new HashMap<Classroom,String>();
try
{
java.util.List<Classroom> classes;
if(user.getType() >= UserType.ADMIN) classes =
classFac.getAllClassrooms();
else classes = classFac.getUserClassrooms(user);
for(Classroom tClass : classes)
{
String value = tClass.getName() + " - Per. "
+ tClass.getPeriod() + " - " + tClass.getDescription();
//value = tClass.getName() + " - Per. " +
tClass.getPeriod() + " - " + tClass.getDescription();
classModel.put(tClass, value);
}
}
catch (Exception e)
{
e.printStackTrace();
}
acctTypeModel = UserType.toMap();
// If the current user is a lower level user, remove the
ability to create higher level users
if(user.getType() < UserType.GOD)
acctTypeModel.remove(Integer.toString(UserType.GOD));
if(user.getType() < UserType.ADMIN)
acctTypeModel.remove(Integer.toString(UserType.ADMIN));
activeModel = new HashMap<String,String>();
activeModel.put("1", "Enabled");
activeModel.put("0", "Disabled");
}
/**
* This function is called upon successful completion of the form.
* The function attempts to add or modify an entry for the user
* to the database. If it cannot do so, it returns with errors.
* @return
*/
Object onSuccess()
{
...
}
/**
* @return the numAccounts
*/
public String getNumAccounts()
{
return Integer.toString(numAccounts);
}
/**
* @param numAccounts the numAccounts to set
*/
public void setNumAccounts(String numAccounts)
{
this.numAccounts = new Integer(numAccounts);
}
/**
* @return the username
*/
public String getUserName()
{
return userName;
}
/**
* @param username the username to set
*/
public void setUserName(String userName)
{
this.userName = userName;
}
/**
* @return the password
*/
public String getPassword()
{
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* @return the firstName
*/
public String getFirstName()
{
return firstName;
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
/**
* @return the lastName
*/
public String getLastName()
{
return lastName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName)
{
this.lastName = lastName;
}
/**
* @return the motd
*/
public String getMotd()
{
return motd;
}
/**
* @param motd the motd to set
*/
public void setMotd(String motd)
{
this.motd = motd;
}
/**
* @return the disabledMods
*/
public String getDisabledMods()
{
return disabledMods;
}
/**
* @param disabledMods the disabledMods to set
*/
public void setDisabledMods(String disabledMods)
{
this.disabledMods = disabledMods;
}
/**
* @return the difficulty
*/
public String getDifficulty()
{
return Integer.toString(difficulty);
}
/**
* @param difficulty the difficulty to set
*/
public void setDifficulty(String difficulty)
{
this.difficulty = new Integer(difficulty);
}
/**
* @return the isActive
*/
public String getIsActive()
{
if(isActive) return "1";
else return "0";
}
/**
* @param isActive the isActive to set
*/
public void setIsActive(String isActive)
{
if(isActive.compareTo("1") == 0) this.isActive = true;
else this.isActive = false;
}
/**
* @return the acctType
*/
public String getAcctType()
{
return Integer.toString(acctType);
}
/**
* @param acctType the acctType to set
*/
public void setAcctType(String acctType)
{
this.acctType = new Integer(acctType);
}
/**
* @return the classes
*/
public java.util.List<Classroom> getClasses()
{
return classes;
}
/**
* @param classes the classes to set
*/
public void setClasses(java.util.List<Classroom> classes)
{
this.classes = classes;
}
/**
* @return the classVE
*/
public ClassroomVE getClassVE()
{
return classVE;
}
/**
* @return the classModel
*/
public HashMap<Classroom, String> getClassModel()
{
return classModel;
}
/**
* @param classModel the classModel to set
*/
public void setClassModel(HashMap<Classroom, String> classModel)
{
this.classModel = classModel;
}
/**
* @return the activeModel
*/
public HashMap<String, String> getActiveModel()
{
return activeModel;
}
/**
* @param activeModel the activeModel to set
*/
public void setActiveModel(HashMap<String, String> activeModel)
{
this.activeModel = activeModel;
}
/**
* @return the acctTypeModel
*/
public HashMap<String, String> getAcctTypeModel()
{
return acctTypeModel;
}
/**
* @param acctTypeModel the acctTypeModel to set
*/
public void setAcctTypeModel(HashMap<String, String> acctTypeModel)
{
this.acctTypeModel = acctTypeModel;
}
}
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On Behalf Of Josh Canfield
> Sent: Wednesday, November 28, 2007 10:24 AM
> To: Tapestry users
> Subject: Re: [T5] Cannot persist field exception
>
> Is that the entire page class?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]