Search in sources :

Example 1 with UrlBuilder

use of com.manydesigns.elements.servlet.UrlBuilder in project Portofino by ManyDesigns.

the class AbstractCrudAction method configureSortLinks.

protected void configureSortLinks(TableFormBuilder tableFormBuilder) {
    for (PropertyAccessor propertyAccessor : classAccessor.getProperties()) {
        String propName = propertyAccessor.getName();
        String sortDirection;
        if (propName.equals(sortProperty) && "asc".equals(this.sortDirection)) {
            sortDirection = "desc";
        } else {
            sortDirection = "asc";
        }
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("sortProperty", propName);
        parameters.put("sortDirection", sortDirection);
        parameters.put(SEARCH_STRING_PARAM, searchString);
        Charset charset = Charset.forName(context.getRequest().getCharacterEncoding());
        UrlBuilder urlBuilder = new UrlBuilder(charset, Util.getAbsoluteUrl(context.getActionPath()), false).addParameters(parameters);
        XhtmlBuffer xb = new XhtmlBuffer();
        xb.openElement("a");
        xb.addAttribute("class", "sort-link");
        xb.addAttribute("href", urlBuilder.toString());
        xb.writeNoHtmlEscape("%{label}");
        if (propName.equals(sortProperty)) {
            xb.openElement("em");
            xb.addAttribute("class", "pull-right glyphicon glyphicon-chevron-" + ("desc".equals(sortDirection) ? "up" : "down"));
            xb.closeElement("em");
        }
        xb.closeElement("a");
        OgnlTextFormat hrefFormat = OgnlTextFormat.create(xb.toString());
        String encoding = getUrlEncoding();
        hrefFormat.setEncoding(encoding);
        tableFormBuilder.configHeaderTextFormat(propName, hrefFormat);
    }
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) XhtmlBuffer(com.manydesigns.elements.xml.XhtmlBuffer) Charset(java.nio.charset.Charset) JSONObject(org.json.JSONObject) UrlBuilder(com.manydesigns.elements.servlet.UrlBuilder) OgnlTextFormat(com.manydesigns.elements.text.OgnlTextFormat)

Example 2 with UrlBuilder

use of com.manydesigns.elements.servlet.UrlBuilder in project Portofino by ManyDesigns.

the class AbstractCrudAction method getLinkToPage.

public String getLinkToPage(int page) {
    int rowsPerPage = getCrudConfiguration().getRowsPerPage();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("sortProperty", getSortProperty());
    parameters.put("sortDirection", getSortDirection());
    parameters.put("firstResult", page * rowsPerPage);
    parameters.put("maxResults", rowsPerPage);
    parameters.put(AbstractCrudAction.SEARCH_STRING_PARAM, getSearchString());
    Charset charset = Charset.forName(context.getRequest().getCharacterEncoding());
    UrlBuilder urlBuilder = new UrlBuilder(charset, Util.getAbsoluteUrl(context.getActionPath()), false).addParameters(parameters);
    return urlBuilder.toString();
}
Also used : Charset(java.nio.charset.Charset) JSONObject(org.json.JSONObject) UrlBuilder(com.manydesigns.elements.servlet.UrlBuilder)

Example 3 with UrlBuilder

use of com.manydesigns.elements.servlet.UrlBuilder in project Portofino by ManyDesigns.

the class AbstractCrudAction method getBlobDownloadUrl.

public String getBlobDownloadUrl(Field field, String baseUrl) {
    Charset charset = Charset.forName(context.getRequest().getCharacterEncoding());
    UrlBuilder urlBuilder = new UrlBuilder(charset, Util.getAbsoluteUrl(context.getRequest(), baseUrl + "/:blob/" + field.getPropertyAccessor().getName()), false);
    return urlBuilder.toString();
}
Also used : Charset(java.nio.charset.Charset) UrlBuilder(com.manydesigns.elements.servlet.UrlBuilder)

Aggregations

UrlBuilder (com.manydesigns.elements.servlet.UrlBuilder)3 Charset (java.nio.charset.Charset)3 JSONObject (org.json.JSONObject)2 PropertyAccessor (com.manydesigns.elements.reflection.PropertyAccessor)1 OgnlTextFormat (com.manydesigns.elements.text.OgnlTextFormat)1 XhtmlBuffer (com.manydesigns.elements.xml.XhtmlBuffer)1