[
https://issues.apache.org/jira/browse/TAPESTRY-1972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12550405
]
Geoff Callender commented on TAPESTRY-1972:
-------------------------------------------
Here's a fuller example. As it stands it demonstrates option (a). To try
option (b) just un-comment _note and its getters and setters in the java and
the one line in the template. To try option (c) just change @Persist("client")
to @Persist.
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<t:form t:id="form">
To cause a server-side validation error, type Joe into first name.<br/>
<t:errors /><br/>
Salutation: <select t:id="salutation" t:type="Select"
value="dude.salutation" model="salutations"/> ... ${dude.salutation}<br/>
First Name: <input t:id="firstName" t:type="TextField"
value="dude.firstName" size="20" validate="required,maxLength=20" /> ...
${dude.firstName}<br/>
Last Name: <input t:id="lastName" t:type="TextField"
value="dude.lastName" size="20" validate="required,maxLength=20" /> ...
${dude.lastName}<br/>
Expiry Date: <input t:id="expiryDate" t:type="DateField"
value="dude.expiryDate" format="${dateFieldFormat}"/> ...
${dude.expiryDate}<br/>
Active: <input t:id="active" t:type="checkbox" value="dude.active"/>
... ${dude.active}<br/>
<!--
Note: <input t:id="note" t:type="TextField" value="note" size="20"
validate="required,maxLength=20" /> ... ${note}<br/>
-->
<br/>
<input type="submit" value="Save" class="positive"/><br/>
<t:pagelink page="Start">To Start</t:pagelink>
</t:form>
</html>
package xyz.pages;
import java.util.Date;
import xyz.entity.Dude;
import org.apache.tapestry.annotations.Component;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.corelib.components.Form;
public class DudeEdit {
@Persist("client")
private Dude _dude;
// @Persist("client")
// private String _note;
@Component(id = "form")
private Form _form;
void setupRender() {
if (!_form.getHasErrors()) {
_dude = new Dude("Mr", "John", "Citizen", true, new
Date());
}
}
void onValidate() {
// Imitate an error
if (_dude.getFirstName().equals("Joe")) {
_form.recordError("First name cannot be Joe.");
return;
}
}
String onSuccess() {
return "Start";
}
void cleanupRender() {
_form.clearErrors();
}
public String[] getSalutations() {
return Dude.SALUTATIONS;
}
public String getDateFieldFormat() {
return "%d/%m/%Y";
}
public Dude getDude() {
return _dude;
}
public void setDude(Dude dude) {
_dude = dude;
}
// public String getNote() {
// return _note;
// }
//
// public void setNote(String note) {
// _note = note;
// }
}
package xyz.entity;
import java.io.Serializable;
import java.util.Date;
@SuppressWarnings("serial")
public class Dude implements Serializable {
static public final String[] SALUTATIONS = { "", "Ms", "Mrs", "Mr",
"Dr", "Prof" };
private String _salutation;
private String _firstName;
private String _lastName;
private boolean _active;
private Date _expiryDate;
public Dude() {
}
public Dude(String salutation, String firstName, String lastName,
boolean active, Date expiryDate) {
_salutation = salutation;
_firstName = firstName;
_lastName = lastName;
_active = active;
_expiryDate = expiryDate;
}
public String getFirstName() {
return _firstName;
}
public void setFirstName(String firstName) {
_firstName = firstName;
}
public String getLastName() {
return _lastName;
}
public void setLastName(String lastName) {
_lastName = lastName;
}
public boolean isActive() {
return _active;
}
public void setActive(boolean active) {
_active = active;
}
public String getSalutation() {
return _salutation;
}
public void setSalutation(String salutation) {
_salutation = salutation;
}
public Date getExpiryDate() {
return _expiryDate;
}
public void setExpiryDate(Date expiryDate) {
_expiryDate = expiryDate;
}
}
> Client persistence bug - user typing lost
> -----------------------------------------
>
> Key: TAPESTRY-1972
> URL: https://issues.apache.org/jira/browse/TAPESTRY-1972
> Project: Tapestry
> Issue Type: Bug
> Components: tapestry-core
> Affects Versions: 5.0.6
> Environment: Safari, OS X, JBoss 4.2.1
> Reporter: Geoff Callender
>
> The user loses the changes they typed into an "input" or "edit" page if an
> error is recorded by onSuccess() AND the page is dealing with a client
> persisted object. The page is redisplayed OK, with error, but with the
> previous values!!!
> The user's changes aren't lost if
> (a) I move the work that finds the error from onSuccess() into onValidate() -
> this fixes all TextField components but does not fix Select, DateField,
> checkbox, or expansions; or
> (b) I add a simple client-persisted field to the page - remarkably this
> fixes; or
> (c) I replace client persistence with session persistence.
> To illustrate the problem, it's just like the example from
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/validation.html,
> which contains these excerpts:
> @Persist
> private String _userName;
> private String _password;
> String onSuccess()
> {
> if (!_authenticator.isValid(_userName, _password))
> {
> _form.recordError(_passwordField, "Invalid user name or
> password.");
> return null;
> }
> return "PostLogin";
> }
> except that instead of a single field, _userName, I am persisting a whole
> object, _user:
> @Persist("client")
> private User _user;
> and in the template we refer to its fields, eg:
> <input t:type="TextField" t:id="firstName"
> value="user.firstName" ...
> If the user types a value into firstName, but the onSuccess() method records
> an error, then the user loses what they typed.
> However, if I add another field to the page then everything works!
> @Persist("client")
> private String _aField;
> <input t:type="TextField" t:id="aField" value="aField" ...
> Alternatively, it works if I do either of the other 2 things - use session
> persistence or move all logic into onValidate().
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]