2

I have a xhtml page which I am calling a method from a managed bean from and it just doesnt seem to work for some reason.I have tried all measures, changed to p : command , tried ajax calls. all page with hcommand works fine, please Im i doing anything wrong here

<?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");

}
user3701188
  • 638
  • 3
  • 7
  • 23
  • Possible duplicate of [commandButton/commandLink/ajax action/listener method not invoked or input value not updated](http://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value) – Kukeltje Jan 31 '17 at 15:28

1 Answers1

2

try this:

your form tag should be like this <h:form> because you are using h:commandButton tag and your p:dataTable tag should be inside h:form tag. Write method name in EL without parenthesis.

<?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> 
ArgaPK
  • 455
  • 1
  • 9
  • 22
  • Trust I have tried that as well I just took it out because the table has nothing to do with the form the table just renders data , but I just tried it again and didnt work – user3701188 Jan 31 '17 at 14:27
  • Can you upload your full backing bean code that contains the methods?? – ArgaPK Jan 31 '17 at 14:29
  • you didn't have h:form tag, did you replace
    with ??
    – ArgaPK Jan 31 '17 at 14:30
  • Thank you soo much bruh, I spent 2 hours on this can you imagine – user3701188 Jan 31 '17 at 14:44
  • no problem, i actually get worried when you say "no trigger", but Glad that the problem is solved now. please do upvote the answer also. – ArgaPK Jan 31 '17 at 14:50
  • Thanks for answering, but please search for duplicates of 'basic' issues. Lots of those already have Q/A in Stackoverflow http://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Kukeltje Jan 31 '17 at 15:29
  • Thanks I would @ArgaPK do you know how I can achieve this with ajax – user3701188 Jan 31 '17 at 15:48
  • @user3701188 try this: – ArgaPK Jan 31 '17 at 17:08