• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp inside jsp

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am looking for a way to have jsp code which is stored as a string in my database be evaluated and the result be displayed. The best I seem to be able to do is display the JSP itself.
Below we have a for loop which is building the table data elements for 1 row of my table.

<% for (int x=0; x < displayColumnArray.size(); x++) { %>
<td>
<%=TableColumnDisplay.getColumnJsp(displayColumnArray.get(x).getArrayId(0))%>
</td>
<% } %>

I know I am asking the compiler to call the function and then process what was returned. Maybe it can't handle that.
I have tried passing this as an arg to a separate jsp page, but to no avail. in fact, that adds some additional characters around the jsp.

<% for (int x=0; x < displayColumnArray.size(); x++) { %>
<jsp:include page="./tableColumnDisplay.jsp">
<jsp:param name="jspTdValue" value="<%=TableColumnDisplay.getColumnJsp(displayColumnArray.get(x).getArrayId(0))%>" />
</jsp:include>
<% } %>

tableColumnDisplay.jsp
<td>
${param.jspTdValue}
</td>

I guess what I am asking is, is there is a way to say f(g(x)) which would cause the jsp to be evaluated and then evaluated again?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Erik Skov wrote:I am looking for a way to have jsp code which is stored as a string in my database be evaluated and the result be displayed.



Ouch. Seriously? You put JSP code into a database with the plan of executing it? Why?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It also looks like you are mixing scriptlets and the EL in a JSP? The only thing worse than using scriptlets (poor practice since 2002) is mixing it with the EL and JSTL.
 
Erik Skov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The plan is to build the column list for this table on the fly. I am supporting multiple departments with the same data, but they would like to see different columns in different orders. I put code related to displaying each column into a table in the database so I could easily add, subtract, and change the order of the columns by doing database updates instead of code changes in the jsp itself.

Table layout: id, column_header_text, display_jsp, dept1_order, dept2_order, dept3_order, dept4_order.

The display_jsp is basically if-true-false, "( value != null, value, space)", so that nulls do not appear in the chart, but in some cases "true" calls a java method and passes the value to it for a returned value. All of these work fine if I just put them directly on the jsp page.

The actual data to be displayed is in an ArrayList for each row returned from the database.

As for the scriplets vs EL, I am at a new job and this is the way the code is styled. HTML with <%...%> mixed in for control statements (if, for) and calling java methods to return values. I am also new to jsp, although I have used java and have used PHP mixed with HTML before. What would you recommend / what is the current standard ? can you point me to a page / tutorial ?
 
Erik Skov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I might be able to rework the code and data so I get this:

<% for (int x=0; x < displayColumnArray.size(); x++) { %>
<td>
<% tdColumn = TableColumnDisplay.getColumnJsp(displayColumnArray.get(x).getArrayId(0));%>
<% tdTest = (tdColumn != null);%>
<% tdTrue = process(tdColumn);%>
<%=(tdTest ? tdTrue : strSpace)%>
</td>
<% } %>
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Erik Skov wrote:The display_jsp is basically if-true-false, "( value != null, value, space)", so that nulls do not appear in the chart, but in some cases "true" calls a java method and passes the value to it for a returned value. All of these work fine if I just put them directly on the jsp page.



It sounds like this is a job for a taglib... or just using JSTL and EL, which automatically render null as the empty string. Also the JSTL <c:out> tag has a "default" attribute which might help.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having JSP code stored in a database to be compiled/evaluated is difficult.

From your description the actual jsp code in the database doesn't change that much - its just inclusion and ordering that is dynamic?

I would definitely go with tag files.
Each "column definition" gets its own tag file.

The table currently storing this code gets replaced with a reference to a tag. So instead of the actual code in the database, you tell it the custom tag to display.

Your process logic would then be a huge switch statement if "code1" then display "tag1" if "code2" then display "tag2".

- you can test each tag independently of the database. Storing JSP code in a database is difficult to maintain, and easy to introduce bugs in
- defining a new column is creating a new tag file and adding it to your application. Not quite as dynamic as your current solution, but I how often do you define new columns anyway? I think the trade-off is more than worth it.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic