My jsp page has several labels coming from controller in ...">

Using a variable in jstl "key" from <fmt: message key = "<% = customFieldData%>" / ">

My jsp page has several labels coming from controller in spring mvc. But I am trying to use a properties file to show different values ​​for these labels. Here is my jsp code

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<fmt:bundle basename="main.resources.abc_messages">
                <%
                    if (request.getAttribute("customFields") != null) {
                        String line = request.getAttribute("customFields").toString();
                        line = line.subSequence(1, line.length() - 1).toString();
                        String[] data = splitLineIntoArray(line, ",");
                        for (int i = 0; i < data.length; i++) {
                            String field = data[i];
                            String[] customFieldData = splitLineIntoArray(field, "=");
                %>
                <div class="row">
                    <div class="left">
                    <fmt:message key="<%=customFieldData[0]%>"/>    
                    </div>
                    <div class="right">
                        <input type="text" type="customField"
                            value="<%=customFieldData[1]%>" id="customField"
                            class="inputfixed" disabled="true" />
                    </div>
                    <div class="clear"></div>
                </div>
                <%
                    }
                    }
                %>
</fmt:bundle>

      

I have placed the properties of the abc_messages.properties file on the classpath. When I use key = "abc" and the properties file has abc = xyz, then I get the value xyz. But when using a variable as required here, I get ???. But I always get this as output

??? color???   : green
??? font ???   : arial

      

Abc_messages.properties file

color=Main Color
font=Main Font

      

+3


source to share


1 answer


The problem was the extra space I was getting as CustomFields data. "color" is the string I was getting, but there was "color" in the properties file. So it gave ??? color ???, I must have trim () customFieldData before entering key



0


source







All Articles