我是新来的话题JSF和开发一个简单的web对话框:我目前的问题是:我的selectOneMenu组件不触发actionListener,也不渲染其他组件。这是我的JSF页面:
<!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>
和he is my Bean:
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 1.2或更高版本,请在第二个表单(包含selectOneMenu)中添加prependId="false"。否则(使用1.2之前的JSF),为表单设置id并将其添加到renderer (renderer ="formId:progressPanel")