It seems like the jsp page below should work.
If the checkbox is checked and then submit is pressed, the input text box appears.
But then anything entered in the input text is lost - the setter is never called.
Can anyone tell me why? Something to do with timing of the component binding?
 
faces-config.xml
<managed-bean>
   <managed-bean-name>testBean</managed-bean-name>
   <managed-bean-class>TestBean</managed-bean-class>
   <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
 
 
 
test.jsp
<%@ page session="false" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="
http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="
http://java.sun.com/jsf/core" prefix="f"%>
<f:view>
        <html>
                <body>
                        <h:form>
                                <h:selectBooleanCheckbox value="#{testBean.boolean}" />
                                <h:inputText value="#{testBean.string}" rendered="#{testBean.boolean}" />
                                <h:commandButton action="" value="submit" />
                        </h:form>
                </body>
        </html>
</f:view>
 
 
TestBean.java
public class TestBean {
 
    private String _string;
    private int _int;
    private boolean _boolean;
 
    public boolean isBoolean() {
        return _boolean;
    }
    public void setBoolean(boolean _boolean) {
        this._boolean = _boolean;
    }
    public int getInt() {
        return _int;
    }
    public void setInt(int _int) {
        this._int = _int;
    }
    public String getString() {
        return _string;
    }
    public void setString(String _string) {
        System.out.println("_string = " + _string);
        this._string = _string;
    }
    public void action() {}
}
 
 
 

 

Reply via email to