0

I have created a java webapp that reads a custom table (consisting of 13 fields per record) from a SAP backend into a JCoTable in the webapp and this all works fine.

My requirement is to output all the records on the JCoTable onto a JSP using EL. How do I reference each individual field for output purposes? i.e.

<c:forEach items="${claimstable}" var="clms">
      ${clms.field1}
      ${clms.field2}
      ${clms.field3}  
</c:forEach>

I have tried using an ArrayList, TreeSet and HashMap to output the table contents on the JSP, using a servlet to forward on the request attribute to the JSP, but I cannot directly access each field, I can only output the contents as one long string.

Do I need to create a class of my table fieldnames and proceed that way? Or what?

Any and all help greatly appreciated.

D. Barrett
  • 23
  • 4

2 Answers2

2

The solution I went with was to create an object of my custom table with setters and getters create each field as a property within the object i.e.

public class ClaimTableProperties {


private String zuonr;
private String bktxt;
private String blart;
private String belnr; 
...etc.

and then map each row of the JCoTable per field to an arraylist:

static ArrayList<ClaimTableProperties> claimstable = new ArrayList<ClaimTableProperties>();

    JCoTable claims = function.getTableParameterList().getTable("CLAIM_DETAILS");

    claims.firstRow();
    int rownums = claims.getNumRows();
    ClaimTableProperties[] ctp = new ClaimTableProperties[rownums];

    for (int i = 0; i < rownums; i++) {
            ctp[i] = new ClaimTableProperties();
            ctp[i].setBelnr(claims.getString("BELNR"));
            ctp[i].setBktxt(claims.getString("BKTXT"));
            ctp[i].setZuonr(claims.getString("ZUONR"));
            ctp[i].setBlart(claims.getString("BLART")); 
            claimstable.add(ctp[i]);
            claims.nextRow(); 
    } // End for

In your servlet, set the attribute so it's known to your jsp

ArrayList<ClaimTableProperties> claims = dgc.returnClaimsTable();
request.setAttribute("claimstable", claims);

Then on the jsp, use JSTL to output each required field:

<table>
<c:forEach items="${claimstable}" var="claim">
<tr>
<td>${claim.belnr}</td>
<td>${claim.bktxt}</td>
<td>${claim.zuonr}</td>
<td>${claim.blart}</td>
</tr>
</c:forEach>
</table>  
D. Barrett
  • 23
  • 4
0

First set the values in the request and then try to access it in the jsp

Do it in your servlet

List<List<Person>> claimstable= getItSomehow();
request.setAttribute("claimstable", claimstable);

The claimstable will be accessible in the jsp. Use double for each loop to traverse the individual String

Avinash Raj
  • 791
  • 1
  • 8
  • 12
  • I have tried creating an ArrayList in my servlet and sending it to my jsp via request.setAttribute but I cannot access each individual field. Should i create an ArrayList ? – D. Barrett May 03 '17 at 17:14
  • Are you forwarding your servlet to the write jsp? Please share your servlet. – Avinash Raj May 03 '17 at 19:39
  • I can access the "claimstable" in my jsp (similar to how you've set it out above) but only as a continuous string because I've set it as an ArrayList, however I need to access each individual field that makes up the table – D. Barrett May 03 '17 at 19:53
  • You need to use it as a 2-Dimensional Matrix., i.e. List of List of Strings as `List>` and set your entries into the Object according to your requirements. – Avinash Raj May 03 '17 at 20:07