aspose file tools*
The moose likes Struts and the fly likes Alert box issue in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Alert box issue in Struts" Watch "Alert box issue in Struts" New topic
Author

Alert box issue in Struts

Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi Ranchers and Moderators,

I'm using Struts for Controller,i.e presentation tier.
IBatis as a Persistence Framework .

Action class --> Service class --> Ibatis .xml file --> Database(SQL Sever 2000)

I have implemented a Save operation In Service class which inserts a record in database.
When the record is successfully inserted into database.

I want to show a Dialog box i.e an alert box saying
"Records are Saved Successfully" else an alert box "Save Operation Unsuccessful",in case records are not saved.

How do i implement this feature in Struts along with Ibatis Framework Integration
Please help........



after insert operation i want to return a value determining whether save is successful or not?? how to proceed.


how should this part be implemented in jsp i.e displaying an alert box depending on some condition.....please help me (in my case return value) ???





Deepak


When The Going Gets Tougher,The Tougher gets Going
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Include some sort of flag and run some JavaScript based on the value of that flag?
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

David,
COuld you please help jme further....

David wrote: Include some sort of flag and run some JavaScript based on the value of that flag?



My interpretation::

I have a flag in action class.i get true or false
------------------
Action class
---------------------
boolean flag = true;
then i redirect to mapping.findforward(Save.jsp); //ok im done with this


Clarifications.::
1> how do i proceed to write the logic in jsp with javascript functionality....i mean how do i mix both javascript and checking the flag condition in jsp
2> Bsed on 1st result, when i get the alert("records saved successfully") how do i proceed to someother page "MainMenu.jsp" ,when the user clicks on "Ok" button of the alert box.




Please help me....
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Hi David,
Could you please help me with this....any snippet of code to achieve this



Thanks and Regards
Deepak Lal
Deepak Lal
Ranch Hand

Joined: Jul 01, 2008
Posts: 507

Sorry for replying again,but could you help me on this issue
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

This doesn't seem to be too difficult to implement. I can't figure out which version of Struts you are using so I'm assuming Struts 2. From SaveAction, you need a way to pass a flag to the JSP indicating whether the insert operation was successful or not. You can do this simply by having a property in SaveAction action. In the JSP, use s:if and s:else tags to generate an alert box depending on whether the insert was successful. Then you can use the window.location in javascript to redirect the user to MainMenu.jsp (example). So Save.jsp would look something like this


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What are you having difficulty with? All you need to do is put the JavaScript code in the JSP and use JSP EL to decide which alert box to show.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Alert box issue in Struts