In my spring project, my view receive from controller a Map object like this:
Map<String, List<?>>
which I access in my jsp code this way:
<c:forEach var="field" items="${values[item]}">
<c:out value="${field}"/> <br/>
</c:forEach>
Considering the class indicatd by ?
it's a regular POJO class, how I can access the attributes from this class in my jsp? In other words, what the correct instruction I should use to replace:
<c:out value="${field}"/> <br/>
because with this I am getting something like that when I open the page in the browser:
com.spring.loja.model.categoria.persistence.model.Categoria@41c0e228
UPDATE
I try use this, following answer posted in this topic:
<c:out value="${field.name}"/>
but I wonder if there is a way to use this method instead:
@Override
protected String getArgument(int ordem) {
switch(ordem) {
case 0: return "Id";
case 1: return "Login";
case 2: return "Senha";
case 3: return "Nome";
case 4: return "Sobrenome";
case 5: return "E-Mail";
case 6: return "Autorizacao";
default: return null;
}
}
and this way be able to avoid the use of the name of the getter method (It's a generic jsp page, used by several views, and I don't know which method will be used)
You can access attributes by creating an object of the class, and by using the dot syntax (. ): The following example will create an object of the Main class, with the name myObj.
The JSP Standard Tag Library (JSTL) represents a set of tags to simplify the JSP development. Fast Development JSTL provides many tags that simplify the JSP. Code Reusability We can use the JSTL tags on various pages.
JSTL formatting tag library provides a convenient way for formatting text, numbers, dates, times and other variables for better display. JSTL formatting tags can also be used to enhance the internationalization of a website. Before using these formatting tags, we've to add the taglib to our JSP:
Create a class called " Main " with two attributes: x and y: Another term for class attributes is fields. You can access attributes by creating an object of the class, and by using the dot syntax (. ): The following example will create an object of the Main class, with the name myObj.
If this POJO has for an example getName()
getter, then you can access name
field using:
<c:out value="${field.name}"/>
If you use Servlet +3.0
version, then you can invoke method from EL. Then you can try something like that:
<c:out value="${field[field.getArgument(2)]}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With