我有一个xhtml页面,我从托管bean调用一个方法,它似乎没有工作的原因。我已经尝试了所有的措施,改为p:命令,尝试了ajax调用。 hcommand的所有页面都运行正常,请我在这里做错了什么
<?xml version="1.0" encoding="ISO-8859-1" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:metadata>
<f:event type="preRenderView" listener="#{hibernateController.getAllWebSites()}"/>
<f:event type="preRenderView" listener="#{hibernateController.getAllScores()}"/>
</f:metadata>
<h:head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mood Watch</title>
<h:outputStylesheet library="css" name="style.css" />
</h:head>
<h:body>
<div id="wrapper">
<div id="header">
<h2>Mood Watch</h2>
</div>
</div>
<form>
<p:outputLabel>Filter : </p:outputLabel>
<p:selectOneMenu id="whySelect1" value="#{hibernateController.siteFromMood}">
<f:selectItems value="#{hibernateController.mySites}" var="tempSites" itemLabel="#{tempSites.site}" itemValue="#{tempSites.moodSite}" />
</p:selectOneMenu>
<h:commandButton value="Filter" action="#{hibernateController.filterSites()}"/>
<h:commandButton value="View All" action="#{hibernateController.setSitMoodToNull()}"/>
</form>
<p:dataTable id="moodTable" var="moodValues" value="#{hibernateController.myFrontEndModels}">
<p:column headerText="Date">
<h:outputText value="#{moodValues.dateCreated}" />
</p:column>
<p:column headerText="Site">
<h:outputText value="#{moodValues.sitename}" />
</p:column>
<p:column headerText="Value">
<h:outputText value="#{moodValues.moodValue}" />
</p:column>
</p:dataTable>
</h:body>
public void setSitMoodToNull() {
siteFromMood = null;
System.out.println("This is setSiteFromMood to null :" + siteFromMood);
}
public void filterSites(){
System.out.println("Show me specifics");
}
答案 0 :(得分:2)
试试这个:
您的表单标记应与此<h:form>
类似,因为您使用的是h:commandButton
代码,而p:dataTable
代码应位于h:form
代码内。在没有括号的EL中写入方法名称。
<?xml version="1.0" encoding="ISO-8859-1" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:metadata>
<f:event type="preRenderView" listener="#{hibernateController.getAllWebSites()}"/>
<f:event type="preRenderView" listener="#{hibernateController.getAllScores()}"/>
</f:metadata>
<h:head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mood Watch</title>
<h:outputStylesheet library="css" name="style.css" />
</h:head>
<h:body>
<div id="wrapper">
<div id="header">
<h2>Mood Watch</h2>
</div>
</div>
<h:form>
<p:outputLabel>Filter : </p:outputLabel>
<p:selectOneMenu id="whySelect1" value="#{hibernateController.siteFromMood}">
<f:selectItems value="#{hibernateController.mySites}" var="tempSites" itemLabel="#{tempSites.site}" itemValue="#{tempSites.moodSite}" />
</p:selectOneMenu>
<h:commandButton value="Filter" actionListener="#{hibernateController.filterSites}"/>
<h:commandButton value="View All" actionListener="#{hibernateController.setSitMoodToNull}"/>
<p:dataTable id="moodTable" var="moodValues" value="#{hibernateController.myFrontEndModels}">
<p:column headerText="Date">
<h:outputText value="#{moodValues.dateCreated}" />
</p:column>
<p:column headerText="Site">
<h:outputText value="#{moodValues.sitename}" />
</p:column>
<p:column headerText="Value">
<h:outputText value="#{moodValues.moodValue}" />
</p:column>
</p:dataTable>
</h:form>
</h:body>