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();
}
}
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"), "");
}
Aggregations