我正在尝试基于表单提交启用和禁用按钮的简单示例。如果有人也可以指出 jsf:id 的概念,因为我正在将纯 html5 与 jsf 混合。
以下是相关代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://java.sun.com/jsf"
xmlns:f="http://java.sun.com/jsf/core">
<head jsf:id="head">
<title>Putting it all together </title>
<!-- script jsf:target="body" jsf:name="js.js"/>
<link jsf:name="css.css" rel="stylesheet" type="text/css" /-->
</head>
<body jsf:id="body">
<form jsf:id="form" jsf:prependId="false">
<label jsf:for="name">Name </label>
<input jsf:id="name" type="text" jsf:value="#{complex.name}">
<f:ajax execute="@this" render="progress"/>
</input>
<label jsf:for="tel">Tel </label>
<input jsf:id="tel" type="tel" jsf:value="#{complex.tel}">
<f:ajax execute="@this" render="progress"/>
</input>
<label jsf:for="email">Email </label>
<input jsf:id="email" type="email" jsf:value="#{complex.email}">
<f:ajax execute="@this" render="progress"/>
</input>
<label for="progress">Progress </label>
<progress jsf:id="progress" max="3">#{complex.progress} of 3 </progress>
<input jsf:id="submit" type="submit" value="submit">
<f:ajax execute="@this" render="login" event="click" listener="#{complex.process}" />
</input>
<!-- label jsf:id="status"></label-->
<button jsf:id="login" disabled="#{complex.status}">Login</button>
</form>
</body>
</html>
托管 bean 是:
package mypackage.bean;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;
@ManagedBean
@SessionScoped
public class Complex implements Serializable {
public Complex() {}
private String name;
private String tel;
private String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
private boolean status;
public void process(AjaxBehaviorEvent event) {
status = !status;
}
public boolean isStatus() {
return status;
}
public boolean getStatus() {
return status;
}
public void setStatus(boolean status) {
this.status = status;
}
public String getProgress() {
int progress = 0;
if(name != null) {
progress++;
}
if(tel != null) {
progress++;
}
if(email != null) {
progress++;
}
return progress + "";
}
}
这是打印到网页的错误:
HTTP Status 500 - java.lang.Boolean cannot be cast to java.lang.String
type Exception report
message java.lang.Boolean cannot be cast to java.lang.String
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.Boolean cannot be cast to java.lang.String
javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
root cause
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
com.sun.faces.renderkit.html_basic.HtmlResponseWriter.getAttributeValue(HtmlResponseWriter.java:1210)
com.sun.faces.renderkit.html_basic.HtmlResponseWriter.flushAttributes(HtmlResponseWriter.java:1170)
com.sun.faces.renderkit.html_basic.HtmlResponseWriter.closeStartIfNecessary(HtmlResponseWriter.java:1112)
com.sun.faces.renderkit.html_basic.HtmlResponseWriter.writeText(HtmlResponseWriter.java:935)
com.sun.faces.facelets.compiler.LiteralTextInstruction.write(LiteralTextInstruction.java:76)
com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:900)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1847)
javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:900)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1847)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:202)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.35 logs.
Apache Tomcat/7.0.35