• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Obtaining a refference to the action form from a jsp page

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

Is there any way to obtain a refference to the action form associated with a jsp from the jsp itself
I don't mean with tags and property
I want to do something like this



the purpose is to hide a datagrid if there is no valid data to display

I am new to struts

If this could be done another way that would also be ok.

Thank you in advance.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrew Para wrote:
Is there any way to obtain a refference to the action form associated with a jsp from the jsp itself


Put the beans valid instance in the scope before accessing it on the page, then you can access it on your jsp page, like



But the above use of scriptlet is not recommended.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could also get it using the same mechanism Struts does (it's either in the request or session depending on your configuration). As Sagar said--I would be *extremely* wary of going down this road; it's a Bad Idea.
 
Andrew Para
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:You could also get it using the same mechanism Struts does (it's either in the request or session depending on your configuration). As Sagar said--I would be *extremely* wary of going down this road; it's a Bad Idea.



I don't necessarily want to go down this road.
But I can't thnk of anything better to do.
I am open to any suggestions.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrew Para wrote:

David Newton wrote:You could also get it using the same mechanism Struts does (it's either in the request or session depending on your configuration). As Sagar said--I would be *extremely* wary of going down this road; it's a Bad Idea.


I don't necessarily want to go down this road.
But I can't think of anything better to do.
I am open to any suggestions.


I think your problem is like this:
"Display the datagrid, if there is any data in the list to be shown, otherwise don't show anything"

For the above problem, I do something like this;:

In Action class


In JSP



HTH
 
Andrew Para
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sagar Rohankar wrote:

Andrew Para wrote:

David Newton wrote:You could also get it using the same mechanism Struts does (it's either in the request or session depending on your configuration). As Sagar said--I would be *extremely* wary of going down this road; it's a Bad Idea.


I don't necessarily want to go down this road.
But I can't think of anything better to do.
I am open to any suggestions.


I think your problem is like this:
"Display the datagrid, if there is any data in the list to be shown, otherwise don't show anything"

For the above problem, I do something like this;:

In Action class


In JSP



HTH



you are dead on
but I don't understand one thing
what goes between <table> and </table>?
and where is the collection?
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrew Para wrote:
but I don't understand one thing
what goes between <table> and </table>?


Your data

Andrew Para wrote:and where is the collection?


In Action class
 
Andrew Para
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sagar Rohankar wrote:

Andrew Para wrote:
but I don't understand one thing
what goes between <table> and </table>?


Your data

Andrew Para wrote:and where is the collection?


In Action class



let me try to explain a little better

this is how I am doing things now:

this is in my jsp



this is in my action form:



this is in my action class:


Now I have the following problem:

if I access localhost/myjsp.jsp I get a null pointer exception because there is nothing to populate the collection with
if I access localhost/myaction.do?regCode=display I get the null pointer exception if the array list recommendations is null

It would be nice if I could display something like: no data found or something if recommendations is null

SO I don't understand why there is a table tag there?
Does my layout:collection go in there instead?
how can I modify my code so that I can avoid the null pointer exception.

Thank you in advance
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrew Para wrote:SO I don't understand why there is a table tag there?
Does my layout:collection go in there instead?


Yes, I don't know your using layout tag for displaying the data. The table thing is for the same.

Andrew Para wrote:how can I modify my code so that I can avoid the null pointer exception.


Never return a null list, either empty or with some data, and my previous reply shown how to do that in Action class.
 
Andrew Para
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sagar Rohankar wrote:

Andrew Para wrote:how can I modify my code so that I can avoid the null pointer exception.


Never return a null list, either empty or with some data, and my previous reply shown how to do that in Action class.



How can I return an empty list?
currently I populate it with "-"
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have no data to display, simply set the empty list instance in scope, like



And why its not good thing to return null instead of empty array/list, see this blog:
http://www.selikoff.net/blog/2008/10/15/never-return-null-arrays/
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic