Note that there are some explanatory texts on larger screens.

plurals
  1. POConditionally render h:selectOneMenu and h:inputText by ajax depending on h:selectOneRadio selection
    primarykey
    data
    text
    <p>I have a form with 2 radio buttons: "type1" and "type2". If "type1" is chosen, then a dropdown must be displayed. If "type2" is chosen, then a textfield must be displayed.</p> <p>Here's the view and the controller:</p> <p><code>test.xtml</code></p> <pre><code>&lt;!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j"&gt; &lt;h:form&gt; &lt;h:selectOneRadio id="type" label="Type" value="#{testBean.type}"&gt; &lt;f:selectItem itemLabel="Type1" itemValue="type1" /&gt; &lt;f:selectItem itemLabel="Type2" itemValue="type2" /&gt; &lt;f:ajax execute="@all" render="selectBox inputBox"/&gt; &lt;/h:selectOneRadio&gt; &lt;h:selectOneMenu id="selectBox" label="Service" value="#{testBean.service}" rendered="#{testBean.isType1}" style="width:285px"&gt; &lt;f:selectItem itemLabel="Medium" itemValue="medium" /&gt; &lt;f:selectItem itemLabel="Basic" itemValue="basic" /&gt; &lt;f:selectItem itemLabel="Premium" itemValue="premium" /&gt; &lt;/h:selectOneMenu&gt; &lt;h:inputText id="inputBox" size="50" value="#{testBean.custom}" rendered="#{!testBean.isType1}" /&gt; &lt;/h:form&gt; &lt;/ui:composition&gt; </code></pre> <p><code>TestBean.java</code></p> <pre><code>package com.test.backing; import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean(name = "testBean") @SessionScoped public class TestBean implements Serializable { private static final long serialVersionUID = -4337084623546767911L; private String type = "type1"; private String service; private String custom; public Boolean getIsType1() { if(type.equals("type1")) { System.out.println(type+":true"); return true; } else { System.out.println(type+":false"); return false; } } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getService() { return service; } public void setService(String service) { this.service = service; } public String getCustom() { return custom; } public void setCustom(String custom) { this.custom = custom; } } </code></pre> <p>When I start my application, I have the following in my stdout:</p> <pre><code>type1:true type1:true type1:true type1:true type1:true type1:true </code></pre> <p>However, nothing happens in the UI when I choose another type. How is this caused and how can I solve it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload