How can I debug tapestry? To debug JSP, you do not need to restart the server. And tapestry
Whether the template or page is modified, restart the server. What does anybody know?
?
Set reloadable to true when setting context.
When you change the page and HTML, recompile a class file so that when you access the file again, tapestry will reaload resouce
Set a JVM parameter for Tomcat eclipse Plugin:
-Dorg. Apache. tapestry. Disable-caching = true
1. There is no getvisit for component, while the inconsistency of page is:
In the page, obtain visit/Global as getvisit ()/getglobal ()
However, this function does not exist in component.
Getpage (). getvisit ()/getpage. getglobal ()
Why is there such inconsistency? I often have
When you extract component from page, you need to modify the code,
Write a component extends basecomponent.
Yes
Getvisit calls getpage. getvisit ()
Getglobal calls getpage. getglobal ()
This is much more convenient.
2. Do you want to write abstract get/set for attributes?
I prefer to write an instance field, and then use Alt + insert to directly
It is much easier to generate the get/set method than to manually write abstract get/set methods.
3. About the debugging page
Sometimes some things displayed in the HTML template are not normal, for example
Dongdong is called condtion.
I'm used to using the @ insert control, and then I typed something in front of it,
In the case of disable cache, you only need to refresh it.
It is very convenient to delete it again.
In addition, in the debugging status, I used to write @ insert value = "ognl: page" at the bottom of border to display the class corresponding to the current page,
Easy debugging. Because the URL of the tapestry's cycle forward method is often unchanged,
I don't know which class the current page corresponds. Then on the border
Write a small form and directly submit the page to be accessed, which is also convenient for debugging.
All of the above are tips in tapestry. What else do you have,
We can discuss it together.
Tapestry 4.0 Study Notes V1
Tapestry
Page Object
Declaring attributes in the page file does not have to be declared in the Java file and Its get and set methods
T4 uses the XXX in the getxxx () abstract method as the page attribute by default. The. Page does not need to be declared, and @ initialvalue ("value") is used to assign the initial value.
The page object instance will be cached (with potential illegal access problems). solution:
Override the initialize () method and initialize the instance variables. (Initialize () is called every day when it is placed in the cache pool ())
Declare instance variables in. Page,. Java declare get/Set Method (optional), T4 automatically generates code Initialization
Implement the pagebeginrenderlistener interface to initialize parameters before page render to prevent null pointer exceptions.
Development and debugging
Disable cache Parameters
-Dorg. Apache. tapestry. Disable-caching = true-dorg. Apache. tapestry. Enable-reset-service = true
Debugging Parameters
Set java_opts = "-dorg. Apache. tapestry. Disable-caching = true" set jpda_address = 8000 set jpda_transport = dt_socket Catalina JPDA start
Activate () does not go to the page immediately. It only saves the Page Object reference in irequestcycle. After the listener execution is completed, the job will be transferred.
Get Page Object
. Page does not require any declaration.. Java provides abstract methods and metadata.
Inject page attribute in. Page,. Java provides Abstract METHODS
Metadata inject pages and attributes can be used without being declared in. Page.
Obtain the page using @ injectpage ("pagename ")
If the class contains an unimplemented "getxxx" method in T4, an instance variable XXX is generated by default. There is no initialization method for this instance variable. You can resolve it in the getxxx () Declaration @ initialvalue ("literal: initvalue ")
Form Verification
Delegate
Solution 1: A New validationdelegate is required to print the error message.
Solution 2: configure the <bean> label in the. page file
Solution 3: <bean> is not configured in. Page, and metadata @ bean is used in the abstract method.
Validators
In the. page file, each form Element component to be verified is bound to a validators
Expression: validators: + judgment condition + [error prompt]
Null Input
T4 can be verified by default if it is null
[Value = "validators: required"] ensures that the input is not empty.
Fieldlable can be bound with textfield to Display error messages
Client Verification
Bind <binding name = "clientvalidationenabled" value = "true"/> to the form component.
If the form input is correct, the logic verification should be performed in the listener method.
For example, if the inventory of apple is only 20 and the user buys 50, this is illegal.
Record error information to validationdelegate during verification
Create delegate
Delegate. setformcomponent (iformcomponent) getcomponent ("XXX "));
Delegate. recordfieldinputvalue (integer. tostring (XXXX ));
Delegate. Record ("XXX must be> = 0", validationconstraint. too_small );
Each page object contains a map to save the bean. (If no one is available, the bean is automatically destroyed when the page pool is returned.) to obtain a defined bean in. Page, use the beans prefix for calling. For example, Beans. beanid. beanproperty.
When using for and foreach, you must declare <source> elements in the collection object <property> in. Page. To facilitate T4 generation of get and set methods.
Component Reuse
In t4, a group cannot be used twice, that is, a consumer CIDR cannot appear repeatedly in. html.
Solution: Rename the component. <Compoment id = "RENAME" copy-of = "name">
"Class @ xxx" indicates the xxx static method or static variable used to access a class.
Determine whether the button is clicked.
Use a form component for each button
Add a "tag" for each button and determine the which button by TAG value to be clicked
Add a listener for each button (simple, object-oriented, recommended)
Principles of submit submission
How to obtain parameters in the listener Method
1. Parameters of the listener method implemented by irequestcycle
2. Declare the listening method with the correct parameter order. T4 automatic boxing
* Public type method (parameters)
* Public type method (irequestcycle cycle, parameters)
* Public type method ()
* Public type method (irequestcycle cycle)
After the page is submitted, T4 will obtain or create a page object from the page pool. Therefore, the Page Object references on the same page before and after submission are different, and the instance variables may be the same and cannot be the same.
Therefore, do not define member variables in page objects (including member variables corresponding to page components), because cross-page access is always ineffective and potentially risky.
Solution to the above problem
1. Use the persistent member variables that the client persistence needs to access, declare the get and set abstract methods, and comment with @ persist ("client. When using this method, you should determine whether the get method is null, because this persistence method does not initialize variables.
2. the abstract get and set methods are implemented by T4.
Hivemind Module
The Session object can be configured in hivemodule. xml.
Hivemodule. XML is stored in the WEB-INF/classes/META-INF directory. Or under the META-INF directory of the. JAR File
Hivemodule. xml each module ID must be unique. Generally, the module package name is used as the ID
Session
Acquisition Method
1. Declare the abstract method and comment it through the metadata injectstate ("objectname ")
2. Declare the abstract method. In. Page, the <inject> Object
Method of Determining existence
Annotation
1. Declare an abstract method. The naming format of this method is getxxx () or isxxx ()
2. Use Metadata Annotation @ injectstateflag ("sessionobj ")
. Page declaration <inject type = "state-flag" property = "userexists" Object = "sessionobj"/>
Logout: Use the Restart service of the servicelink component. This service deletes sessionobj and directs it to the home page.
T4 creates an object through a constructor without Parameters
Security Processing
1. Key pages should be verified by users on the pages to prevent anonymous users from accessing them. The Page Object implements the pagevalidatelistener interface.
2. htmla-> login-> htmla Solution
This page class implements iexternalpage, which accepts parameters
Parameter maintenance
Client save parameters (recommended)
1. Use the hidden component and provide the get and set methods for this genus.
2. Metadata @ persist ("client") cannot be used to declare the abstract set and get methods.
Session save Parameters
Snippets
Default expression
Literal in. html
Ognl in. Page
Property access
Mathematical Expressions
Method invocations
Reference static fields of public classes
Create new objects, including lists and maps
SP in the URL, T3 is a service parameter, and T4 is a listener parameter.
Page Object Query
1. Declaration in. Page
2. Search for org. Apache. tapestry. Page-class-packages in. Application Declaration (recommended)
Special Page Components
1. $ remove $: Delete the HTML element (that is, remove only one element)
2. $ content $: generate only the HTML code between the element tags. Ignore and remove other elements (that is, only the content in the element tag is retained)
Internationalization
Tips in HTML
1. <span key = "hello"> Hello </span> indicates the dictionary key.
2. It must be a <span> label and the key does not have to be prefixed (such as message:, ognl :)
Different pages are named in xxx_cn.html format.
Dictionary file
1. Each page can have a poperties
2. Create $ {servletname}. properties under the WEB-INF, all pages share
Custom Components
Recommended component configuration files are most reasonable under the WEB-INF
Use of controls in contrib
<Library id = "contrib" Specification-Path = "/org/Apache/tapestry/contrib. Library"/>
Input verification
Writer. beginempty ("input") is recommended ")
Use writer. Begin ("input") and writer. End ()
Rewinding, which can be understood as refresh
Form. isrewinding ()
Cycle. isrewinding ()
Parameters
Component parameter initialization
<Parameter> set initialization in. JWC
Initialize in finishload () method
Parameter type
Formal: A component parameter defined in the component specification. Each formal parameter has a specific (case sensitive) name and is marked as required or optional.
Informa: an attribute parameter of an HTML element.
Page Configuration
Binding method
1. Static binding: Read-only. The bound value is specified in the component specification.
2. dynamic binding: When a component needs to be dynamically bound, it obtains the value through its specified JavaBean.
Disable the tapestry cache pool to improve development efficiency
Tapestry has its own Cache Policy for the page. Once the page is accessed for the first time, the page object will be loaded into the cache. Therefore, every modification to HTML, page, or Java does not take effect immediately. You must restart the server. This is inconvenient when we develop programs. Therefore, we can disable the cache policy of tapestry and enable it when the project is released.
Add:
<meta key="org.apache.tapestry.disable-caching" value="true"/><meta key="org.apache.tapestry.enable-reset-service" value="true"/>
Add:
-Dorg.apache.tapestry.disable-caching=true-Dorg.apache.tapestry.enable-reset-service=true