如何解决单击a4j:commandbutton时,方法不会执行
| 我正在使用jsf2.0,richfaces 4.0,tomcat 6.0开发应用程序。在页面上,我试图删除一行。但是,当我单击删除图标时,有时不显示弹出面板,而当它显示时,单击删除按钮没有任何反应。 以下是我的.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:h=\"http://java.sun.com/jsf/html\"
xmlns:f=\"http://java.sun.com/jsf/core\"
xmlns:c=\"http://java.sun.com/jsp/jstl/core\"
xmlns:ui=\"http://java.sun.com/jsf/facelets\"
xmlns:a4j=\"http://richfaces.org/a4j\"
xmlns:rich=\"http://richfaces.org/rich\">
<ui:composition template=\"template.xhtml\">
<ui:define name=\"metadata\">
<f:metadata>
<f:viewParam name=\"meetingId\" required=\"true\" value=\"#{meetingBean.selectedMeetId}\" />
</f:metadata>
</ui:define>
<ui:define name=\"content\">
<h3>List of Employees in selected meeting</h3>
<a4j:status onstart=\"#{rich:component(\'statPane\')}.show()\"
onstop=\"#{rich:component(\'statPane\')}.hide()\" />
<h:form>
<c:if test=\"#{! empty meetingBean.selectedMeeting}\">
<c:set target=\"#{flash}\" property=\"selectedMeeting\"
value=\"#{meetingBean.selectedMeeting}\" />
</c:if>
<c:if test=\"#{! empty flash.selectedMeeting}\">
<c:set target=\"#{meetingBean}\" property=\"selectedMeeting\"
value=\"#{flash.selectedMeeting}\" />
</c:if>
<rich:extendedDataTable value=\"#{meetingBean.selectedMeeting.employees}\" var=\"empMeet\" border=\"1\" id=\"table\">
<rich:column>
<f:facet name=\"header\">Employee Id</f:facet>
#{empMeet.empId}
</rich:column>
<rich:column>
<f:facet name=\"header\"> Employee Name</f:facet>
#{empMeet.firstName} #{empMeet.lastName}
</rich:column>
<rich:column>
<a4j:commandLink execute=\"@this\" render=\"@none\" oncomplete=\"#{rich:component(\'confirmPanel\')}.show();\">
<h:graphicImage value=\"/images/icons/delete.gif\" alt=\"delete\" />
<a4j:param value=\"#{empMeet.empId}\" assignTo=\"#{meetingBean.deleteEmpId}\" />
</a4j:commandLink>
</rich:column>
</rich:extendedDataTable>
<a4j:jsFunction name=\"removeEmp\" action=\"#{meetingBean.deleteEmployee}\" render=\"table\" execute=\"@this\"
oncomplete=\"#{rich:component(\'confirmPanel\')}.hide();\" >
</a4j:jsFunction>
<rich:popupPanel id=\"statPane\" autosized=\"true\">
<h:graphicImage value=\"/images/ai.gif\" />
Please wait...
</rich:popupPanel>
<rich:popupPanel id=\"confirmPanel\" autosized=\"true\" >
Are you sure you want to delete the row?
<a4j:commandButton value=\"Cancel\" onclick=\"#{rich:component(\'confirmPane\')}.hide(); return false;\" />
<a4j:commandButton value=\"Delete\" onclick=\"removeEmp(); return false;\" />
</rich:popupPanel>
<h:commandButton action=\"addEmpMeeting\" value=\"Invite More Employees\" />
</h:form>
</ui:define>
</ui:composition>
</html>
以下是我的bean类:
package com.drishti.apps.mommanager.meeting;
/**
* this class represents a meeting object
*/
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.event.ComponentSystemEvent;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import org.richfaces.component.SortOrder;
import com.drishti.apps.mommanager.employee.AbstractBacking;
import com.drishti.apps.mommanager.employee.EmployeeEntity;
import com.drishti.apps.mommanager.employee.EmployeeService;
@ManagedBean
public class MeetingBean extends AbstractBacking {
@ManagedProperty(value = \"#{requestScope}\")
private Map<String,Object> requestMap;
private int meetingId;
private Date meetingTime;
private String agenda;
private String result;
public String[] empIdsInMeeting;
private List<EmployeeEntity> employees = new ArrayList<EmployeeEntity>();
private Integer selectedMeetId;
private MeetingEntity selectedMeeting;
private String selectedAgenda;
private int deleteEmpId;
private EmployeeEntity deletableEmployee;
/**
* this method is used to load a meeting object when it is being updated
*
* @param cse
*/
public void loadMeeting(ComponentSystemEvent cse) {
if (null == getSelectedMeeting()) {
Integer meetId = getSelectedMeetId();
if (meetId == null) {
meetId = (Integer)getFlash().get(\"selectedMeetId\");
}
if (meetId == null) {
getFacesContext().addMessage(null,new FacesMessage(\"The meeting is invalid\"));
getFlash().setKeepMessages(true);
getFacesContext().getApplication().getNavigationHandler()
.handleNavigation(getFacesContext(),null,\"listMeetings\");
} else {
MeetingEntity meet = MeetingService.getCurrentInstance().getMeetingForId(meetId);
if (meet == null) {
getFacesContext().addMessage(null,new FacesMessage(\"The meeting is invalid\"));
getFlash().setKeepMessages(true);
getFacesContext().getApplication().getNavigationHandler()
.handleNavigation(getFacesContext(),\"listMeetings\");
} else {
getFlash().put(\"selectedMeeting\",meet);
getSelectedMeeting();
}
}
}
}
/**
* this method updates a meeting object
*
* @return
*/
public void updateMeeting() {
//String result = null;
MeetingService meetSer = MeetingService.getCurrentInstance();
MeetingEntity meeting = getSelectedMeeting();
meetSer.updateMeeting(meeting);
getFlash().clear();
//result = \"meetUpdated\";
//return result;
}
/**
* this method adds a meeting object to database
*
* @return
*/
public void addMeeting() {
MeetingEntity meeting = (MeetingEntity)getRequestMap().get(\"meetingEntity\");
MeetingService.getCurrentInstance().addMeeting(meeting);
//return \"successMeeting\";
}
/**
* this method is used to delete a meeting
*/
public void deleteMeeting(){
MeetingService meetSer = MeetingService.getCurrentInstance();
MeetingEntity meeting = getSelectedMeeting();
meetSer.deleteMeeting(meeting);
getFlash().clear();
}
/**
* returns data model containing all meetings present in database
*
* @return
*/
public DataModel<MeetingEntity> getMeetingList() {
DataModel<MeetingEntity> meetingList = new ListDataModel<MeetingEntity>(MeetingService.getCurrentInstance()
.getMeetings());
return meetingList;
}
/**
* returns list containing agenda of all meetings
*
* @return
*/
public ArrayList<String> getAgendaList() {
ArrayList<String> agendaList = new ArrayList<String>();
agendaList.add(getSelectedMeeting().getAgenda());
return agendaList;
}
/**
* this method is used to get a list of employee names for employees who are not invited to a particular meeting
*/
public List<String> getEmpNameIdList() {
List<EmployeeEntity> employeeList = new ArrayList<EmployeeEntity>(EmployeeService.getCurrentInstance()
.getEmployeeList());
List<String> uninvitedEmpList = new ArrayList<String>();
ListIterator<EmployeeEntity> empIter = employeeList.listIterator();
ArrayList<Integer> idList = new ArrayList<Integer>();
while (empIter.hasNext()) {
idList.add(empIter.next().getEmpId());
}
MeetingEntity meeting = getSelectedMeeting();
List<EmployeeEntity> employees = meeting.getEmployees();
if(employees!=null){
ListIterator<EmployeeEntity> invitedIter = employees.listIterator();
ArrayList<Integer> invitedIds = new ArrayList<Integer>();
while (invitedIter.hasNext()) {
invitedIds.add(invitedIter.next().getEmpId());
}
idList.removeAll(invitedIds);
}
EmployeeEntity emp;
ListIterator<Integer> idIter = idList.listIterator();
while (idIter.hasNext()) {
int id = idIter.next();
emp = EmployeeService.getCurrentInstance().getEmployeeForId(id);
uninvitedEmpList.add(emp.getFirstName() + \" \" + emp.getLastName() + \" (\" + emp.getEmpId() + \")\");
}
return uninvitedEmpList;
}
/**
* this method adds employees to a meeting
* @return
*/
public String addEmpToMeeting() {
MeetingEntity meeting = MeetingService.getCurrentInstance().getMeetingFromAgenda(
getSelectedMeeting().getAgenda());
for (int i = 0; i < empIdsInMeeting.length; i++) {
String id = null;
id = empIdsInMeeting[i].substring(empIdsInMeeting[i].lastIndexOf(\"(\") + 1,empIdsInMeeting[i].lastIndexOf(\")\"));
int empId = Integer.parseInt(id);
meeting.getEmployees().add(EmployeeService.getCurrentInstance().getEmployeeForId(empId));
}
MeetingService.getCurrentInstance().addMeeting(meeting);
return \"empAddedToMeeting\";
}
/**
* this method removes employee from a meeting
* @return
*/
public void deleteEmployee(){
List<EmployeeEntity>inviteEmployees=getSelectedMeeting().getEmployees();
EmployeeEntity emp=getDeletableEmployee();
inviteEmployees.remove(emp);
}
public Integer getSelectedMeetId() {
return selectedMeetId;
}
public void setSelectedMeetId(Integer selectedMeetId) {
this.selectedMeetId = selectedMeetId;
setSelectedMeeting(MeetingService.getCurrentInstance().getMeetingForId(selectedMeetId));
}
public MeetingEntity getSelectedMeeting() {
return selectedMeeting;
}
public void setSelectedMeeting(MeetingEntity selectedMeeting) {
this.selectedMeeting = selectedMeeting;
}
public Map<String,Object> getRequestMap() {
return requestMap;
}
public void setRequestMap(Map<String,Object> requestMap) {
this.requestMap = requestMap;
}
public Date getMeetingTime() {
return meetingTime;
}
public void setMeetingTime(Date meetingTime) {
this.meetingTime = meetingTime;
}
public String getAgenda() {
return agenda;
}
public void setAgenda(String agenda) {
this.agenda = agenda;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public int getMeetingId() {
return this.meetingId;
}
public List<EmployeeEntity> getEmployees() {
return employees;
}
public String[] getEmpIdsInMeeting() {
return empIdsInMeeting;
}
public void setEmpIdsInMeeting(String[] empIdsInMeeting) {
this.empIdsInMeeting = empIdsInMeeting;
}
public void setEmployees(List<EmployeeEntity> employees) {
this.employees = employees;
}
public String getSelectedAgenda() {
return selectedAgenda;
}
public void setSelectedAgenda(String selectedAgenda) {
this.selectedAgenda = selectedAgenda;
}
public void setTimeOrder(SortOrder timeOrder) {
this.timeOrder = timeOrder;
}
public int getDeleteEmpId() {
return deleteEmpId;
}
public void setDeleteEmpId(int deleteEmpId) {
this.deleteEmpId = deleteEmpId;
setDeletableEmployee(EmployeeService.getCurrentInstance().getEmployeeForId(deleteEmpId));
}
public EmployeeEntity getDeletableEmployee() {
return deletableEmployee;
}
public void setDeletableEmployee(EmployeeEntity deletableEmployee) {
this.deletableEmployee = deletableEmployee;
}
}
请帮忙 。
解决方法
该问题可能与JSF覆盖您的自定义onclick有关。
解决方法是使用onmousedown而不是onclick,并在此处描述潜在的警告:
http://blogs.oracle.com/jtb/entry/jsf_h_commandlink_and_onclick
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。