I have a problem with navigating the pages through buttons.
My current xhtml snippet is like that:
<p:layoutUnit position="west" size="200" header="Menü" resizable="true" closable="true" collapsible="true">
<p:column>
<p:commandButton type="button" value="New Project" icon="ui-icon-document" action="#{createProject.create()}"/>
<p:commandButton type="button" value="All Projects" icon="ui-icon-folder-open"/>
<p:commandButton type="button" value="Edit" icon="ui-icon-pencil"/>
<p:commandButton type="button" value="Delete" icon="ui-icon-closethick"/>
<p:separator />
<p:commandButton type="button" title="Yazdır" icon="ui-icon-print"></p:commandButton>
</p:column>
</p:layoutUnit>
Here, when I click on New Project it doesn't navigate to related page.
My beanfile:
@ManagedBean
@RequestScoped
public class CreateProject {
/**
* Creates a new instance of CreateProject
*/
public String create() {
return "newproject.xhtml";
}
}
How can I navigate user when the button is clicked?
edit: here is my faces-config
<faces-config
version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<managed-bean>
<managed-bean-name>loginBean</managed-bean-name>
<managed-bean-class>com.ibb.source.LoginBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>myProjects</managed-bean-name>
<managed-bean-class>com.ibb.source.MyProjects</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>myCalendar</managed-bean-name>
<managed-bean-class>com.ibb.source.MyCalendar</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/panel.xhtml</from-view-id>
<navigation-case>
<from-outcome>create</from-outcome>
<to-view-id>newproject.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>createProject</managed-bean-name>
<managed-bean-class>com.ibb.source.CreateProject</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>inPlaceEditor</managed-bean-name>
<managed-bean-class>com.ibb.source.InPlaceEditor</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>projectsList</managed-bean-name>
<managed-bean-class>com.ibb.source.ProjectsList</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>panel.xhtml</from-view-id>
<navigation-case>
<from-outcome>newproject</from-outcome>
<to-view-id>/newproject.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>allProjects</managed-bean-name>
<managed-bean-class>com.ibb.source.AllProjects</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>allProjectsList</managed-bean-name>
<managed-bean-class>com.ibb.source.AllProjectsList</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
This code:
type="button"
makes commandbutton a simple javascript trigger. If you want to do anything on the server, you must remove type="button". Also, your method defined on action tag, must return a string corresponding to your desired view, and you don`t need yo use an xml for defining navigation. Have a nice day!
By default, commandButton component of the PrimeFaces, uses ajax to send the commands so navigations won't work. Set the ajax property to false:
<p:commandButton ajax="false" value="New Project" icon="ui-icon-document" action="#{createProject.create()}" />
Also make sure that your buttons are inside a form element. Put a <h:form> ... </h:form> around your whole <p:layoutUnit> tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With