Remove scriptlets from JSP

S

stephenfu1

Hi

In my JSP i have some scriptet code that defines the method
display(ArrayList a, String s)

and is called using
<%=display(personDetails.getList1, "List 1")%>
<%=display(personDetails.getList2, "List 2")%>

This method performs some checks on the ArrayList and writes some html
code and text to the screen.

I'd like to clean up the code (using Struts) and move this method into
a separate helper class

Is there a variation on <bean:write name="personDetails"
property="display"/> that i can use to call display(ArrayList a, String
s). I need to be able to pass in the arguments (to output p.getList1
and p.getList2 and perform some other logic)

Thanks for any help
 
A

Andrew Thompson

Thanks for any help

It helps to ask a question.

...and if the question is 'how do I do the above?',
expect a lot of 'buy a book' type answers.

This group is a dicsussion group that can be good for
specific answers to specific technical questions, but
not so much for tutoring.
 
R

Robert Klemme

Hi

In my JSP i have some scriptet code that defines the method
display(ArrayList a, String s)

and is called using
<%=display(personDetails.getList1, "List 1")%>
<%=display(personDetails.getList2, "List 2")%>

This method performs some checks on the ArrayList and writes some html
code and text to the screen.

I'd like to clean up the code (using Struts) and move this method into
a separate helper class

Is there a variation on <bean:write name="personDetails"
property="display"/> that i can use to call display(ArrayList a,
String s). I need to be able to pass in the arguments (to output
p.getList1 and p.getList2 and perform some other logic)

Not that I know of. In this case I'd rather write a custom tag that does
the transformation you need. An alternative approach could be to use
include to call another servlet / JSP that carries your helper code. If
it's a JSP and you're on Tomcat 5 or newer you might be able to do it with
the new expression language. But from the little info I have a custom tag
seems more appropriate.

Kind regards

robert
 
D

Darren

Andrew Thompson said:
It helps to ask a question.
Is there a variation on <bean:write name="personDetails"
property="display"/> that i can use to call display(ArrayList a, String
s).

reads like a question to me despite the lack of a question mark.
 
A

Andrew Thompson

Darren said:
Is there a variation on <bean:write name="personDetails"
property="display"/> that i can use to call display(ArrayList a, String
s).

reads like a question to me despite the lack of a question mark.

I did not jump out as a question to me as someone *scanning*
for the mark that denotes a question.

But now you point it out. OK - it is a question for all
but the '?'. I missed it.
 
D

Darren

Andrew Thompson said:
I did not jump out as a question to me as someone *scanning*
for the mark that denotes a question.

But now you point it out. OK - it is a question for all
but the '?'. I missed it.

No worries mate, we've all done it. :)
 
T

Tim B

Hi

In my JSP i have some scriptet code that defines the method
display(ArrayList a, String s)

and is called using
<%=display(personDetails.getList1, "List 1")%>
<%=display(personDetails.getList2, "List 2")%>

This method performs some checks on the ArrayList and writes some html
code and text to the screen.

I'd like to clean up the code (using Struts) and move this method into
a separate helper class

Is there a variation on <bean:write name="personDetails"
property="display"/> that i can use to call display(ArrayList a, String
s). I need to be able to pass in the arguments (to output p.getList1
and p.getList2 and perform some other logic)

Thanks for any help

you could just import the helper class and still use an expression
<%=MyHelperClass.display(personDetails.getList1, "List 1")%>

or if the 'some other logic' you have in you display method is simple
enough, you might be able to replace it with Struts logic tags, such as
<logic:iterate> and <logic:equal>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top