Details
-
Question
-
Status: Closed
-
Minor
-
Resolution: Invalid
-
5.0.18
-
None
-
None
Description
I am new to Tapestry (awesome BTW!) and not sure if this is a bug / misunderstanding / RTFM moment / or just an FYI.
But this tripped me up for awhile and makes perfect sense when I tracked it down.
If you copy or clone a object field in the get mutator to protect from unexpected mutations (which is "a good thing"), it affects Tapestry.
Given the code and page below; the page will display but seemingly "ignore" the entered value (See comments in code).
It makes sense, but not cloning the object field opens the code up to other unintended / non-beneficial mutations.
Perhaps all that is needed is to document this, or I should RTFM if it already is
Thanks - again awesome product!
===============
public class TestContainer
{
private String testValue;
public TestContainer()
{ super(); }public TestContainer(String _testValue) { setTestValue(_testValue); }
public TestContainer(TestContainer _container) { this(_container.getTestValue()); }
public String getTestValue() { return testValue; }
public void setTestValue(String _testValue) { testValue = _testValue; }
@Override public String toString() { return "TestContainer.testValue = '" + testValue + '\''; }
}
===============
public class TestWrapper
{
private TestContainer testContainer;
public TestWrapper() { super(); }
public TestWrapper(TestContainer _testContainer)
{ setTestContainer(_testContainer); }public TestWrapper(TestWrapper _testWrapper)
{ this(_testWrapper.getTestContainer()); }public TestContainer getTestContainer()
{ // This works as expected. //return testContainer; // "Cloning/Copying" causes unforseen issues. return testContainer == null ? null : new TestContainer(testContainer); }public void setTestContainer(TestContainer _testContainer)
{ // "Cloning/Copying" here doesn't matter. testContainer = _testContainer == null ? null : new TestContainer(_testContainer); }@Override public String toString()
{ return "TestWrapper.testContainer = " + testContainer; }}
===============
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.corelib.components.Form;
public class TestWrapperPage
{
@Component private Form form;
@Property @Persist private TestWrapper request;
@Persist @Property private String response;
public TestWrapperPage()
{ super(); }void onActivate()
{ if (request == null) request = new TestWrapper(new TestContainer("init")); }void onSelectedFromSendRequest()
{ response = "TestWrapperPage.testWrapper = " + request.toString(); }}
===============
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<head>
<title>Test Wrapper Page</title>
</head>
<body>
<form t:id="form">
<t:errors />
<input type="text" t:type="TextField" t:id="request" t:value="request.testContainer.testValue" /><br />
<input type="submit" t:type="submit" t:id="sendRequest" value="Send Request" /><br />
<textarea cols="80" rows="10" readonly="true" t:type="TextArea" t:id="response">
</textarea>
</form>
</body>
</html>