Defining page property in definition file versus using implemented methods
--------------------------------------------------------------------------
Key: TAPESTRY-792
URL: http://issues.apache.org/jira/browse/TAPESTRY-792
Project: Tapestry
Type: Improvement
Components: Framework
Versions: 4.0
Environment: Tapestry 4 beta 13, Hivemind 1.1, Apache Tomcat 4.1, Java
SDK1.4.2_08, W2000Professional SP4
Reporter: Petr Marek
When page property is declared using <property name="testName"> in page
property file and then java class for this file implements getters and setters
for the same property using concrette (not abstract) methods implementation,
Tapestry ignores this getters and setters and constructs this own methods
implementation as the getters and setters were defined using abstract methods.
Result is the implemented logic in methods is quitely overwriten and
implemented logic ignored.
Described behaviour is not a bug (I suggest), but can can lead to serious
problems, because application is not protected for instance against mistyping
or oversight when definig properties. Expecialy in largere developer teams.
Proposed solution:
1) Tapestry should at least recognise such situation and inform developer it is
overwriting implemented method. Or the abstract method shoud be required for
property or the concrette implementation should not be overriden for the
property.
2) Documentation should be much clear at this point.
Attached please find working example. Problem can be seen in property
"implementedWithDefinition". It has getters and setters implemented with
log.debug message, which is never called - result can be seen in the log
example o the end of email.
--------------------------------------------------------------------------------------------------------------------------------------------------
EXAMPLE:
TestProperties.html
------------------------
<html>
<body>
Hello, this is test of properties!
</body>
</html>
TestProperties.page
-------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE page-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 4.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd">
<page-specification class="cz.profinit.kos.web.stranky.TestProperties">
<property name="abstractWithDefinition"/>
<property name="implementedWithDefinition"/>
</page-specification>
TestProperties.java
------------------------
package cz.profinit.kos.web.stranky;
import org.apache.log4j.Logger;
import org.apache.tapestry.event.PageBeginRenderListener;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.html.BasePage;
/**
* Tests the results of calling and setting abstract and implemented properties.
*
* History:
* <br>$Log: TestProperties.java,v $
* <br>
*
* @author $Author: pmarek $
* @version $Revision: 1.0 $
*/
public abstract class TestProperties extends BasePage implements
PageBeginRenderListener {
private static Logger log =
Logger.getLogger(TestProperties.class.getName());
/**
* Abstract property with definition in TestProperties.page using
<property tag>.
* @return
*/
public abstract String getAbstractWithDefinition();
public abstract void setAbstractWithDefinition(String
abstractWithDefinition);
/**
* Implemented property with definition in TestProperties.page using
<property tag>.
*/
private String implementedWithDefinition;
public String getImplementedWithDefinition() {
log.debug("running getImplementedWithDefinition()...");
return this.implementedWithDefinition;
}
public void setImplementedWithDefinition(String
implementedWithDefinition) {
log.debug("running setImplementedWithDefinition(...)...");
this.implementedWithDefinition = implementedWithDefinition;
}
/**
* Abstract property with NO definition in TestProperties.page.
* @return
*/
public abstract String getAbstractNoDefinition();
public abstract void setAbstractNoDefinition(String
abstractNoDefinition);
/**
* Implemented property with NO definition in TestProperties.page.
*/
private String implementedNoDefinition;
public String getImplementedNoDefinition() {
log.debug("running getImplementedNoDefinition()...");
return this.implementedNoDefinition;
}
public void setImplementedNoDefinition(String implementedNoDefinition) {
log.debug("running setImplementedNoDefinition(...)...");
this.implementedNoDefinition = implementedNoDefinition;
}
/**
* Implementation of @see PageRenderListener#pageBeginRender.
* @param pageEvent
*/
public void pageBeginRender (PageEvent pageEvent) {
log.debug("setAbstractWithDefinition("+TEST_VALUE_1+")");
this.setAbstractWithDefinition(TEST_VALUE_1);
log.debug("getAbstractWithDefinition()");
log.debug("Should be '"+TEST_VALUE_1+"'. Is
'"+this.getAbstractWithDefinition()+"'");
log.debug("setImplementedWithDefinition("+TEST_VALUE_2+")");
this.setImplementedWithDefinition(TEST_VALUE_2);
log.debug("getImplementedWithDefinition()");
log.debug("Should be '"+TEST_VALUE_2+"'. Is
'"+this.getImplementedWithDefinition()+"'");
log.debug("setAbstractNoDefinition("+TEST_VALUE_3+")");
this.setAbstractNoDefinition(TEST_VALUE_3);
log.debug("getAbstractNoDefinition()");
log.debug("Should be '"+TEST_VALUE_3+"'. Is
'"+this.getAbstractNoDefinition()+"'");
log.debug("setImplementedNoDefinition("+TEST_VALUE_4+")");
this.setImplementedNoDefinition(TEST_VALUE_4);
log.debug("getImplementedNoDefinition()");
log.debug("Should be '"+TEST_VALUE_4+"'. Is
'"+this.getImplementedNoDefinition()+"'");
}
private static final String TEST_VALUE_1 = "test value 1";
private static final String TEST_VALUE_2 = "test value 2";
private static final String TEST_VALUE_3 = "test value 3";
private static final String TEST_VALUE_4 = "test value 4";
}
Here is log listing after page TestProperties constructed:
---------------------------------------------------------------------
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
setAbstractWithDefinition(test value 1)
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
getAbstractWithDefinition()
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
Should be 'test value 1'. Is 'test value 1'
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
setImplementedWithDefinition(test value 2)
*** here is not "running setImplementedWithDefinition(...)..." printed -
Tapestry created its own implementation
*** here is not "running getImplementedWithDefinition()..." printed -
Tapestry created its own implementation
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
getImplementedWithDefinition()
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
Should be 'test value 2'. Is 'test value 2'
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
setAbstractNoDefinition(test value 3)
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
getAbstractNoDefinition()
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
Should be 'test value 3'. Is 'test value 3'
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
setImplementedNoDefinition(test value 4)
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
running setImplementedNoDefinition(...)...
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
getImplementedNoDefinition()
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
running getImplementedNoDefinition()...
2005-12-05 12:01:28,587 DEBUG cz.profinit.kos.web.stranky.TestProperties -
Should be 'test value 4'. Is 'test value 4'
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]