• 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

Confirm message on submit

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

I am new to JSF. With some basic knowledge in JSF i tried implementing a screen.
I am stuck with a javascript confirm message on load of the page.

Screen Functionality:

Employee.jsf having name & no. should load first.
Validation must be done only in the server side. Ajax not recommended.
If the validation is successful it should navigate to success.jsp.
Else it should display an confirm box with message "Data invalid, want to continue?"
1. If user chooses OK it should redirect to success.jsp
2. If user chooses Cancel it should retain in the same page

Please review the below code and suggest me a solution to attain the above functionality.

Thanks,

Code (simulates the functionality except the confirm message):
Bean Class:

jsp:

faces config:

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ganesh,

As per your faces-config, on the save action (which gives 'index' as the result) it goes to /pages/inputname.jsp, not to success.jsp.
And you are calling the validate function on page load.

# /**
# * Unable to reach this method. Please help.
# * @return
# */



You are not calling this method anywhere.
(You commented out the line where you specify the form action as this method.)
Where are you stuck? Did you get the confirm dialog? What happens when you press the OK/Cancel button?


Are you populating the validate field to 'false' from the backing bean?
In the if statement, alert the value of document.getElementById('empForm:validate').value

Also, if you want to stay in the same page, you don't need to submit the page, just return false from the method. Submitting the page will reload the page again, which is not welcome by many (One of the reasons I love ajax, for you don't need to reload the full page.)
Why is ajax not recommended? I am just asking out of curiosity.
 
Ganesh Rangan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.


As per your faces-config, on the save action (which gives 'index' as the result) it goes to /pages/inputname.jsp, not to success.jsp.



I am terribly sorry that was a copy paste mistake. It should be success.jsp

2.


You are not calling this method anywhere.
(You commented out the line where you specify the form action as this method.)
Where are you stuck? Did you get the confirm dialog? What happens when you press the OK/Cancel button?



I commented out since it doesn't set the action.
Yes, i got the confirm dialog but when i click on OK it submits the form but doesn't call the navigate method. Cancel button works fine.

I am stuck after clicking on OK button in the confirm dialog. I expected clicking OK should take me to navigate method (in bean class) but unfortunately it didn't happen from javascript submit.
//document.forms[0].action="#{Employee.navigate}";
or I don't know how to submit my page from javascript (equivalent to JSF action submit, redirecting to the specified method in the bean class).

3.


Are you populating the validate field to 'false' from the backing bean?


Yes, even javascript alert returns false when validation fails.

4. Ajax.
I have shown you with a simple example. In the actual application it has 10 input fields with validation hitting the db for every field. hence i considered ajax might slowdown.
Since app. is cross browser, client has suggested to use minimal js.

Hope i have answered your questions.

Any help on this would be greatly helpful.

Thanks,
Ganesh


 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this the working code?
 
Ganesh Rangan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes the Employee code that is posted is the working code.
100% Tested.

You can copy&paste this code and execute.

Modification reqd are.
1. Generate getter & setter in Employee class
2. Create success.jsp

 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay Ganesh. I am testing it. I hope to point out the error.

Regards,
Teena
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, your faces-config misses managed bean 'Employee'. Sorry, my mistake, you have it.
Add it also. Are you sure the code is working? jsp doesn't allow you to give '#' for el. you should use '$' in jsp.
 
Ganesh Rangan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<managed-bean-name>Employee</managed-bean-name>
<managed-bean-class>Employee</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>



I have used it 'Employee' as the managed bean class name.

moreover i am using # and not $ its working for me. i guess $ is used when we use jstl core tags.

since i copy pasted from eclipse, am very sure that i have posted only the working code.

Thanks.
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes. you are right. i just forgot that we can use jsf el in jsp also
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello Ganesh,

Have you resolved your problem? If not here is a little help:

Please add/modify the following files as below:

1. add index.jsp (its for your convenience, you can specify this as the welcome file, and include your employee.jsp in it. so that it will forward the request to the employee.jsp)

2. web.xml



3.faces-config.xml



4. employee.jsp



Hope this helps,
Teena
 
Ganesh Rangan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Teena,

Thanks a lot for the help.
yesterday i found the work around for it.

Thanks,
Ganesh
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Really Good Ganesh!
Can you describe the way you have resolved it?

Thanks,
Teena
 
Ganesh Rangan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Problem Definition:
On load of the page a confirm box will be displayed (if validation fails).
When user clicks on OK in confirm box it should submit the page (call a method in the bean class) and redirect to success.jsp.

Actual result:
Clicking on OK submits the page but calls only constructor and stays in the same page.

Resoultion:
Created another button (made it hidden) and when user clicks OK the click event of button is called.



Thanks,
Ganesh
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I feel that is a bad style of coding, hiding a button and calling it for click event of another button. Action method alone (with PROPER navigation rules) will help you to redirect to the next page.

Regards,
Teena
 
Ganesh Rangan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yes, you are right. That was a bad fix but i didn't get the proper solution yet.
Coming to your solution, it talks about showing confirm dialog on click of a button (before submit). Simple way of handling events before submitting the page.
The problem i posted was different

You can try showing a confirm box on load of the page, then try hitting your bean class method (after clicking on OK button). Probably you will face the same issue what i am trying to explain

Thanks,
Ganesh
 
Teena George
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay will try to find another way around for you.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic