0

I'm using <ignored-parameter> tags in friendly-url-routes.xml to hide requets parameters. The Liferay documentation says "Ignored parameters do not effect URL recognition." When I redirect to a Struts action my parameters are lost and ignored.

Snippet from my friendly-url-routes.xml

<route>
    <pattern>/showSearch</pattern>
    <ignored-parameter name="searchId"/>
    <ignored-parameter name="pageNumber"/>
    <ignored-parameter name="count"/>
</route>

This is in struts.xml

<action name="showSearch" method="showSearch" class="com.mycomp.portlet.action.search.SearchAction">
        <result name="success">
            <param name="location">/WEB-INF/jsp/results/detail.jsp</param>
            <param name="searchId">${searchId}</param>
            <param name="pageNumber">${pageNumber}</param>
            <param name="count">${count}</param>
        </result>
</action>

How is it possible that the tag is affecting the functionality of the action when it is not supposed to? Is there anything I can do to hide these parameters but keep the functionality? I cannot use <generated-parameter> tags because these parameters do not always have a value

Thanks

steven35
  • 2,815
  • 2
  • 30
  • 39
  • Struts2 uses its own scheme for URL recognition. The most important parameters are action name and namespace. Other parameters that are after the action name are not important, so could be ignored. – Roman C Nov 10 '14 at 17:56
  • Problem is if I ignore them then checkboxes don't stay checked, text inputs won't persist their text etc... I'm redirecting through a few actions so maybe it interferes with one of the generated urls somewhere down the line – steven35 Nov 10 '14 at 18:02
  • Then you should add them to a pattern. – Roman C Nov 10 '14 at 18:07
  • You mean before the "?" in the url? It's a search for that's getting submitted with approximately 40 parameters so I'm trying not to display them at all. IE can only support urls up to just over 2000 chars. Also, that's only going to work if the parameter has some value. In my case they are sometimes empty. (when the user doesn't type anything into the search bar) – steven35 Nov 10 '14 at 18:11
  • Why do you passing them by url? – Roman C Nov 10 '14 at 18:16
  • I have to. I was told not to use session – steven35 Nov 10 '14 at 18:19
  • How about request? Do you allowed to use it? What kind of requests do you know? – Roman C Nov 10 '14 at 18:20
  • I'm doing a full page refresh. Otherwise these values are request scoped – steven35 Nov 10 '14 at 18:24
  • Struts have `Preparable` interface for actions that want to populate amount of data before rendering a page, and that data keep themselves populated even if errors occurred during refresh. – Roman C Nov 10 '14 at 18:28

1 Answers1

1

I don't know Liferay, but it seems logical that if you ask to ignore a parameter, that parameter will be ignored (read: removed from the URLs).

The same documentation you linked, in the previous sentence states that:

The ignored-parameter element specifies a parameter that should be ignored and not included in generated URLs.

Afterward, it is not clear what are you trying to achieve.

If you want to work with GET requests, the parameters in the QueryString need to stay there (but you can format them in Pretty URLs / Clean URLs with Advanced Wildcard Mapping). Otherwise you are violating HTTP 1.1 (GET with body).

There is also no need to put those parameters in Struts configuration at all...

Unless your results are of type redirect / redirectAction, and hence the parameters would be lost across the two requests. In that case, you could (in redirectAction) statically replicate the parameters in the way used in your code, or (in redirect) dynamically copy only the existing parameters for that request, without the need to know them and to hard-code them in the configuration, with this trick.

Community
  • 1
  • 1
Andrea Ligios
  • 46,329
  • 24
  • 102
  • 208
  • You are right about the parameters in the Struts config. It is actually a redirect action I just changed it when I copied it in here. I've got the parameter hiding working in another portlet with tags but it's not working in this one and I can't figure out why – steven35 Nov 10 '14 at 17:23
  • Just use getters and setters, and all the parameters in redirectAction even when empty – Andrea Ligios Nov 10 '14 at 20:27