How can I use the liferay-ui:search-form tag to specify a JSP containing my search form?

3.4k views Asked by At

I have a JSP, say view.jsp, that's using the basic Liferay search container pattern:

<liferay-ui:search-container>
    <liferay-ui:search-form page="..." />
    ...
</liferay-ui:search-container>

Let's say view.jsp is in the docroot/jsp folder and that, in the same folder, is my search form, search.jsp. Now, when I do:

<liferay-ui:search-container>
    <liferay-ui:search-form page="search.jsp" />
    ...
</liferay-ui:search-container>

The page renders correctly but without the search form. In the console, I notice the ff. exception:

08:11:01,937 ERROR [IncludeTag:154] java.lang.IllegalArgumentException: Path search.jsp does not start with a "/" character
        at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:370)
        at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:196)
        at com.liferay.taglib.util.IncludeTag.include(IncludeTag.java:173)
        at com.liferay.taglib.util.IncludeTag._doInclude(IncludeTag.java:223)
        at com.liferay.taglib.util.IncludeTag.doEndTag(IncludeTag.java:58)
        ...

If I use an absolute path like so:

<liferay-ui:search-container>
    <liferay-ui:search-form page="/jsp/search.jsp" />
    ...
</liferay-ui:search-container>

The same thing happens but the exception is now:

08:21:21,796 ERROR [IncludeTag:154] javax.servlet.ServletException: File &quot;/jsp/search.jsp&quot; not found
        at org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:335)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:551)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:488)
        at com.liferay.taglib.util.IncludeTag.include(IncludeTag.java:175)
        at com.liferay.taglib.util.IncludeTag._doInclude(IncludeTag.java:223)
        at com.liferay.taglib.util.IncludeTag.doEndTag(IncludeTag.java:58)
        ...

Does anyone know how to fix this?

1

There are 1 answers

0
Bertrand On BEST ANSWER

If you are developing in the plugin environement, you should use something like that to include your search form:

<liferay-ui:search-form
        page="/search.jsp"
        searchContainer="<%= searchContainer %>"
        servletContext="<%= this.getServletConfig().getServletContext() %>"
        showAddButton="true" />

(This is Liferay 6.0.6 TLD)