struts2struts2-jquerystruts-validation

Should I find and copy struts styles and javascripts to the /struts/ folder enable client-side validation?


Client-side validation doesn't work for me. First I thought that it is a myeclipse fault that doesn't copy them to the root folder but then I discovered the js and css files reside in the struts core jar. Now I wonder what I should do! Should if I find and copy all js and css files from their appropriate folders to the webRoot or there is an intelligent workaround like changing the configuration? Should struts copy them by self?

I use Tiles with Struts. Could it be the problem?

My JSP files are in the WEB-INF folder! Can it have caused some problem?

Can using something like struts2-jquery plugin solve my problem?

I use struts2!

My struts2 filter configuration is

  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
  </filter-mapping>

    <listener>
    <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

Solution

  • The specific problem here is the filter configuration:

    <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>*.action</url-pattern>
    </filter-mapping>
    

    The recommended configuration (unless you specifically know what you're doing) is to map to *:

    <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>*</url-pattern>
    </filter-mapping>
    

    If you map only to *.action, non-action requests (like CSS and JavaScript) won't be processed by the filter. S2 examines the request for files it (S2) knows about, like its own CSS and JavaScript files, and serves those requests itself even though they're not action requests.

    This is documented in the S2 guides' Static Content section.

    It's perfectly valid to map to *.action, but then you do need to extract the static files and put them at their required location, at least if you intend to use the default S2 themes/JavaScript. That's also optional: the framework is designed to get you started relatively quickly, but if you have specific needs that the framework doesn't handle, using that part of S2 may or may not be the best choice.