Search in sources :

Example 1 with RenderData

use of org.lastaflute.web.response.render.RenderData in project fess by codelibs.

the class SearchAction method doSearch.

protected HtmlResponse doSearch(final SearchForm form) {
    validate(form, messages -> {
    }, () -> asHtml(virtualHost(path_SearchJsp)));
    if (isLoginRequired()) {
        return redirectToLogin();
    }
    if (viewHelper.isUseSession()) {
        final HttpSession session = request.getSession(false);
        if (session != null) {
            final Object resultsPerPage = session.getAttribute(Constants.RESULTS_PER_PAGE);
            if (resultsPerPage instanceof Integer) {
                form.num = (Integer) resultsPerPage;
            }
        }
    }
    if (StringUtil.isBlank(form.q) && form.fields.isEmpty() && !form.hasConditionQuery()) {
        // redirect to index page
        form.q = null;
        return redirectToRoot();
    }
    try {
        buildFormParams(form);
        form.lang = searchHelper.getLanguages(request, form);
        final WebRenderData renderData = new WebRenderData();
        searchHelper.search(form, renderData, getUserBean());
        return asHtml(virtualHost(path_SearchJsp)).renderWith(data -> {
            if (form.hasConditionQuery()) {
                form.q = renderData.getSearchQuery();
            }
            renderData.register(data);
            RenderDataUtil.register(data, "displayQuery", getDisplayQuery(form, labelTypeHelper.getLabelTypeItemList(SearchRequestType.SEARCH, request.getLocale() == null ? Locale.ROOT : request.getLocale())));
            createPagingQuery(form);
            final String[] relatedContents = relatedContentHelper.getRelatedContents(form.getQuery());
            RenderDataUtil.register(data, "relatedContents", relatedContents);
            final String[] relatedQueries = relatedQueryHelper.getRelatedQueries(form.getQuery());
            if (relatedQueries.length > 0) {
                RenderDataUtil.register(data, "relatedQueries", relatedQueries);
            }
        });
    } catch (final InvalidQueryException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        saveError(e.getMessageCode());
        return redirectToRoot();
    } catch (final ResultOffsetExceededException e) {
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        saveError(messages -> {
            messages.addErrorsResultSizeExceeded(GLOBAL);
        });
        return redirectToRoot();
    }
}
Also used : FessSearchAction(org.codelibs.fess.app.web.base.FessSearchAction) Constants(org.codelibs.fess.Constants) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) LaRequestUtil(org.lastaflute.web.util.LaRequestUtil) RelatedQueryHelper(org.codelibs.fess.helper.RelatedQueryHelper) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SearchRequestType(org.codelibs.fess.entity.SearchRequestParams.SearchRequestType) Locale(java.util.Locale) Map(java.util.Map) RenderData(org.lastaflute.web.response.render.RenderData) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LaFunctions(org.lastaflute.taglib.function.LaFunctions) SearchRenderData(org.codelibs.fess.entity.SearchRenderData) HttpSession(javax.servlet.http.HttpSession) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) Set(java.util.Set) RelatedContentHelper(org.codelibs.fess.helper.RelatedContentHelper) SearchForm(org.codelibs.fess.app.web.base.SearchForm) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Execute(org.lastaflute.web.Execute) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) HttpSession(javax.servlet.http.HttpSession) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException)

Example 2 with RenderData

use of org.lastaflute.web.response.render.RenderData in project fess by codelibs.

the class RenderDataUtilTest method test_register.

public void test_register() {
    RenderData data = new RenderData();
    RenderDataUtil.register(data, "key1", null);
    assertNull(data.getDataMap().get("key1"));
    RenderDataUtil.register(data, "key5", "");
    assertEquals(data.getDataMap().get("key5"), "");
}
Also used : RenderData(org.lastaflute.web.response.render.RenderData)

Aggregations

RenderData (org.lastaflute.web.response.render.RenderData)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Set (java.util.Set)1 Resource (javax.annotation.Resource)1 HttpSession (javax.servlet.http.HttpSession)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 StringUtil (org.codelibs.core.lang.StringUtil)1 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)1 Constants (org.codelibs.fess.Constants)1 FessSearchAction (org.codelibs.fess.app.web.base.FessSearchAction)1 SearchForm (org.codelibs.fess.app.web.base.SearchForm)1 SearchRenderData (org.codelibs.fess.entity.SearchRenderData)1 SearchRequestType (org.codelibs.fess.entity.SearchRequestParams.SearchRequestType)1 InvalidQueryException (org.codelibs.fess.exception.InvalidQueryException)1