1

Below is a simple jsf page containing 1 x selectOneMenu, 3 x inputText and 1 x commandButton. testBean is unable to get the value of p2 and p3 from inputText in submit method when the commandButton is clicked, p2 and p3 are always return null. It has something to do with 'rendered' attribute, p2 and p3 are working fine when I remove it.

According to log, setType and setP1 are executed, but setP2 and setP3 are missing.

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
    <meta charset="utf-8" />
    <title>Test</title>
</h:head>
<h:body>
    <h:messages id="msg" />
    <h:form id="form1" method="post">
        <h:selectOneMenu value="#{testBean.type}">
            <f:selectItem itemValue="" itemLabel="Select..." />
            <f:selectItem itemValue="all" />
            <f:ajax render="@form" execute="@form" />
        </h:selectOneMenu>
        <h:inputText value="#{testBean.p1}" />
        <h:inputText value="#{testBean.p2}"
            rendered="#{not empty testBean.type}" />
        <h:panelGroup rendered="#{not empty testBean.type}">
            <h:inputText value="#{testBean.p3}" />
        </h:panelGroup>
        <h:commandButton value="Submit" action="#{testBean.submit}" />
    </h:form>
</h:body>
</html>
@javax.interceptor.Interceptors(LogInterceptor.class)
@javax.inject.Named
@javax.enterprise.context.RequestScoped
public class TestBean {
    protected static final org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getLogger();

    String type;
    String p1;
    String p2;
    String p3;

    public void submit() {
        logger.debug("type: {}", this.type);
        logger.debug("p1: {}", this.p1);
        logger.debug("p2: {}", this.p2);
        logger.debug("p3: {}", this.p3);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getP1() {
        return p1;
    }

    public void setP1(String p1) {
        this.p1 = p1;
    }

    public String getP2() {
        return p2;
    }

    public void setP2(String p2) {
        this.p2 = p2;
    }

    public String getP3() {
        return p3;
    }

    public void setP3(String p3) {
        this.p3 = p3;
    }


}
XYZ
  • 11
  • 1
  • I'm sort of confused... Can you set a breakpoint in the `getType()` and check the value if you can see in the stackt during debugging that the renderd EL is evaluated? And does it sort of work with a longer scope? And what is your JSF version and implementation?... Good [mcve] btw... compliments! – Kukeltje Aug 21 '20 at 08:06
  • And what if you remove the logging interceptor? – Kukeltje Aug 21 '20 at 08:34
  • See item #6 of the duplicate. Just replace `@RequestScoped` by `@ViewScoped`. – BalusC Aug 21 '20 at 08:41
  • @BalusC: Hmmm I did read the duplicate to check how it might be related (I suspected it would be) but did not land at #6 and am not sure why (too little coffee?)... Thanks – Kukeltje Aug 21 '20 at 08:46
  • @Kukeltje: The recently introduced [``](https://showcase.omnifaces.org/components/inputHidden) can also solve this case if the requirement is to keep the bean `@RequestScoped`. – BalusC Aug 21 '20 at 08:50

0 Answers0