Jmesa简单的使用demo

1.Bean


package org.jmesaweb.domain;
public class Name {
    private String firstName;
    private String lastName;
    private String nickName;
    
    public Name() {        
    }


    public Name(String firstName, String lastName, String nickName) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.nickName = nickName;
    }


    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;
    }


    public String getFullName() {
        return getFirstName() + " " + getLastName();
    }


    public String getNickName() {
        return nickName;
    }


    public void setNickName(String nickName) {
        this.nickName = nickName;
    }
}

--------------------------------------------------------------------------------------------------------
package org.jmesaweb.domain;


import java.io.Serializable;
import java.util.Date;

public class President implements Serializable {
    private int id;
    private Name name;
    private String term;
    private Date born;
    private Date died;
    private String education;
    private String career;
    private String politicalParty;
    private String selected;


    public President(int id, Name name, String term, Date born, Date died,
String education, String career, String politicalParty,
String selected) {
super();
this.id = id;
this.name = name;
this.term = term;
this.born = born;
this.died = died;
this.education = education;
this.career = career;
this.politicalParty = politicalParty;
this.selected = selected;
}


    
public President(int id, String term, Date born, Date died,
String education, String career, String politicalParty,
String selected) {
super();
this.id = id;
this.term = term;
this.born = born;
this.died = died;
this.education = education;
this.career = career;
this.politicalParty = politicalParty;
this.selected = selected;
}




public int getId() {
        return id;
    }


    public void setId(int id) {
        this.id = id;
    }


    public Name getName() {
        return name;
    }


    public void setName(Name name) {
        this.name = name;
    }


    public Date getBorn() {
        return born;
    }


    public void setBorn(Date born) {
        this.born = born;
    }


    public String getCareer() {
        return career;
    }


    public void setCareer(String career) {
        this.career = career;
    }


    public Date getDied() {
        return died;
    }


    public void setDied(Date died) {
        this.died = died;
    }


    public String getEducation() {
        return education;
    }


    public void setEducation(String education) {
        this.education = education;
    }


    public String getPoliticalParty() {
        return politicalParty;
    }


    public void setPoliticalParty(String politicalParty) {
        this.politicalParty = politicalParty;
    }


    public String getTerm() {
        return term;
    }


    public void setTerm(String term) {
        this.term = term;
    }
    
    public String getSelected() {
        return selected;
    }


    public void setSelected(String selected) {
        this.selected = selected;
    }
}


2.Action

package com.base;


import static org.jmesa.facade.TableFacadeFactory.createTableFacade;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;


import static org.jmesa.limit.ExportType.CSV;
import static org.jmesa.limit.ExportType.JEXCEL;
import static org.jmesa.limit.ExportType.PDFP;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.jmesa.core.filter.DateFilterMatcher;
import org.jmesa.core.filter.MatcherKey;
import org.jmesa.facade.TableFacade;
import org.jmesa.limit.Limit;
import org.jmesa.view.component.Column;
import org.jmesa.view.component.Row;
import org.jmesa.view.component.Table;
import org.jmesa.view.editor.CellEditor;
import org.jmesa.view.editor.DateCellEditor;
import org.jmesa.view.html.HtmlBuilder;
import org.jmesa.view.html.component.HtmlColumn;
import org.jmesa.view.html.component.HtmlRow;
import org.jmesa.view.html.component.HtmlTable;
import org.jmesa.view.html.editor.DroplistFilterEditor;
import org.jmesa.view.html.editor.HtmlCellEditor;
import org.jmesaweb.domain.Name;
import org.jmesaweb.domain.President;
import org.slf4j.LoggerFactory;


public class FirstJsAction extends DispatchAction {

public ActionForward execute(ActionMapping mapping, ActionForm arg1,
HttpServletRequest request, HttpServletResponse response) throws Exception {
Name name = new Name("firstName", "lastName", "nickName");
President president = null;
List items = new ArrayList();
for(int i=0;i<25;i++) {
president = new President(1, "term"+i, new Date(), new Date(), "education", "career", "politicalPart"," selected");
items.add(president);
}
String id = request.getParameter("id");
id = "base";

TableFacade tableFacade = createTableFacade(id, request);
        System.out.println("id = "+id);
        tableFacade.setItems(items); // set the items
        tableFacade.setExportTypes(response, CSV, JEXCEL, PDFP); // set the exports allowed
        tableFacade.setStateAttr("restore"); // return to the table in the same state that the user left it.
        
        Limit limit = tableFacade.getLimit();
        if (limit.isExported()) {
            export(tableFacade);
            return null; // In Spring returning null tells the controller not to do anything.
        }
        
        String html = getHtml(tableFacade);
        request.setAttribute("presidents", html); // Set the Html in the request for the JSP
return mapping.findForward("success");
}
private String getHtml(TableFacade tableFacade) {
        // add a custom filter matcher to be the same pattern as the cell editor used.
        tableFacade.addFilterMatcher(new MatcherKey(Date.class, "born"), new DateFilterMatcher("MM/yyyy"));


        // set the column properties
        tableFacade.setColumnProperties("education", "selected", "term", "career", "born");
        
        HtmlTable table = (HtmlTable) tableFacade.getTable();
        table.setCaption("我的第一个jmesa");
        table.getTableRenderer().setWidth("1000px");


        HtmlRow row = table.getRow();


        HtmlColumn firstName = row.getColumn("education");
        firstName.setTitle("First Name");


        HtmlColumn lastName = row.getColumn("selected");
        lastName.setTitle("Last Name");


        HtmlColumn career = row.getColumn("career");
        career.getFilterRenderer().setFilterEditor(new DroplistFilterEditor());
        career.setTitle("career");


        Column born = row.getColumn("born");
        born.getCellRenderer().setCellEditor(new DateCellEditor("MM/yyyy"));


        // Using an anonymous class to implement a custom editor.
        firstName.getCellRenderer().setCellEditor(new CellEditor() {
            public Object getValue(Object item, String property, int rowcount) {
                Object value = new HtmlCellEditor().getValue(item, property, rowcount);
                HtmlBuilder html = new HtmlBuilder();
                html.a().href().quote().append("http://www.baidu.com/").quote().close();
                html.append(value);
                html.aEnd();
                return html.toString();
            }
        });


        return tableFacade.render(); // Return the Html.
    }


    private void export(TableFacade tableFacade) {
        // set the column properties
        tableFacade.setColumnProperties("name.firstName", "name.lastName", "term", "career");


        Table table = tableFacade.getTable();
        table.setCaption("Presidents");//设置标题


        Row row = table.getRow();//获得表行


        Column firstName = row.getColumn("name.firstName");
        firstName.setTitle("First Name");


        Column lastName = row.getColumn("name.lastName");
        lastName.setTitle("Last Name");


        tableFacade.render(); // Will write the export data out to the response.
    }
}


3.Jsp

<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<link rel="stylesheet" type="text/css" href="/TestJmesa/css/web.css"></link>
<link rel="stylesheet" type="text/css" href="/TestJmesa/css/jmesa.css"></link>
<script type="text/javascript" src="/TestJmesa/js/jquery-1.3.min.js"></script>
<script type="text/javascript" src="/TestJmesa/js/jquery.bgiframe.pack.js"></script>
<script type="text/javascript" src="/TestJmesa/js/jquery.jmesa.js"></script>
<script type="text/javascript" src="/TestJmesa/js/jmesa.js"></script>


<title>Insert title here</title>
</head>
<body>
test!
   <form name="presidentsForm" action="first.do">
    <div align="center">
            ${presidents}
        </div>    
            kankan
        </form>
        
        <p class="content">
            This example source code can be found 
            <a href="http://code.google.com/p/jmesa/wiki/FacadeExample">here</a>.
        </p>
        <script type="text/javascript">
            function onInvokeAction(id) {
                alert("id"+id);
                $.jmesa.setExportToLimit(id, '');
                $.jmesa.createHiddenInputFieldsForLimitAndSubmit(id);
            }
            function onInvokeExportAction(id) {
                var parameterString = $.jmesa.createParameterStringForLimit(id);
                location.href = '${pageContext.request.contextPath}/first.do?' + parameterString;
            }
        </script>
</body>
</html>


<html>
    
    <head>
        <title>JMesa Example</title>
    </head>
    
    <body>
        
        <p class="content">
            JMesa using the Limit to only retrieve the current rows needed. Also using AJAX to avoid a full page refresh. 
        </p>
        
        <p class="content">
            Other examples:<br/>
            <a href="${pageContext.request.contextPath}/basic.run?restore=true">Basic</a> <br/>
            <a href="${pageContext.request.contextPath}/groovy.run?restore=true">Groovy</a><br/>
            <a href="${pageContext.request.contextPath}/tag.run?restore=true">Tag</a><br/>
            <a href="${pageContext.request.contextPath}/worksheet.run">Worksheet</a><br/>
        </p>
        
        <form name="presidentsForm">
            <div id="presidents">
                ${presidents}
            </div>
        </form>
        
        <p class="content">
            This example source code can be found 
            <a href="http://code.google.com/p/jmesa/wiki/FacadeLimitExample">here</a>.
        </p>
        
        <script type="text/javascript">
            function onInvokeAction(id) {
                $.jmesa.setExportToLimit(id, '');


                var parameterString = $.jmesa.createParameterStringForLimit(id);
                $.get('${pageContext.request.contextPath}/limit.run?ajax=true&' + parameterString, function(data) {
                $("#presidents").html(data)
            });
        }


        function onInvokeExportAction(id) {
            var parameterString = $.jmesa.createParameterStringForLimit(id);
            location.href = '${pageContext.request.contextPath}/limit.run?ajax=false&' + parameterString;
        }
        </script>
        
    </body>
    
</html>


4.jmesa.properties

html.toolbar.maxRowsDroplist.increments=12,24,36
limit.rowSelect.maxRows=12


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是SonarQube的简单使用demo: 1. 安装SonarQube 首先,你需要下载并安装SonarQube服务器。你可以从SonarQube的官方网站下载最新版本的SonarQube。安装完成后,启动SonarQube服务器。 2. 安装SonarScanner 接下来,你需要下载并安装SonarScanner。SonarScanner是一个命令行工具,用于将代码分析结果发送到SonarQube服务器。你可以从SonarQube的官方网站下载最新版本的SonarScanner。 3. 配置SonarQube服务器 在SonarQube服务器上,你需要创建一个项目,并且为该项目配置相应的代码分析规则。在SonarQube的Web界面中,你可以通过“Administration”菜单来创建项目,并且在“Quality Profiles”中配置代码分析规则。 4. 分析代码 在你的代码库中,创建一个名为sonar-project.properties的文件,该文件包含了SonarQube分析所需的参数。其中一些参数包括: - sonar.projectKey:项目的唯一标识符。 - sonar.projectName:项目的名称。 - sonar.projectVersion:项目的版本。 - sonar.sources:指定要分析的源代码目录。 - sonar.java.binaries:指定编译后的二进制文件目录。 在命令行中运行SonarScanner: ``` sonar-scanner ``` 5. 查看分析结果 分析完成后,你可以在SonarQube的Web界面中查看分析结果。你可以查看代码的质量指标、发现的问题及其严重程度、代码覆盖率等信息。 以上就是SonarQube的简单使用demo,希望能够帮助到你。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值