views:

254

answers:

1

I want to be able to show some data based on criteria the user enters in a text field. I can easily take this data, process the form post, and show the data on another page. However, I want to be able to do it all on the same page - they click the button, and a new div shows up with the information. This doesn't seem too complicated, but I want to use jstl tags to format the data like:

<c:forEach items="${model.data}" var="d">
  <tr>
    <td><fmt:formatDate type="date" dateStyle="short" timeStyle="default" value="${d.reportDate}" /></td>
    <td><c:out value="${d.cardType}"/></td> 
  </tr>
</c:forEach>

If jstl tags are processed when the page loads, can I use that in this new div? Can I update it via a javascript (using prototype) function to display the proper data? Will I be able to do the same thing if they change the criteria and click the submit button again?

+1  A: 

No, you can't. You already said yourself, JSTL only runs at the server side. As you're running this entirely at the client side, your only resort is to use JavaScript to populate the table. I've posted similar answers before here and here with code examples how to populate a table with help of jQuery, JSON, Google Gson and a Servlet. I know that you're using Prototype, but the jQuery syntax should be recognizeable enough to port it to Prototype syntax without any problems.

BalusC
You're too pro `GSon`, why not download a fully stable `JSon` Object Serializer from `JSon.org` themselves?
The Elite Gentleman
@The Elite Gentleman: I've tried almost all available Java based JSON serializers and Gson has the best support for generics and nested beans. You basically don't need to do anything yourself to get it to work the way you want. Just `Gson#toJson()` and `Gson#fromJson()` suffices.
BalusC