(2)ÔÚÀàÎļþÖÐÓÃannotationsÀ´Ã÷È·×é¼þ
@Component(parameters = {\private PageLink theLink;
@Component(parameters = {\private TextField theTextBox;
¶þ¡¢Ò³Ãæ¼ä´«Öµ
¼Ù¶¨Òª½«Ò»¸ö×Ö´®´«¸øAnotherÒ³Ãæ£¬Another¶¨ÒåÈçÏÂ:
public class Another{
private String passedMessage;
public String getPassedMessage(){ return passedMessage; }
public void setPassedMessage(String passedMessage){ this.passedMessage = passedMessage; } }
1.¼òµ¥´«Öµ·½Ê½
@InjectPage
private Another another;
@OnEvent(value=\Object onFormSubmit(){
another.setPassedMessage(message); return another; }
ÔËÐÐÕý³££¬µ«µ±ä¯ÀÀÆ÷ÖØÐÂÇëÇóÒ³ÃæÊ±£¬´«µÝµÄÊý¾Ý½«¶ªÊ§¡£ÒòΪTapestryÒ³Ãæ³ØÔÚ¸üÐÂAnotherʵÀýʱ£¬Ëü²»ÖªµÀÄãÓÐÊý¾ÝÒª´«µ½Õâ¸öÒ³Ãæ¡£ 2.½«ÊôÐÔÓò³Ö¾Ã»¯
@Persist
private String passedMessage;
ÕâÖÖ·½Ê½×î¼òµ¥£¬Ëü½«°ÑÎÒÃÇ´«¸øpersistent propertyÖеÄÖµ£¬´æ´¢ÔÚHttpSessionÖС£ÕâÖÖ·½Ê½Óи±×÷Óã¬Ò»ÊÇ´óÁ¿Óû§Í¬Ê±·ÃÎÊʱռÄڴ棬¶þÊÇSessionµ½ÆÚʧЧ¡£ÁíÍâÿ´ÎÇëÇóÕâ¸öÒ³Ãæ£¬Tapestry¶¼»áput the value stored for it in the session into that property,no matter what instance of the page
is being used¡£
3.ʹÓÃpage activation context
ÕâÊÇTapestry5רÃŶ¨ÒåµÄÒ³Ãæ´«Öµ·½Ê½¡£Ôö¼Ó·½·¨onActivateºÍ
onPassivate£¬ËüÃǽ«ÔÚHttpÇëÇóÉúÃüÆÚÖеÄÒ»¸öÊʵ±Ê±ºò±»Tapestryµ÷Óá£
/*The onActivate method is invoked every time the page is loaded
*it might be to check whether the user who tries to access the page *was successfully authenticated */
void onActivate(String message){
System.out.println(\message);
this.passedMessage = message; }
String onPassivate(){
System.out.println(\ return passedMessage; }
ÔÚµÚÒ»¸öÒ³ÃæÊµÀý·ÅÈëµ½Ò³Ãæ³ØÖ®Ç°£¬Tapesty½«¼ì²éÒ³ÃæÊÇ·ñʹÓÃÁË
activation context£¨the activation context by implementing the pair of methods, onActivate and onPassivate£©£¬Èç¹ûÓÃÁË£¬¾Íµ÷ÓÃÒ³ÃæÊµÀýµÄ
onPassivate·½·¨¡£
Tapestry½«¼ÇסonPassivateµÄ·µ»ØÖµ£¬²¢Á¢¿ÌʹÓÃÒ³ÃæµÄÁíÒ»¸öÐÂʵÀý£¬½«¼Ç¼ÏµÄÖµ×÷Ϊ²ÎÊý´«µÝ¸øÐÂʵÀýµÄonActivate·½·¨¡£ÕâÑù¾Í´ïµ½ÁË´«ÖµÄ¿µÄ¡£ ÕâÖÖ·½Ê½²»Óý«Öµ´æÔÚSessionÖУ¬¶øÊǼǼÔÚURLÖеġ£È磺http://localhost:8080/t5first/another/hi+there!
(The message was recorded into the URL while redirecting the user's browser)
Èý¡¢Application State Object ÔÚTapestryÖУ¬Ó¦ÓóÌÐòµÄÿ¸öÒ³Ãæ¿ÉÒÔʹÓõĶÔÏó±»³ÆÎªApplication State Object (ASO)¡£Í¨³££¬ÕâЩÊÇÓÐÌØÊâʹÓÃÄ¿µÄµÄÊý¾Ý¶ÔÏó¡£¼ÙÈ綨ÒåÁËÒ»¸öUserÀࣺ
public class User{
public String getFirstName(){ return firstName; }
public void setFirstName(String firstName){ this.firstName = firstName; }
public String getLastName(){ return lastName; }
public void setLastName(String lastName){ this.lastName = lastName; } }
1.create a private field of the type User and mark it with the @ApplicationState annotation£¬ÈçÔÚµÇÂ¼Ò³Ãæ¶¨Òåºó£¬Ôڳɹ¦µÇ¼ʱдÈëÏàÓ¦µÄÈËÔ±ÐÅÏ¢¡£
@ApplicationState private User user;
Tapestry½«ÔÚµÚÒ»´ÎÇëÇóASOʱ£¬´´½¨´ËASOµÄʵÀý¡£Ò²¾ÍÊÇ˵ÎÞÂÛʲôʱºòÇëÇóASO£¬Ëû½«Ò»Ö±´æÔÚ£¬²»Îª¿Õ¡£ ĬÈÏÇé¿öÏ£¬Application State Objects ´æ´¢ÔÚSessionÖС£Õâ¾ÍÒâζ×Å£¬Èç¹ûsession»¹²»´æÔÚ£¬ÄÇôµ±µÚÒ»´ÎÇëÇóASOʱ£¬Ëü²Å»á±»´´½¨¡£ 2.ÔÚÒ³ÃæÖÐʹÓÃ
¸÷¸öÒ³Ãæ¿ÉÒÔ¶¨Ò岻ͬµÄprivateÓò£¬ËüÃǶ¼Ö¸Ïòͬһ¸öApplication State Object¡£
@ApplicationState
private User currentUser;
public User getCurrentUser(){ return currentUser; }
The user is ${currentUser.firstName} ${currentUser.lastName}