File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts action not returning page on first click of button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts action not returning page on first click of button" Watch "Struts action not returning page on first click of button" New topic
Author

Struts action not returning page on first click of button

Frank Serkland
Ranch Hand

Joined: Jun 21, 2010
Posts: 106
I have a couple of Struts forms representing poll questions. When the user chooses an option and submits, the vote is supposed to be processed, and the original page is updated to show the results rather than the original form. I am having to click twice to get the results to be shown. Below is the relevant code. Can anyone help me? Let me know if you need to see any other files.

Here is the JSP with the forms:


Here is one of the DAO classes. Both update the database correctly after each click. I'm just having to click twice, and I only want one click.


Here is my struts.xml:
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9319
    
  17

Its hard to say what the problem is without the action code. Also you are setting HTTP Cookies in a DAO class?? This is a very bad design. Also each time the tallyVote method is called, hibernate is configured and session factory is built. Hibernate configuration should happen only once and then you can store the SessionFactory object in your DAO class (actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes). Again a bad design...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Frank Serkland
Ranch Hand

Joined: Jun 21, 2010
Posts: 106
Ankit Garg wrote:Its hard to say what the problem is without the action code.


Here is the action code.


Ankit Garg wrote:Also you are setting HTTP Cookies in a DAO class?? This is a very bad design.


Why is it a bad design? Please suggest something better.

Ankit Garg wrote:so each time the tallyVote method is called, hibernate is configured and session factory is built. Hibernate configuration should happen only once and then you can store the SessionFactory object in your DAO class


I'm not entirely sure what you mean here. Please explain

Ankit Garg wrote:(actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes). Again a bad design...


Again, please elaborate why this is a bad design and what would be better.
Frank Serkland
Ranch Hand

Joined: Jun 21, 2010
Posts: 106
Ankit Garg wrote:Also you are setting HTTP Cookies in a DAO class?? This is a very bad design.


I've put the cookies in the action class in the presumption that's better. I would still like an explanation as to why the cookies should not be in the DAO class.

Ankit Garg wrote:Also each time the tallyVote method is called, hibernate is configured and session factory is built. Hibernate configuration should happen only once and then you can store the SessionFactory object in your DAO class (actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes). Again a bad design...


Please explain why what I did is bad and what is better. I am still having the same problem.
Frank Serkland
Ranch Hand

Joined: Jun 21, 2010
Posts: 106
Ankit Garg wrote:(actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes)


So where do I store this class in my file system? When would it be called? How would it be called? Google searches aren't telling me this.
Frank Serkland
Ranch Hand

Joined: Jun 21, 2010
Posts: 106
Ankit Garg wrote:(actually there should be a separate class to manage hibernate configuration and SessionFactory which is used by all DAO classes)


Never mind. I'll look elsewhere.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts action not returning page on first click of button