Java Code Examples for com.jfinal.template.stat.Scope#setGlobal()

The following examples show how to use com.jfinal.template.stat.Scope#setGlobal() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArticlePageDirective.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Controller controller = JbootControllerContext.get();

    int page = controller.getParaToInt(1, 1);
    int pageSize = getParaToInt("pageSize", scope, 10);
    String orderBy = getPara("orderBy", scope, "id desc");

    // 可以指定当前的分类ID
    Long categoryId = getParaToLong("categoryId", scope, 0L);
    ArticleCategory category = controller.getAttr("category");

    if (categoryId == 0 && category != null) {
        categoryId = category.getId();
    }

    Page<Article> articlePage = categoryId == 0
            ? service.paginateInNormal(page, pageSize, orderBy)
            : service.paginateByCategoryIdInNormal(page, pageSize, categoryId, orderBy);

    scope.setGlobal("articlePage", articlePage);
    renderBody(env, scope, writer);
}
 
Example 2
Source File: ArticleSearchPageDirective.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Controller controller = JbootControllerContext.get();

    String keyword = controller.getAttr("keyword");
    int page = controller.getAttr("page");
    int pageSize = getParaToInt("pageSize", scope, 10);

    Page<Article> dataPage = StrUtil.isNotBlank(keyword)
            ? articleService.search(keyword, page, pageSize)
            : null;

    if (dataPage != null) {
        scope.setGlobal("articlePage", dataPage);
    }

    //需要页面自行判断 articlePage 是否为空
    renderBody(env, scope, writer);
}
 
Example 3
Source File: ProductPageDirective.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Controller controller = JbootControllerContext.get();

    int page = controller.getParaToInt(1, 1);
    int pageSize = getParaToInt("pageSize", scope, 10);
    String orderBy = getPara("orderBy", scope, "id desc");

    // 可以指定当前的分类ID
    Long categoryId = getParaToLong("categoryId", scope, 0L);
    ProductCategory category = controller.getAttr("category");

    if (categoryId == 0 && category != null) {
        categoryId = category.getId();
    }

    Page<Product> productPage = categoryId == 0
            ? service.paginateInNormal(page, pageSize, orderBy)
            : service.paginateByCategoryIdInNormal(page, pageSize, categoryId, orderBy);

    scope.setGlobal("productPage", productPage);
    renderBody(env, scope, writer);
}
 
Example 4
Source File: ProductSearchPageDirective.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Controller controller = JbootControllerContext.get();

    String keyword = controller.getAttr("keyword");
    int page = controller.getAttr("page");
    int pageSize = getParaToInt("pageSize", scope, 10);

    Page<Product> dataPage = StrUtil.isNotBlank(keyword)
            ? productService.search(keyword, page, pageSize)
            : null;

    if (dataPage != null) {
        scope.setGlobal("productPage", dataPage);
    }

    //需要页面自行判断 productPage 是否为空
    renderBody(env, scope, writer);
}
 
Example 5
Source File: PageCommentPageDirective.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Controller controller = JbootControllerContext.get();

    int page = controller.getParaToInt(1, 1);
    int pageSize = getParaToInt("pageSize", scope, 10);

    SinglePage singlePage = controller.getAttr("page");
    if (singlePage != null) {
        Page<SinglePageComment> articlePage = service.paginateByPageIdInNormal(page, pageSize, singlePage.getId());
        scope.setGlobal("commentPage", articlePage);
        renderBody(env, scope, writer);
    }
}
 
Example 6
Source File: CommentPageDirective.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Controller controller = JbootControllerContext.get();

    int page = controller.getParaToInt(1, 1);
    int pageSize = getParaToInt("pageSize", scope, 10);

    Article article = controller.getAttr("article");
    if (article != null) {
        Page<ArticleComment> articlePage = service.paginateByArticleIdInNormal(page, pageSize, article.getId());
        scope.setGlobal("commentPage", articlePage);
        renderBody(env, scope, writer);
    }
}
 
Example 7
Source File: ProductCommentPageDirective.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onRender(Env env, Scope scope, Writer writer) {

    Controller controller = JbootControllerContext.get();

    int page = controller.getParaToInt(1, 1);
    int pageSize = getParaToInt("pageSize", scope, 10);

    Product product = controller.getAttr("product");
    if (product != null) {
        Page<ProductComment> articlePage = service.paginateByProductIdInNormal(page, pageSize, product.getId());
        scope.setGlobal("commentPage", articlePage);
        renderBody(env, scope, writer);
    }
}