Skip to content

Instantly share code, notes, and snippets.

@lucascs
Created November 30, 2010 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascs/721689 to your computer and use it in GitHub Desktop.
Save lucascs/721689 to your computer and use it in GitHub Desktop.
@Target(ElementType.METHOD)
@Retention(RetentionType.RUNTIME)
public @interface DisplayTag {
String value();
}
@Intercepts
@Lazy
public class DisplayTagInterceptor implements Interceptor {
private MutableRequest request;
public DisplayTagInterceptor(MutableRequest request) {
this.request = request;
}
public boolean accepts(ResourceMethod method) {
return method.containsAnnotation(DisplayTag.java);
}
public void intercept(InterceptorStack stack, ResourceMethod method, Object instance)
throws InterceptionException {
String tableId = method.getMethod().getAnnotation(DisplayTag.class).value();
String sortParam = new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_SORT));
String orderParam = new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_ORDER));
String pageParam = new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_PAGE));
request.setParameter("sort", request.getParameter(sortParam));
request.setParameter("order", request.getParameter(orderParam));
request.setParameter("page", request.getParameter(pageParam));
stack.next(method, instance);
}
}
@Resource
public class YourController {
//...
@DisplayTag("myTableId")
public void list(AnyParam param, Integer sort, Integer order, Integer page) {
//....
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment