当我在加载 index.xhtml 页面后尝试此代码时,这是我的欢迎页面(并且页面 strana1.xhtml 最初包含为 p:outputPanel“sadrzaj”的内容)并单击按钮“Napred”(表示转发)一切正常很好,我得到了p:outputPanel id =“sadrzaj”的ajax更新(页面strana2.xhtml加载并替换index.xhtml页面内的页面strana1.xhtml,在p:outputPanel“sadrzaj”下)。但在此之后,radioButtons(它是页面 strana2.xhtml 的一部分)的任何更改都不会触发任何 ajax 请求,并且按钮“Nazad”(表示返回)也不起作用(单击后没有任何反应)。可能是什么问题?
页面索引.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:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Proba1</title>
</h:head>
<h:body>
<h:form>
<h:panelGroup id="sadrzaj">
<ui:include src="#{user.sadrzaj}"/>
</h:panelGroup>
<h:panelGrid id="dugmad" columns="2">
<p:commandButton value="Nazad" disabled="#{user.iscrtajNazad}"
actionListener="#{user.nazad}" update="sadrzaj, dugmad"/>
<p:commandButton value="Napred" disabled="#{user.iscrtajNapred}"
actionListener="#{user.napred}" update="sadrzaj, dugmad"/>
</h:panelGrid>
</h:form>
</h:body>
</html>
页面 strana1.xhtml 最初包含在 index.xhtml 中:
<?xml version='1.0' encoding='UTF-8' ?>
<!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:p="http://primefaces.org/ui">
<h:head>
<title>IGNORED</title>
</h:head>
<h:body>
<h3>Dobrodoslicu zelim svima!</h3>
<p:outputLabel for="tekst1" value="Tekst1: "/>
<p:inputText id="tekst1" value="#{user.tekst1}"/>
<br/>
<p:selectBooleanCheckbox id="personalizovana" value="#{user.personalizovana}"/>
<p:outputLabel for="personalizovana" value="personalizovana"/>
<br/>
<h:outputText value="Broj strana: "/>
<p:inputText value="#{user.brojStrana}"/>
<br/>
<p:outputLabel for="datum" value="Datum: "/>
<p:calendar id="datum" mode="popup" showOn="button" pattern="dd/MM/yyyy"
value="#{user.datum}"/>
</h:body>
</html>
页面 strana2.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!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:p="http://primefaces.org/ui">
<h:head>
<title>IGNORED</title>
</h:head>
<h:body>
<p:selectOneRadio id="izborNacinaKreiranjaAnkete"
value="#{user.izborNacinaKreiranjaAnkete}" >
<f:selectItems value="#{user.ponudaNacinaKreiranjaAnkete}"/>
<f:ajax event="change" listener="#{user.izborNacinaKreiranjaAnketeListener}"
render="sadrzajNacinaKreiranjaAnkete"/>
</p:selectOneRadio>
<br/>
<p:outputPanel id="sadrzajNacinaKreiranjaAnkete">
<h:outputText value="#{user.text}"/>
</p:outputPanel>
</h:body>
</html>
这是我的名为“用户”的 bean:
package beans;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.SelectItem;
@ManagedBean(name="user")
@SessionScoped
public class UserBean implements Serializable {
private SelectItem[] ponudaNacinaKreiranjaAnkete = {
new SelectItem("1", "postojeca pitanja"),
new SelectItem("2", "kreiraj pitanje")
};
private String sadrzaj="strana1.xhtml";
private String tekst1;
private java.util.Date datum;
private boolean bolje;
private boolean personalizovana;
private String brojStrana;
private String izborNacinaKreiranjaAnkete = "2";
private String sadrzajNacinaKreiranjaAnkete = "kreirajPitanje.xhtml";
private boolean iscrtajNazad = true;
private boolean iscrtajNapred = false;
private String text = "Drugi text";
private String homeSadrzaj = "homePrva.xhtml";
public void napred(ActionEvent e) {
setSadrzaj("strana2Proba.xhtml");
setIscrtajNazad(false);
setIscrtajNapred(true);
}
public void nazad(ActionEvent e) {
setSadrzaj("strana1.xhtml");
setIscrtajNazad(true);
setIscrtajNapred(false);
}
/**
* @return the sadrzaj
*/
public String getSadrzaj() {
return sadrzaj;
}
/**
* @param sadrzaj the sadrzaj to set
*/
public void setSadrzaj(String sadrzaj) {
this.sadrzaj = sadrzaj;
}
/**
* @return the tekst1
*/
public String getTekst1() {
return tekst1;
}
/**
* @param tekst1 the tekst1 to set
*/
public void setTekst1(String tekst1) {
this.tekst1 = tekst1;
}
/**
* @return the datum
*/
public java.util.Date getDatum() {
return datum;
}
/**
* @param datum the datum to set
*/
public void setDatum(java.util.Date datum) {
this.datum = datum;
}
/**
* @return the bolje
*/
public boolean isBolje() {
return bolje;
}
/**
* @param bolje the bolje to set
*/
public void setBolje(boolean bolje) {
this.bolje = bolje;
}
/**
* @return the iscrtajNazad
*/
public boolean isIscrtajNazad() {
return iscrtajNazad;
}
/**
* @param iscrtajNazad the iscrtajNazad to set
*/
public void setIscrtajNazad(boolean iscrtajNazad) {
this.iscrtajNazad = iscrtajNazad;
}
/**
* @return the iscrtajNapred
*/
public boolean isIscrtajNapred() {
return iscrtajNapred;
}
/**
* @param iscrtajNapred the iscrtajNapred to set
*/
public void setIscrtajNapred(boolean iscrtajNapred) {
this.iscrtajNapred = iscrtajNapred;
}
/**
* @return the personalizovana
*/
public boolean isPersonalizovana() {
return personalizovana;
}
/**
* @param personalizovana the personalizovana to set
*/
public void setPersonalizovana(boolean personalizovana) {
this.personalizovana = personalizovana;
}
/**
* @return the brojStrana
*/
public String getBrojStrana() {
return brojStrana;
}
/**
* @param brojStrana the brojStrana to set
*/
public void setBrojStrana(String brojStrana) {
this.brojStrana = brojStrana;
}
/**
* @return the izborNacinaKreiranjaAnkete
*/
public String getIzborNacinaKreiranjaAnkete() {
return izborNacinaKreiranjaAnkete;
}
/**
* @param izborNacinaKreiranjaAnkete the izborNacinaKreiranjaAnkete to set
*/
public void setIzborNacinaKreiranjaAnkete(String izborNacinaKreiranjaAnkete) {
this.izborNacinaKreiranjaAnkete = izborNacinaKreiranjaAnkete;
}
/**
* @return the ponudaNacinaKreiranjaAnkete
*/
public SelectItem[] getPonudaNacinaKreiranjaAnkete() {
return ponudaNacinaKreiranjaAnkete;
}
/**
* @param ponudaNacinaKreiranjaAnkete the ponudaNacinaKreiranjaAnkete to set
*/
public void setPonudaNacinaKreiranjaAnkete(SelectItem[] ponudaNacinaKreiranjaAnkete) {
this.ponudaNacinaKreiranjaAnkete = ponudaNacinaKreiranjaAnkete;
}
public void izborNacinaKreiranjaAnketeListener(AjaxBehaviorEvent e) {
if(izborNacinaKreiranjaAnkete.equals("1"))
text = "Prvi tekst";
else if(izborNacinaKreiranjaAnkete.equals("2"))
text = "Drugi tekst";
}
/**
* @return the sadrzajNacinaKreiranjaAnkete
*/
public String getSadrzajNacinaKreiranjaAnkete() {
return sadrzajNacinaKreiranjaAnkete;
}
/**
* @param sadrzajNacinaKreiranjaAnkete the sadrzajNacinaKreiranjaAnkete to set
*/
public void setSadrzajNacinaKreiranjaAnkete(String sadrzajNacinaKreiranjaAnkete) {
this.sadrzajNacinaKreiranjaAnkete = sadrzajNacinaKreiranjaAnkete;
}
public void prvi(ActionEvent e) {
setHomeSadrzaj("homePrva.xhtml");
}
public void drugi(ActionEvent e) {
setHomeSadrzaj("index.xhtml");
}
/**
* @return the text
*/
public String getText() {
return text;
}
/**
* @param text the text to set
*/
public void setText(String text) {
this.text = text;
}
/**
* @return the homeSadrzaj
*/
public String getHomeSadrzaj() {
return homeSadrzaj;
}
/**
* @param homeSadrzaj the homeSadrzaj to set
*/
public void setHomeSadrzaj(String homeSadrzaj) {
this.homeSadrzaj = homeSadrzaj;
}
public void izmeni(ActionEvent e) {
sadrzaj = "homePrva.xhtml";
}
public void izmeni2(ActionEvent e) {
text = "Prvi tekst";
}
}
此外,我尝试从 p:selectOneRadio 中删除 f:ajax,然后该按钮“Nazad”正常工作,我可以更改 outputPanel“sadrzaj”,只需单击按钮“Napred”(表示前进)和“Nazad”(表示返回)。我还尝试将页面 strana2.xhtml 作为我的欢迎页面,如下所示:
页面 strana2.xhtml 更改为欢迎页面:
<?xml version='1.0' encoding='UTF-8' ?>
<!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:p="http://primefaces.org/ui">
<h:head>
<title>IGNORED</title>
</h:head>
<h:body>
<h:form>
<p:selectOneRadio id="izborNacinaKreiranjaAnkete"
value="#{user.izborNacinaKreiranjaAnkete}" >
<f:selectItems value="#{user.ponudaNacinaKreiranjaAnkete}"/>
<f:ajax event="change" listener="#{user.izborNacinaKreiranjaAnketeListener}"
render="sadrzajNacinaKreiranjaAnkete"/>
</p:selectOneRadio>
<br/>
<p:outputPanel id="sadrzajNacinaKreiranjaAnkete">
<h:outputText value="#{user.text}"/>
</p:outputPanel>
</h:form>
</h:body>
</html>
结果很好,一切正常,但在 index.xhtml 页面内(当然我随后删除了这些 h:form 标签)它不起作用。
请问有人知道为什么会这样吗?
这是我的问题的一部分,只是为了更清楚:
我正在使用 netBeans7.1.2、Tomcat7.0.22 和 Primefaces 3.3.1,有时我会在服务器控制台中收到错误消息,但我没有看到这些消息对我的项目有任何影响,其实我想说即使我的项目有效,有时我也会收到这些错误,有时即使我的项目无效,我也没有收到任何消息。这些消息是:
第一条消息:
SEVERE: IOException while loading persisted sessions: java.io.InvalidClassException: beans.UserBean; local class incompatible: stream classdesc serialVersionUID = -5783497785664294581, local class serialVersionUID = -8328898459300814685
java.io.InvalidClassException: beans.UserBean; local class incompatible: stream classdesc serialVersionUID = -5783497785664294581, local class serialVersionUID = -8328898459300814685
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:604)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1601)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1750)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1613)
at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1073)
at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:284)
at org.apache.catalina.session.StandardManager.load(StandardManager.java:204)
at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:470)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5241)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:607)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:558)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:468)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1329)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:389)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:334)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1041)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:727)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:148)
at org.apache.catalina.startup.Catalina.start(Catalina.java:621)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)
另一个是:
NotifyUtil::java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
at java.net.SocketInputStream.read(SocketInputStream.java:121)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3035)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.readLine(BufferedReader.java:317)
at java.io.BufferedReader.readLine(BufferedReader.java:382)
at org.netbeans.modules.web.monitor.server.NotifyUtil$RecordSender.run(NotifyUtil.java:299)
如果单击任何按钮或单选按钮,我会在 Firebug 控制台中收到此消息:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response><error><error-name>class java.lang.ClassCastException</error-name><error-message><![CDATA[javax.faces.component.StateHolderSaver cannot be cast to [Ljava.lang.Object;]]></error-message></error></partial-response>