Apache Tapestry PageActivationContext tutorial
The idea behind this annotation is nice and very simple. It's all about telling tapestry how to hypothetically convert a string to an object of your choice. This string is actually a key used to look up a desired object.
Now to do that you need to provide tapestry with your value encoder implementation then go ahead and use the @PageActivationContext annotation.
First create a value encoder service :
package com.skycomm.cth.services.encoders;
import org.apache.tapestry5.ValueEncoder;
import org.apache.tapestry5.services.ValueEncoderFactory;
import com.jarmy.beans.UserInfo;
import com.jarmy.services.dao.UserDAO;
public class UserInfoEncoder implements ValueEncoder, ValueEncoderFactory {
private final UserDAO userDao;
public UserInfoEncoder(UserDAO userDao) {
this.userDao = userDao;
}
@Override
public ValueEncodercreate(Class paramClass) {
return this;
}
@Override
public String toClient(UserInfo paramV) {
return paramV.getId();
}
@Override
public UserInfo toValue(String paramString) {
return userDao.getById(paramString);
}
}
Then within your page java class:
@PageActivationContextRemeber, you should not create an onActivate() method (not sure about the onPassivate() method, I think you can't create that one too), as Tapestry will attempt to create it but will throw an exception if it find it already implemented !
private UserInfo user;
Now go ahead and use your object presented to you on a silver platter :D
Is this framework UNBELIEVABLE or what ?!
Please, if you have any improvement to my post, questions, recommendations...fire away :)
Comments
Post a Comment