webtier@glassfish.java.net

Re: [webtier] How to hide & unhide panels in JSF.

From: Mikael Andersson <mail.micke_at_gmail.com>
Date: Tue, 1 Jul 2008 22:48:23 +0100

The EL in the rendered attribute evaluates to a boolean true/false. Looks to
me like you are referencing an actual component, I'm not sure how that gets
evaluated but my guess is that as long as it isn't null it is evaluated as
true.

How about changing the rendered line to something like this:
rendered="#{FormBean.ddlZip.checked}"



2008/7/1 <webtier_at_javadesktop.org>:

> Thanks!
> Ok, so I took out the panels, and I tried to specify rendered on just the
> drop down lists I want to hide/unhide, and now they always show.
> my code looks like this:
>
> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
> <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
> <%@taglib uri="http://www.infragistics.com/faces/netadvantage"
> prefix="ig"%>
> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
> pageEncoding="ISO-8859-1"%>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
> http://www.w3.org/TR/html4/loose.dtd">
>
> <f:view>
> <h:form id="form1">
> <h:panelGroup id="geogScopePanel">
> Select Geography<br />
> <ig:radioButton binding="#{FormBean.rbZip}"
>
> smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
> groupName="geogScopeGroup"
> immediate="true"
> id="rbZip"
> label="Zip"
> value="zip" /> &nbsp;
> <ig:radioButton binding="#{FormBean.rbCounty}"
>
> smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
> groupName="geogScopeGroup"
> immediate="true"
> id="rbCounty"
> label="County"
> value="county" /> &nbsp;
> <ig:radioButton binding="#{FormBean.rbDma}"
>
> smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
> groupName="geogScopeGroup"
> immediate="true"
> id="rbDma"
> label="DMA"
> value="dma" /> &nbsp;
> <ig:radioButton binding="#{FormBean.rbNational}"
>
> smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
> groupName="geogScopeGroup"
> immediate="true"
> id="rbNational"
> label="National"
> value="national" /><br />
> </h:panelGroup>
>
> <br />
>
> <h:panelGroup id="zipDdlPanel"
> binding="#{FormBean.panelDdlZip}"
> style="#{FormBean.panelDdlZipStyle}">
> <ig:dropDownList binding="#{FormBean.ddlZip}"
> smartRefreshIds="myOutput2"
> dataSource="#{DataBean.zipGeogs}"
> id="zipGeogList" />
> </h:panelGroup>
> <h:panelGroup id="countyDdlPanel"
> binding="#{FormBean.panelDdlCounty}"
> style="#{FormBean.panelDdlCountyStyle}">
> <ig:dropDownList binding="#{FormBean.ddlCounty}"
> smartRefreshIds="myOutput3"
> dataSource="#{DataBean.countyGeogs}"
> id="countyGeogList" />
> </h:panelGroup>
> <h:panelGroup id="dmaDdlPanel"
> binding="#{FormBean.panelDdlDma}"
> style="#{FormBean.panelDdlDmaStyle}">
> <ig:dropDownList binding="#{FormBean.ddlDma}"
> smartRefreshIds="myOutput4"
> dataSource="#{DataBean.dmaGeogs}"
> id="dmaGeogList" />
> </h:panelGroup>
>
> <br />
>
> <ig:dropDownList binding="#{FormBean.ddlZipEstimateTypes}"
> dataSource="#{DataBean.zipEstimateTypes}"
> rendered="#{FormBean.ddlZip}"
> id="zipEstimateTypes" />
>
> <br />
>
> myOutput1: <h:outputText id="myOutput1"
> value="#{FormBean.myOutput1}" /><br />
> myOutput2: <h:outputText id="myOutput2"
> value="#{FormBean.myOutput2}" /><br />
> myOutput3: <h:outputText id="myOutput3"
> value="#{FormBean.myOutput3}" /><br />
> myOutput3: <h:outputText id="myOutput4"
> value="#{FormBean.myOutput4}" /><br />
> </h:form>
> </f:view>
>
> My FormBean looks like this:
> import com.infragistics.faces.input.component.*;
> import javax.faces.component.*;
>
> public class FormBean {
> /** PROPERTY: rbZip */
> protected RadioButton rbZip;
> public RadioButton getRbZip() {
> System.out.println("[DCA]getRbZip");
> return rbZip;
> } // getRbZip.
> public void setRbZip(RadioButton rbZip) {
> System.out.println("[DCA]setRbZip");
> this.rbZip = rbZip;
> } // setRbZip.
>
> /** PROPERTY: rbCounty */
> protected RadioButton rbCounty;
> public RadioButton getRbCounty() {
> System.out.println("[DCA]getRbCounty");
> return rbCounty;
> } // getRbCounty.
> public void setRbCounty(RadioButton rbCounty) {
> System.out.println("[DCA]setRbCounty");
> this.rbCounty = rbCounty;
> } // setRbCounty.
>
> /** PROPERTY: rbDma */
> protected RadioButton rbDma;
> public RadioButton getRbDma() {
> System.out.println("[DCA]getRbDma");
> return rbDma;
> } // getRbDma.
> public void setRbDma(RadioButton rbDma) {
> System.out.println("[DCA]setRbDma");
> this.rbDma = rbDma;
> } // setRbDma.
>
> /** PROPERTY: rbNational */
> protected RadioButton rbNational;
> public RadioButton getRbNational() {
> System.out.println("[DCA]getRbNational");
> return rbNational;
> } // getRbNational.
> public void setRbNational(RadioButton rbNational) {
> System.out.println("[DCA]setRbNational");
> this.rbNational = rbNational;
> } // setRbNational.
>
> /** PROPERTY: ddlZip */
> protected UIInput ddlZip = null;
> public UIInput getDdlZip() {
> System.out.println("[DCA]getDdlZip");
> return ddlZip;
> } // getDdlZip.
> public void setDdlZip(UIInput ddlZip) {
> System.out.println("[DCA]setDdlZip");
> this.ddlZip = ddlZip;
> } // setDdlZip.
>
> /** PROPERTY: ddlCounty */
> protected UIInput ddlCounty = null;
> public UIInput getDdlCounty() {
> System.out.println("[DCA]getDdlCounty");
> return ddlCounty;
> } // getDdlCounty.
> public void setDdlCounty(UIInput ddlCounty) {
> System.out.println("[DCA]setDdlCounty");
> this.ddlCounty = ddlCounty;
> } // setDdlCounty.
>
> /** PROPERTY: ddlDma */
> protected UIInput ddlDma = null;
> public UIInput getDdlDma() {
> System.out.println("[DCA]getDdlDma");
> return ddlDma;
> } // getDdlDma.
> public void setDdlDma(UIInput ddlDma) {
> System.out.println("[DCA]setDdlDma");
> this.ddlDma = ddlDma;
> } // setDdlDma.
>
> /** OUTPUT TEXT FIELDS */
> public String getMyOutput1() {
> System.out.println("[DCA]getMyOutput1");
> return getSelectedGeogScope();
> } // getMyOutput1.
> public String getMyOutput2() {
> System.out.println("[DCA]getMyOutput2");
> return (String)getDdlZip().getValue();
> } // getMyOutput2.
> public String getMyOutput3() {
> System.out.println("[DCA]getMyOutput3");
> return (String)getDdlCounty().getValue();
> } // getMyOutput3.
> public String getMyOutput4() {
> System.out.println("[DCA]getMyOutput4");
> return (String)getDdlDma().getValue();
> } // getMyOutput4.
>
> /** PROPERTY: panelDdlZip. */
> protected String panelDdlZip;
> public String getPanelDdlZip() {
> System.out.println("[DCA]getPanelDdlZip");
> return panelDdlZip;
> } // getPanelDdlZip.
> public void setPanelDdlZip(String panelDdlZip) {
> System.out.println("[DCA]setPanelDdlZip");
> this.panelDdlZip = panelDdlZip;
> } // setPanelDdlZip.
>
> /** PROPERTY: panelDdlCounty. */
> protected String panelDdlCounty;
> public String getPanelDdlCounty() {
> System.out.println("[DCA]getPanelDdlCounty");
> return panelDdlCounty;
> } // getPanelDdlCounty.
> public void setPanelDdlCounty(String panelDdlCounty) {
> System.out.println("[DCA]setPanelDdlCounty");
> this.panelDdlCounty = panelDdlCounty;
> } // setPanelDdlCounty.
>
> /** PROPERTY: panelDdlDma. */
> protected String panelDdlDma;
> public String getPanelDdlDma() {
> System.out.println("[DCA]getPanelDdlDma");
> return panelDdlDma;
> } // getPanelDdlDma.
> public void setPanelDdlDma(String panelDdlDma) {
> System.out.println("[DCA]setPanelDdlDma");
> this.panelDdlDma = panelDdlDma;
> } // setPanelDdlDma.
>
> /** PROPERTY: panelDdlZipStyle */
> protected String panelDdlZipStyle;
> public String getPanelDdlZipStyle() {
> System.out.println("[DCA]getPanelDdlZipStyle");
> getSelectedGeogScope();
> return panelDdlZipStyle;
> } // getPanelDdlZipStyle.
>
> /** PROPERTY: panelDdlCountyStyle. */
> protected String panelDdlCountyStyle;
> public String getPanelDdlCountyStyle() {
> System.out.println("[DCA]getPanelDdlCountyStyle");
> getSelectedGeogScope();
> return panelDdlCountyStyle;
> } // getPanelDdlCountyStyle.
>
> /** PROPERTY: panelDdlDmaStyle. */
> protected String panelDdlDmaStyle;
> public String getPanelDdlDmaStyle() {
> System.out.println("[DCA]getPanelDdlDmaStyle");
> getSelectedGeogScope();
> return panelDdlDmaStyle;
> } // getPanelDdlDmaStyle.
>
> /** PROPERTY: ddlZipEstimateTypes */
> protected UIInput ddlZipEstimateTypes = null;
> public UIInput getDdlZipEstimateTypes() {
> System.out.println("[DCA]getDdlZipEstimateTypes");
> return ddlZipEstimateTypes;
> } // getDdlZipEstimateTypes.
> public void setDdlZipEstimateTypes(UIInput ddlZipEstimateTypes) {
> System.out.println("[DCA]setDdlZipEstimateTypes");
> this.ddlZipEstimateTypes = ddlZipEstimateTypes;
> } // setDdlZipEstimateTypes.
>
> /** CONSTRUCTOR */
> public FormBean() {
> System.out.println("[DCA]FormBean");
> panelDdlZipStyle = "visibility: hidden;";
> panelDdlCountyStyle = "visibility: hidden;";
> panelDdlDmaStyle = "visibility: hidden;";
> } // constructor.
>
> /** METHOD: getSelectedGeogScope */
> public String getSelectedGeogScope() {
> System.out.println("[DCA]getSelectedGeogScope");
> String result = new String();
>
> if(rbZip.isChecked()) {
> result = rbZip.getLabel();
> panelDdlZipStyle = "visibility: visible;";
> panelDdlCountyStyle = "visibility: hidden;";
> panelDdlDmaStyle = "visibility: hidden;";
> } else if(rbCounty.isChecked()) {
> result = rbCounty.getLabel();
> panelDdlZipStyle = "visibility: hidden;";
> panelDdlCountyStyle = "visibility: visible;";
> panelDdlDmaStyle = "visibility: hidden;";
> } else if(rbDma.isChecked()) {
> result = rbDma.getLabel();
> panelDdlZipStyle = "visibility: hidden;";
> panelDdlCountyStyle = "visibility: hidden;";
> panelDdlDmaStyle = "visibility: visible;";
> } else if(rbNational.isChecked()) {
> result = rbNational.getLabel();
> panelDdlZipStyle = "visibility: hidden;";
> panelDdlCountyStyle = "visibility: hidden;";
> panelDdlDmaStyle = "visibility: hidden;";
> } // if/else.
>
> return result;
> } // getSelectedGeogScope.
>
> public String checkRb() {
> System.out.println("[DCA]checkRb");
> StringBuilder sb = new StringBuilder(0);
>
> if(rbZip != null) {
> if(rbZip.isChecked()) sb.append("\n\t[DCA] rbZip IS CHECKED");
> else sb.append("\n\t[DCA] rbZip NOT CHECKED");
> } // if.
>
> if(rbCounty != null) {
> if(rbCounty.isChecked()) sb.append("\n\t[DCA] rbCounty IS
> CHECKED");
> else sb.append("\n\t[DCA] rbCounty NOT CHECKED");
> } // if.
>
> if(rbDma != null) {
> if(rbDma.isChecked()) sb.append("\n\t[DCA] rbDma IS CHECKED");
> else sb.append("\n\t[DCA] rbDma NOT CHECKED");
> } // if.
>
> if(rbNational != null) {
> if(rbNational.isChecked()) sb.append("\n\t[DCA] rbNational IS
> CHECKED");
> else sb.append("\n\t[DCA] rbNational NOT CHECKED");
> } // if.
>
> return sb.toString();
> } // checkRb.
> } // class FormBean.
> [Message sent by forum member 'djdanjazz' (djdanjazz)]
>
> http://forums.java.net/jive/thread.jspa?messageID=283756
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>
>