• 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

how to display database values in a table

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

I am trying to disply the product column from the database into a table. I am able to add the items to the ArrayList
But the items are not being displayed in the jsp. My action class is as follows:



The jsp is not printing the product name stored in the database. The jsp is as follows:
 
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
Line 38 creates a new, local "productsdealt" list. The action property is never set or filled, so there's nothing to display.

From a stylistic standpoint it's more common to use names like "productsDealt", which is arguably easier to read.
 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So either you can set "productsdealt" to session scope or request scope. And accordingly retrieve it in jsp.
 
David Newton
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
@Amandeep: That's not the preferred mechanism in Struts 2--there's no reason to set something to a JEE scope unless you have a specific requirement to do so.
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so what is the recommended approach to do this in struts 2?
 
David Newton
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
Expose an action property, as the OP did in the second code snippet (but never filled it with values).
 
Prashant K. Singh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

I modified the action class and the jsp a bit and now I am able to print the output on the jsp.

But Hulloa there is a problem. Also every time I hit the refresh button, the output gets increased by one ie if i have bariton as output then it becomes barition bariton.

I am again posting the code:

Here is the Productdisplay.java



Here is the Product.java



Here is the producthandles.jsp

 
David Newton
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
Are you using Spring?

It's difficult to understand code's intent when there are ambiguities--for example, the action method creates a local variable called "productName", and the action has a property called "productName", and they're different types.
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Expose an action property, as the OP did in the second code snippet (but never filled it with values).



As i am a newbie to Struts 2. Just a question, in the previous code how Prashant is exposing the 'products' to the jsp.
Because inside the ActionSupport, we are not exposing it through any reference.
 
David Newton
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

how Prashant is exposing the 'products' to the jsp


 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this i know. i actually meant is this exposed as a action property inside struts-config.xml

as i know struts 1. this feature is available only in struts 2.

please correct me if i am wrong.
 
David Newton
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're not wrong--this is Struts 2, as was the original question.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic