• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

<s:select > populate data from database

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to populate list of values from db to s:select tag and have to return id of the selected item from the list.
my jsp page



my action class


error I obtained.


please help me to solve this problem.
 
Pradeesh Pakkat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey all,

I got my list in action class but I cann't connect it with the select tag in jsp. please help me.. what is the procedure...
 
Pradeesh Pakkat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me its really urgent... I don't know how to populate list to select tag.
 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pradeesh Pakkat wrote:please help me its really urgent...



Everyone's question on JavaRanch is urgent.
That said, does your action do anything? I don't see an execute method or anything that resembles one.
 
Pradeesh Pakkat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Everyone's question on JavaRanch is urgent.

Sorry for my emergency.

I have methods to populate the form values to database. It works properly(I hard core the value for select tag). Now the problem is that how can I populate bean list to jsp page.

action.java //I am just mentioning about the list. all other execute(), getters and setters are working fine

struts.xml

reg.jsp
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does displayStates() return a String?
Where does it get called? Have you checked the value of the states list after that invocation?

 
Pradeesh Pakkat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I just saw similar example somewhere else. But it couldn't help me to achieve the goal... Simply I just don't nothing about how to populate from list to jsp page in struts2. I go through some docs but i couldn't trace out the linking between jsp page and the list in the action class. Please help me to sort it out.
 
Pradeesh Pakkat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
any help please
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered the questions I asked?
 
Pradeesh Pakkat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I got some more information about the problem. As of my knowledge through Google is that we can't call jsp page directly after populating the list from the bean/action class. If we want to do so we have to call the action class ( Display.action instead of Display.jsp).


Why does displayStates() return a String?
Where does it get called? Have you checked the value of the states list after that invocation?


struts.xml

When framework starts the display function will automatically populate the list, 'I think so'.

Now my question changed to 'HOW CAN WE CALL AN ACTION PAGE DIRECTLY'
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pradeesh Pakkat wrote: As of my knowledge through Google is that we can't call jsp page directly after populating the list from the bean/action class.



I'm not sure you understand how Struts works. The browser sends a request to a URL mapped to an action, the action performs whatever tasks necessary (usually obtaining or updating data) and forwards to a JSP. The JSP then renders whatever data the action set up and returns something (usually HTML) to the browser. There is no direct call to the JSP. If one were to invoke a JSP directly, there'd be no data to display.


When framework starts the display function will automatically populate the list, 'I think so'.



No it will not. You have made a really, really basic Java error in your action class. Please consider the questions I asked again. I have no idea why you posted a piece of your struts.xml file that refers to a class you haven't shown us.


Now my question changed to 'HOW CAN WE CALL AN ACTION PAGE DIRECTLY'



Answer 1. "you don't want to" because it would break the MVC pattern.
Answer 2: "you can't" - see the top of this post. If the action sets up the data, calling the JSP directly will not work.
Answer 3: "you can't" because Struts tags throw an error if the Struts framework doesn't run first.
 
Pradeesh Pakkat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Joe,

There is no direct call to the JSP. If one were to invoke a JSP directly, there'd be no data to display.


by direct call to the jsp I mean the URL to be display in the address bar.(like http://10.xxx.16.xx:8080/EpssService/page/test1.jsp when it comes through the action class it will become http://10.xxx.16.xx:8080/EpssService/page/registration.action).

this is my struts.xml


this is my action class



Answer 1. "you don't want to" because it would break the MVC pattern.
Answer 2: "you can't" - see the top of this post. If the action sets up the data, calling the JSP directly will not work.
Answer 3: "you can't" because Struts tags throw an error if the Struts framework doesn't run first.


Now I simply asking you that how can I populate a list containing items from database.
my jsp page
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll say this again:

Joe Ess wrote:
You have made a really, really basic Java error in your action class. Please consider the questions I asked again.



Pradeesh Pakkat wrote:
by direct call to the jsp I mean the URL to be display in the address bar.



It is possible to do database access from a JSP (a JSP is compiled into Java Servlet so whatever you can do in a plain old Servlet you can do in a JSP). This is generally considered a Bad Thing because JSP's are display components and data access should be in a controller component (See MVC Pattern). It will cause a problem with your page in particular because Struts tags will throw an error if the Struts framework doesn't run before they are processed.
You are attempting to route around a logic error in your action class. It's always a good idea to isolate the problem as the code samples you posted are fairly large. Think about how you are obtaining the list of states and how that list is accessed on the JSP.
 
Pradeesh Pakkat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote
Why does displayStates() return a String?
Where does it get called? Have you checked the value of the states list after that invocation?


I removed the function display() from the action class so there is no call to this function too. After invoking the list through RMI I printed it. It worked well @ the action class.

Joe Ess wrote
Think about how that list is accessed on the JSP.


I don't know and that's my problem.... I just saw populating the list through JSONto the JSP and I am working on it. I am using struts with maven. Hope your kindness and help....
 
Pradeesh Pakkat
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote
You have made a really, really basic Java error in your action class.


I couldn't figure it out ...:-(
 
Joe Ess
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Pradeesh Pakkat wrote:

Joe Ess wrote
You have made a really, really basic Java error in your action class.


I couldn't figure it out ...:-(



Let me rephrase my question:
How does the JSP obtain the list named "states"?
 
    Bookmark Topic Watch Topic
  • New Topic