I am using primefaces 3.3, have 3 components on page: data table, edit area, command button. I have 1 strange issue: when I open page, data is displayed in data table, but if I click on any of button, debugger suggests that corresponding button code is not even called. However, if I click on any record in table, edit area is populated, then if I click on buttons they start working. below is page code, i tried different options, putting all content in 1 form etc., none works. please help
<ui:define name="content">
<h:form id="form" prependId="false">
<p:growl id="growl" showDetail="true"/>
<p:dataTable id="table" var="var"
value="#{regions.list}"
selection="#{regions.selected}"
rowKey="#{var.idRegion}"
selectionMode="single"
paginator="true" rows="10"
paginatorPosition="bottom"
>
<p:ajax event="rowSelect" listener="#{regions.onRowSelect}" update=":frmEdit :form:growl" />
<p:ajax event="rowUnselect" listener="#{regions.onRowUnSelect}" update=":frmEdit :form:growl"/>
<f:facet name="header">
List of Regions
</f:facet>
<p:column sortBy ="#{var.shortName}">
<f:facet name="header">Short Name</f:facet>
<h:outputText value="#{var.shortName}" />
</p:column>
<p:column sortBy ="#{var.fullName}">
<f:facet name="header">Full Name</f:facet>
<h:outputText value="#{var.fullName}" />
</p:column>
<p:column sortBy ="#{var.created}">
<f:facet name="header">Created On</f:facet>
<h:outputText value="#{var.created}" />
</p:column>
</p:dataTable>
</h:form>
<p:panel header="Add/Edit Properties">
<h:form id="frmEdit">
<h:panelGrid id="display" columns="6" cellpadding="4" >
<h:outputText value="Short Name:" />
<h:inputText value="#{regions.selected.shortName}" />
<h:outputText value="Full Name:" />
<h:inputText value="#{regions.selected.fullName}" />
</h:panelGrid>
</h:form>
<h:form id="frmBtn">
<h:panelGrid id="command" columns="6" cellpadding="4" >
<p:commandButton id="new" value="New" actionListener="#{regions.add()}" process="@this :frmEdit" update="result :frmEdit :form" >
</p:commandButton>
<p:commandButton id="save" value="Save" actionListener="#{regions.save()}" process="@this :frmEdit" update="result :frmEdit :form" >
</p:commandButton>
<p:commandButton id="delete" value="Delete" actionListener="#{regions.delete()}" process="@this :frmEdit" update="result :frmEdit :form" >
</p:commandButton>
<p:commandButton id="refresh" value="Refresh" actionListener="#{regions.refresh()}" process="@this :frmEdit" update="result :frmEdit :form" >
</p:commandButton>
</h:panelGrid>
<p:messages id="result" showDetail="true" autoUpdate="true"/>
</h:form>
</p:panel>
</ui:define>
below is JSF MB Code:
@ManagedBean
@ViewScoped
public class Regions implements Serializable {
private List<Region> list;
private Region selected;
private @EJB RegionFacade esvc; //entity services
private FacesContext context;
private FacesMessage msg;
private boolean newRec =false;
@SuppressWarnings("OverridableMethodCallInConstructor")
public Regions() {
// context = FacesContext.getCurrentInstance();
// HttpSession session = (HttpSession)context.getExternalContext().getSession(false);
// Users user = (Users)session.getAttribute("user");
// if (user != null)
// init();
// else {
// msg = new FacesMessage("Session Expired, Return to Login Page");
// context.addMessage(null, msg);
// }
}
@PostConstruct
public void init(){
try{
list = esvc.findAll();
}catch (Exception ex){
System.out.println(ex);
}
}
public String add(){
selected = new Region();
newRec = true;
return "region";
}
public String save(){
int result;
if (newRec){
result=esvc.insert(selected);
newRec=false;
}
else{
result=esvc.update(selected);
}
refresh();
context = FacesContext.getCurrentInstance();
if (result>0){
msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"Success", "Record Saved");
refresh();
}else{
msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"Failure", "Record not Saved");
}
context.addMessage(null, msg);
return "region";
}
public String delete(){
int result;
result= esvc.delete(selected);
context = FacesContext.getCurrentInstance();
refresh();
if (result>0){
msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"Success", "Record Deleted");
refresh();
}else {
msg = new FacesMessage(FacesMessage.SEVERITY_INFO,"Failure", "Record not Deleted");
}
context.addMessage(null, msg);
return "region";
}
public void refresh(){
selected=null;
list=getList();
}
public List<Region> getList() {
return list;
}
public Region getSelected() {
return selected;
}
public void setSelected(Region selected) {
this.selected = selected;
}
public void onRowSelect(SelectEvent event) {
context = FacesContext.getCurrentInstance();
msg = new FacesMessage("Selected", ((Region) event.getObject()).getFullName());
context.addMessage(null, msg);
}
public void onRowUnSelect(UnselectEvent event) {
context = FacesContext.getCurrentInstance();
selected=null;
}
}