1

Every time I debug the application and type something in the Textbox, the Controller remember only when I refresh the page. Without the ajax Tag it's working fine. So my guess: the rendering of the outputPanel does not Work. I set Breakpoints (ajax listener and field setter are both called) and tested it many times and the outcome was the controller only works when i clicked the button and then refreshed the page. Referring JSF, I work with Eclipse for Java EE and Tomcat v.9.0 and earlier.

Strange thing is that the execute attribute only has the id for the name input in its execute attribute and still the listener is called (sysout is printed), this is not to be expected accordimg to #9 in commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated. But changing it to @form does not change it

new.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:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      >
    <h:head>
    </h:head>

    <h:body>
        <h:form id="formID">
            <h:inputText id="name" value="#{LayoutController.name}"></h:inputText>

            <h:commandButton value="Welcome Me">
                <f:ajax event="click" listener="#{LayoutController.listen}" execute=":formID:name" render=":formID:output"/>
            </h:commandButton>

            <h:panelGroup id="output">
                <h:outputText value="#{LayoutController.name}"/>
            </h:panelGroup>
        </h:form>
    </h:body>
</html>

LayoutController.java:

    package Template;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.AjaxBehaviorEvent;

@ManagedBean(name="LayoutController")
@SessionScoped
public class LayoutController{

    private String name;

    public LayoutController() {
        this.name="";
    }

    public String getName() {
       return name;
    }
    public void setName(String name) {
       this.name = name;
    }

    public void listen (AjaxBehaviorEvent event) {
        this.name = this.name + " ! ";
        System.out.println("Clicked");
    }


}
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • the page shall not refresh, it should load or render the panelGroup dynamically. but it only renders after refreshing the site and only works with @Sessionscoped. – Phil Hofmann Jun 19 '19 at 19:45
  • For example with @Requestscoped it can not work because after refreshing the site the controller does not exist anymore – Phil Hofmann Jun 19 '19 at 19:45
  • ooops, yes the listener is called ! and the click print works also fine – Phil Hofmann Jun 19 '19 at 19:51
  • just the rendering... – Phil Hofmann Jun 19 '19 at 19:51
  • i know the post and the solution with @form but for me it does not work.. I also tried in this code :formID:output etc. so annoying.. – Phil Hofmann Jun 19 '19 at 20:05
  • oh and i have jsf 2.3 you mean deleting the render? – Phil Hofmann Jun 19 '19 at 20:07
  • why did you not mention you knew this? Would have saved me time asking etc... – Kukeltje Jun 19 '19 at 20:08
  • Jsf 2.3 is an api version. Not real implementation version. Can you fix https://stackoverflow.com/questions/31068678/which-xml-namespace-to-use-with-jsf-2-2/ – Kukeltje Jun 19 '19 at 20:10
  • oops sorry... noob move :D – Phil Hofmann Jun 19 '19 at 20:10
  • No problem... glad you are responding. So many ask a question and are silent for one, two or even more days – Kukeltje Jun 19 '19 at 20:15
  • I removed some comments and added some summary to your question. Can you validate? – Kukeltje Jun 19 '19 at 20:22
  • how to validate..? ok so i just added jsf2.2 to my project and it does not work – Phil Hofmann Jun 19 '19 at 20:42
  • validate my changes in your question. are they a correct summary from our comments. And I requested you to change the namespaces in your page, not to change a jsf 2.3.x implementation for a 2.2.x one (what is your jsf implementation (mojarra or myfaces) and version btw) – Kukeltje Jun 20 '19 at 05:34
  • 2
    Inside a form you may use simple ids like `execute='name'` or `render='output'`. Did you try simple ids? Did you look in the response data in your browser console? Is ` – Holger Jun 20 '19 at 08:05

0 Answers0