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.

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

1 Answers1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555