S Singh
S Singh

Reputation: 1473

How to populate all java bean properties in jsp using jstl

I need to render all java bean properties in jsp using jsp jstl. I am using spring mvc. Below is the part of spring code.

@RequestMapping(method=RequestMethod.POST)
public ModelAndView processForm(@ModelAttribute(value="FORM") UploadForm form,BindingResult result) throws Exception{
    String filePath = System.getProperty("java.io.tmpdir") + "/" + form.getFile().getOriginalFilename();
    ModelAndView model = new ModelAndView("view");
    List<Customer> customerList=null;//Customer is POJO file
    if(!result.hasErrors()){
        ProcessUploadedFile processUploadedFile = new ProcessUploadedFile(form, filePath);
        processUploadedFile.putUploadedFileToServer(form,filePath);
        customerList= ProcessUploadedFile.readWithCsvBeanReader(filePath);
    }
    model.addObject("customerList", customerList);//add list of customers in object. all customer data need to be render in jsp
    return model;
}

JSP JSTL code:

<c:forEach var="customer" items="${customerList}">

           <tr>
           <td><c:out value="${customer.hit_time_gmt}"/></td>
               <td><c:out value="${customer.service}"/></td>
               <td><c:out value="${customer.accept_language}"/></td>
               <td><c:out value="${customer.date_time}"/></td>
               <td><c:out value="${customer.visid_high}"/></td>
               <td><c:out value="${customer.visid_low}"/></td>
.
.
.
.
</tr>
</c:forEach>

Actually there are arround 300 properties in POJO and manually write property like is very tedious.

I want some looping way to get all properties value is jsp using jstl or may be other way. Please share yours tips !

thanks

Upvotes: 0

Views: 2057

Answers (2)

Alex
Alex

Reputation: 11579

You can create Array of all properties for each customer using java reflection and put it into some new POJO.

public CustomerProp {
   private List<String> properties;
}

And then to display them in jsp using one more iteration for each customer.

Upvotes: 0

Velu
Velu

Reputation: 1911

You should write your own custom tag and make it available to the community users. As for as i know there is no available JSTL Tag which tries to display all the properties of an object.

Upvotes: 0

Related Questions