我是新主題JSF並開發一個簡單的web對話框: 我目前的問題是:我的selectOneMenu組件不會觸發actionListener,也不會重新發送其他組件。 這是我的JSF頁面:<h:selectOneMenu>不會觸發actionListener
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="cache-control" content="no-cache, must-revalidate">
<link href='styles/kn.css' rel="styleSheet" type="text/css" />
</head>
<style>
.top {
vertical-align: top;
}
</style>
<body>
<f:view>
<f:loadBundle basename="messages" var="msg" />
<h:form id="navigation">
<%@include file="include/kn_header.jsp"%>
</h:form>
<h:form >
<rich:panel styleClass="mainPanel" header="#{msg.log_title}"
id="logviewer">
<h:selectOneMenu value="#{logviewer.machine} " onchange="submit()" immediate="true">
<f:selectItems value="#{logviewer.machineList}" />
<a4j:support event="onchange"
actionListener="#{logviewer.processValueChanged}"
ajaxSingle="true" immediate="true" reRender="progressPanel" />
</h:selectOneMenu>
<rich:spacer height="10px" />
<a4j:outputPanel id="progressPanel"
rendered="#{logviewer.isMachine}">
<rich:progressBar value="#{logviewer.currentValue}" interval="1000"
label="#{logviewer.currentValue} %" enabled="#{logviewer.enabled}"
minValue="-1" maxValue="100" reRenderAfterComplete="progressPanel">
<f:facet name="initial">
<br />
<a4j:commandButton action="#{logviewer.startProcess}"
value="Start Download" reRender="progressPanel"
rendered="#{logviewer.buttonRendered}"
style="margin: 9px 0px 5px;" />
</f:facet>
<f:facet name="complete">
<br />
<rich:spacer height="10px" />
<a4j:commandButton id="doDownload"
action="#{logviewer.doDownload}" value="button"
alt="#{msg.download}" title="#{msg.download}"
image="#{icon.download}">
<rich:toolTip value="#{msg.download}"
style="background-color:#{richSkin.generalBackgroundColor}; border-color:#{richSkin.headerBackgroundColor}">
</rich:toolTip>
</a4j:commandButton>
<div class="TextArea">
<rich:panel styleClass="mainPanel">
<h:inputTextarea id="logView" value="#{logviewer.log}"
rows="35" style="font-size:10pt; width:100%" readonly="true" />
</rich:panel>
</div>
</f:facet>
</rich:progressBar>
</a4j:outputPanel>
</rich:panel>
</h:form>
</f:view>
</body>
</html>
和票數是我的豆:
package com.kn.documentserver.jsf;
import java.util.ArrayList;
import java.util.List;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import com.kn.commons.util.BeanLocator;
import com.kn.dcs.distribution.DownloadFile;
import com.kn.documentserver.entity.Machine;
import com.kn.documentserver.interfaces.IMachine;
public class LogviewerBean extends AbstractBean {
// private final static Logger LOG =
// Logger.getLogger(AdministrationBean.class);
private List<SelectItem> machineList;
private Machine machine;
private int maxlength;
private String logfile= null;
private DownloadFile logFile;
private boolean buttonRendered = true;
private boolean enabled = false;
IMachine s = BeanLocator.lookup(IMachine.class,
"java:global/KN_DocumentServerFrontendJBoss/MachineBean");
public LogviewerBean() {
super();
machineList = new ArrayList<SelectItem>();
initMachineList(readMachineList());
}
private List<Machine> readMachineList() {
return s.findAll();
}
private void initMachineList(List<Machine> machines) {
for (Machine m : machines) {
if (m.getMachineName().contains("KN")
&& !m.getMachineName().equals("ASKNGHST")
&& !m.getMachineName().equals("ASKNITRA")) {
SelectItem item= new SelectItem(m.getMachineName(),m.getMachineName());
machineList.add(item);
}
}
}
public List<SelectItem> getMachineList() {
return machineList;
}
public void changeEvent() {
System.out.println("Works");
}
public void setMachineList(List<SelectItem> machineList) {
this.machineList = machineList;
}
public Machine getMachine() {
return machine;
}
public String getLog() {
return logfile;
}
// public GenericConverter getMachineConverter() {
//
// return new GenericConverter(machineList.values());
// }
public void setMachine(Machine machine) {
this.machine = machine;
}
public String processValueChanged(ValueChangeEvent vce) {
String temp = (String) vce.getNewValue();
this.machine=s.findByName(temp);
return null;
}
public void doshowLog() {
setMachine(this.machine);
}
public int getMaxlength() {
return maxlength;
}
public void setMaxlength(int maxlength) {
this.maxlength = maxlength;
}
public boolean getIsMachine() {
return (this.machine == null) ? false : true;
}
public String getLogfile() {
return logfile;
}
public String startProcess() {
setEnabled(true);
setButtonRendered(false);
logFile = new DownloadFile(machine);
System.out.println(getTotalValue());
logFile.start();
return null;
}
public void setLogfile() {
byte[] bytes = logFile.getLogfileAsbyte();
if (bytes != null) {
this.logfile = new String(bytes);
}
}
public boolean getIsLogfileDownloaded() {
return (this.logfile == null) ? false : true;
}
public long getTotalValue() {
return logFile.getFilelength();
}
public Long getCurrentValue() {
if (isEnabled()) {
Long current = new Long(logFile.getCurrfilelength());
current = (current * 100)/getTotalValue();
if (current >= 100) {
setButtonRendered(true);
setLogfile();
return Long.valueOf(101);
} else {
return current;
}
} else {
return Long.valueOf(-1);
}
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isButtonRendered() {
return buttonRendered;
}
public void setButtonRendered(boolean buttonRendered) {
this.buttonRendered = buttonRendered;
}
}
能否請你幫我調查,究竟怎麼了?。
親切的問候 亞歷
你正在使用哪個版本的JSF? – 2013-03-19 10:53:07
我認爲2.0 –
user2186105
2013-03-19 10:56:06
請找出確切的JSF版本。所有代碼都採用JSF 1.2風格,而您使用的是JSP而不是Facelets,而JSP自JSF 2.0以來已棄用。 – BalusC 2013-03-19 12:17:24