在为医院开发演示erp Web应用程序时遇到了primefaces组件<p:commandButton>
的问题,它不会将请求发送到服务器到指定的方法。我将Spring Core与hibernate和primefaces集成在一起。
Here is main.xhtml
this page resposible for getting the required tab to show on screen
<pe:layout fullPage="true" options="#{mainService.layoutOptionsOne}" rendered="true" state="true">
<pe:layoutPane position="west">
<p:accordionPanel value="#{accordionPanelController.tabs}" var="accordionTab">
<p:tab title="#{accordionTab.title}">
<p:tree value="#{accordionTab.rootNode}" var="data">
<p:treeNode>
<h:form id="form">
<p:commandLink value="#{data.sectionLabel}"
update=":tabView :tabView:#{tabController.activeTabIndex}:tab"
actionListener="#{tabController.openTab(data.screenId)}" />
</h:form>
</p:treeNode>
</p:tree>
</p:tab>
</p:accordionPanel>
</pe:layoutPane>
<pe:layoutPane id="tabLayout" position="center">
<p:tabView id="tabView" value="#{tabController.tabs}" var="tab" dynamic="true"
activeIndex="#{tabController.activeTabIndex}"
onTabClose="#{tabController.closeTab(tab.screenId)}" scrollable="true">
<p:tab id="tab" title="#{tab.title}" closable="#{tab.closable}">
<p:panel rendered="#{tab.screenId == 'DEFAULT'}" style="border:none;">
<ui:include src="/default.xhtml" />
</p:panel>
<p:panel rendered="#{tab.screenId == 'DOCTOR_TAB'}">
<ui:include src="/doctor/doctor-list-tab.xhtml" />
</p:panel>
</p:tab>
</p:tabView>
</pe:layoutPane>
</pe:layout>
医生一览tab.xhtml 此页面负责显示所有医生的列表,并提供用于创建新医生和编辑现有医生的按钮
<!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:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui" xmlns:pe="http://primefaces.org/ui/extensions">
<h:head>
<style type="text/css">
.ui-ribbon .ui-colorpicker .ui-button {
height: 24px;
}
.ui-ribbon .ui-ribbon-group .ui-ribbon-group-content {
height: 4em;
padding: 0.2em 0.2em 0;
}
.ui-icon.ui-ribbonicon-new {
margin-left: -10px;
margin-top: -20px;
background-image: url("#{resource['icons/new.png']}");
}
.ui-icon.ui-ribbonicon-save {
background-image: url("#{resource['icons/save.png']}");
}
.ui-icon.ui-ribbonicon-paste {
background-image: url("#{resource['icons/paste.png']}");
}
.ui-widget .ui-widget {
font-size: 0.9em;
}
.ui-icon.ui-ribbonicon-cut {
background-image: url("#{resource['icons/cut.png']}");
}
.ui-icon.ui-ribbonicon-print {
background-image: url("#{resource['icons/print.png']}");
}
.ui-icon.ui-ribbonicon-zoomin {
background-image: url("#{resource['icons/zoomin.png']}");
}
.ui-icon.ui-ribbonicon-zoomout {
background-image: url("#{resource['icons/zoomout.png']}");
}
.ui-tabs-nav.ui-helper-reset.ui-helper-clearfix.ui-widget-header.ui-corner-all {
width: auto;
}
.ui-ribbon-group-content {
height: 70px;
}
</style>
</h:head>
<h:body>
<p:ribbon style="width:auto; height:auto;">
<p:tab title="File">
<p:ribbonGroup label="Options" id="options">
<p:commandButton value="New" action="#{doctorListTabController.newRecord}"
styleClass="ui-ribbon-bigbutton" icon="ui-ribbonicon-new" process="@this" />
<p:commandButton value="Save" icon="ui-ribbonicon-save" styleClass="ui-ribbon-bigbutton" />
</p:ribbonGroup>
</p:tab>
</p:ribbon>
<p:dataTable id="doctors" var="doctor" value="#{doctorListTabController.doctors}"
draggableColumns="true" resizableColumns="true" style="margin-top:20px" selectionMode="single"
selection="#{doctorListTabController.selectedRecord}" rowKey="#{doctor.id}" paginator="true">
<f:facet name="header">
List of Doctors
</f:facet>
<p:ajax event="rowSelect" listener="#{doctorListTabController.onRecordSelect}"
update=":tabView:#{tabController.activeTabIndex}:doctors" />
<p:column headerText="Id">
<h:outputText value="#{doctor.id}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{doctor.name}" />
</p:column>
<p:column headerText="Age">
<h:outputText value="#{doctor.age}" />
</p:column>
<p:column headerText="address">
<h:outputText value="#{doctor.address}" />
</p:column>
<p:column headerText="mobile">
<h:outputText value="#{doctor.mobile}" />
</p:column>
<p:column headerText="email">
<h:outputText value="#{doctor.email}" />
</p:column>
<p:column headerText="gender">
<h:outputText value="#{doctor.gender}" />
</p:column>
<p:column headerText="Scoiality">
<h:outputText value="#{doctor.sociality}" />
</p:column>
<p:column headerText="Degree">
<h:outputText value="#{doctor.degree}" />
</p:column>
<p:column headerText="SSN">
<h:outputText value="#{doctor.ssn}" />
</p:column>
</p:dataTable>
</h:body>
</html>
DoctorListTablController.java
package com.admin.doctor.controller;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.primefaces.context.RequestContext;
import org.primefaces.event.SelectEvent;
import org.springframework.transaction.annotation.Transactional;
import com.server.doctor.Doctor;
import com.server.doctor.DoctorManagerImpl;
public class DoctorListTabController implements Serializable{
private static final long serialVersionUID = 1L;
private List<Doctor> doctors;
private DoctorManagerImpl doctorManager;
private Doctor selectedRecord;
public DoctorListTabController() {
init();
}
private void init() {
}
@Transactional
public List<Doctor> getDoctors() {
return doctorManager.load(Doctor.class);
}
@Transactional
public List<Doctor> loadAll() {
return doctorManager.load(Doctor.class);
}
public void setDoctors(List<Doctor> doctors) {
this.doctors = doctors;
}
public DoctorManagerImpl getDoctorManager() {
return doctorManager;
}
public void setDoctorManager(DoctorManagerImpl doctorManager) {
this.doctorManager = doctorManager;
}
public void onRecordSelect(SelectEvent event) {
System.out.println(((Doctor) event.getObject()).getId());
}
public Doctor getSelectedRecord() {
return selectedRecord;
}
public void setSelectedRecord(Doctor selectedRecord) {
this.selectedRecord = selectedRecord;
}
public void newRecord() {
Map<String,Object> options = new HashMap<String, Object>();
options.put("modal", true);
options.put("width", 640);
options.put("height", 340);
options.put("contentWidth", "100%");
options.put("contentHeight", "100%");
options.put("headerElement", "customheader");
RequestContext.getCurrentInstance().openDialog("/doctor/new-doctor.xhtml", options, null);
}
}
其实我不知道为什么<p:commandButton>
没有调用newMethod
如果有人帮助我,我会感激的 提前谢谢。