Navigating to another page JSF

纵然是瞬间 提交于 2021-01-04 07:59:30

问题


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.


回答1:


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:

  • How to choose the right bean scope?
  • How to navigate in JSF? How to make URL reflect current page (and not previous one)
  • Differences between action and actionListener


来源:https://stackoverflow.com/questions/30536572/navigating-to-another-page-jsf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!