I am upgrading struts2 (core) from 2.1.8.1 to 2.3.31 and having the following problem: After upgrading all the jars, compiling the app, running it, and accessing the page, I get the following error:
java.lang.NoSuchMethodError: org/apache/struts2/views/jsp/ui/SelectTag.setRequired(Ljava/lang/String;)V
So I do a little digging and find the following report: Source compatibility report for the struts2-core library between 2.3.8 and 2.3.12 versions
Basically showing that :
AbstractUITag.setRequiredLabel ( String requiredLabel ) : void
- added.
AbstractUITag.setRequired ( String required ) : void
- was removed
Now, the docs for Select element, mention the following, that requiredLabel
is defined as If set to true, the rendered element will indicate that input is required of type Boolean.
So, I am kind of lost here, should I use requiredLabel=true
or just drop the required
attribute and validate in code?
The requiredLabel
attribute will generate an *
to render visually that the field is mandatory.
The attribute was called required
in old versions of the tags, but then HTML5 specs came out with the required
attribute, that has nothing to do with the asterisk and instead instructs a browser to not allow the submission of a form with those fields empty, and hence the new versions of the tags had to change it in order to make possible to use the HTML5 version, while keeping the asterisk functionality available, just under another name: requiredLabel
.
Your only needed operation is:
find every occurrence of
required="true"
, replace it withrequiredLabel="true"
.
The suggested operation is:
find every occurrence of
required="true"
,replace it with
requiredLabel="true" required="required"
,so you'll get the best of both worlds.
Also pay attention to useless but potentially existing required="false"
occurrencies.