I am working on a Spring application, and on a JSPX page, I need to dynamically load some values from the property page and set them as a drop-down list using the options tag. I need to use the same text for parameter values and for display, but for parameter values I need to remove all special characters.
For example, if the value is mother’s uncle, then I need
<option value="MaternalUncle">Maternal Uncle</option>
What I get
<option value="Maternal Uncle">Maternal Uncle</option>
There are 2 applications that can use this page and which property file to load depends on the application. If I load values for application 1, the values will be displayed correctly, the last value in application 1 is “Other” and does not have special characters. For application 2, it does not trim spaces where the last value is “Maternal Uncle”. repOptions in code is an ArrayList with values loaded from the properties file. Here is my code:
<select name="person" id="person"> <option value="na">Select the relationship</option> <c:forEach items="${repOptions}" var="repOption"> <option value="${fn:replace(repOption, '[^A-Za-z]','')}">${repOption}</option> </c:forEach> </select>
The first application removes spaces, as this is the fourth in list 9. For app2, this is the last value, and the regex does not work. If I put Maternal Uncle as the first property for application2, then this works fine, but the requirements should have the latter option.
<option value="${fn:replace(repOption, ' ','')}">
works for spaces, but there may be values like Brother / Sister, so I need to remove / as well, so I use regex.