2

I wrote a jsf application, this app inserts the data into mysql database and shows some of the inserted details in another page.

I am successful in inserting the values into database, but unable to redirect to the other page even after writing the navigation rule.

My action code

<div align="center"><p:commandButton label="Submit" action="#{userData.add}" align="center" ajax="false" /></div> 

Navigation rule

<managed-bean> <managed-bean-name>UserData</managed-bean-name> <managed-bean-class>userData.UserData</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> <navigation-rule> <display-name>home.xhtml</display-name> <from-view-id>/home.xhtml</from-view-id> <navigation-case> <to-view-id>/badge.xhtml</to-view-id> </navigation-case> </navigation-rule> 

If i write the face-redirect true then its showning an error, or if i write the action to the other page then its not inserting the values to database.

4
  • No in the action property of command button like this action="#userData.add?faces-redirect=true" Commented May 29, 2015 at 18:29
  • I wrote <redirect/> but still the page is not navigating now my faces-config.xml looks like this <navigation-case> <to-view-id>/badge.xhtml</to-view-id> <redirect/> </navigation-case> Commented May 29, 2015 at 18:39
  • I executed the insert sql statement in add method , can you tell me how to write <from-outcome> Commented May 29, 2015 at 18:56
  • Now i added action listener for command button and wrote a method in class like this public String edit(){ return "badge"; } Commented May 29, 2015 at 19:15

1 Answer 1

2

Stop reading JSF 1.x resources and get rid of all that JSF 1.x-style <managed-bean> and <navigation-rule> entries in faces-config.xml.

The proper JSF 2.x approach for your action="#{userData.add}" is as below:

@ManagedBean @ViewScoped public class UserData { public String add() { // ... return "/badge.xhtml?faces-redirect=true"; } } 

No additional XML mess needed. Also no action listeners.

Links to JSF 2.x tutorials/books can be found in our JSF wiki page.

See also:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.