Reputation: 427
This is my first PrimeFaces project, I am using Primefaces 5.2. I put some form/action in my list page roleList.xhtml such as:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head/>
<h:body>
<ui:composition template="/WEB-INF/ozssc-template.xhtml">
<ui:define name="content">
<h3>#{clientrole['web.role.list.heading']}</h3>
<p:toolbar>
<p:toolbarGroup>
<h:panelGrid columns="3">
<p:button value="#{apps['applicaiton.nav.backtomain']}" outcome="/index.xhtml" icon="fa fa-fw fa-home" type="button"/>
<h:form><p:commandButton value="#{clientrole['web.role.label.new']}" action="#{roleControlBean.createRole()}" icon="fa fa-fw fa-plus-square" ajax="false" type="submit"/></h:form>
</h:panelGrid>
</p:toolbarGroup>
</p:toolbar>
<p:dataTable id="rolelist" var="role" value="#{roleBean.roles}" rows="20" paginator="true" tableStyle="width:auto" resizableColumns="true" liveResize="true">
<f:facet name="header">Size of #{clientrole['web.role.table.name']} #{roleBean.roles.size()}</f:facet>
<!--<p:column headerText="#{clientrole['web.role.label.id']}"><h:link value="#{role.roleId}" outcome="#{roleControlBean.viewRole(role.roleId)}" /></p:column>-->
<p:column headerText="#{clientrole['web.role.label.id']}"><h:form><h:commandLink value="#{role.roleId}" action="#{roleControlBean.viewRole(role)}" /></h:form></p:column>
<!--<p:column headerText="#{clientrole['web.role.label.id']}">#{role.roleId}</p:column>-->
<p:column headerText="#{clientrole['web.role.label.name']}">#{role.roleName}</p:column>
<p:column headerText="#{clientrole['web.role.label.desc']}">#{role.roleDescription}</p:column>
<p:column headerText="#{clientrole['web.role.label.reportto']}">#{role.roleReportto}</p:column>
<p:column headerText="#{clientrole['web.role.label.function']}">#{role.roleFunction}</p:column>
</p:dataTable>
</ui:define>
</ui:composition>
</h:body>
</html>
my back bean method as:
@Named(value = "roleControlBean")
@SessionScoped
public class RoleControlBean implements Serializable{
private static final String ROLE_EDIT="/role/roleEdit.xhtml";
.......
public String createRole(){
Role newrole = new Role();
newrole.inited();
/*logger.info(newrole != null?newrole.toString():"no role created by constructor.");*/
roleRemote.create(newrole);
if (roleBean.findRoleInCache(newrole.getRoleId())!=null){
roleBean.setCurrentRole(newrole);
}
return ROLE_EDIT;
}
.......
}
As previous code shows, xhtml will generate a button to be pressed to call backing bean's createRole() method to create a role and then navigate to roleEdit.xhtml. But unfortunately, every time when I access or refresh roleList.xhtml. The backing bean method was called to created a new role object, that means the form/action was execute without button pressing to fire the backing bean action but the UI still stay in roleList.xhtml.
Does anyone have more experience on PrimeFaces developing please point out what's wrong I am doing?
Edit: This page will load template.xhtml as well. When I used link/outcome to call other backing method in other page, it happen again:
<p:link id="personid" value="#{clientperson['web.person.label.new']}" outcome="#{personControlBean.createPersonFromStaff(staffBean.currentStaff.staffId)}"
ajax="false" rendered="#{empty staffBean.currentStaff.personId}"><f:attribute name="staffId" value="#{staffBean.currentStaff.staffId}"/>
</p:link>
My question is: How I can prevent linkage/buttons not auto fired on page load??
Newly Added My application server is Weblogic 12cR2. I already saw BalusC's answer to similar question. It not work in my case, I don't know why. Please advise some more explain why the linkage/button was execute when page loaded, and how to prevent it happen again and again?
Upvotes: 0
Views: 33