Skip to main content

How to hide & unhide panels in JSF.

5 replies [Last post]
djdanjazz
Offline
Joined: 2008-05-14
Points: 0

Hello,
I'm trying to hide/unhide JSF panels based on UI events.
More specifically, I have radio buttons and drop down lists.
Every component exists within its own panel.
I need to make a panel visible based on radio button click or drop down list item select.
I also need to make another panel invisible based on radio button click or drop down list item select.

Thanks in advance,
Dan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Mikael Andersson

Sounds like a job for the good old rendered attribute to me.

Ex:
rendered="#{controlVisibilityBean.buttonOneVisible}"/>

2008/6/30 :

> Hello,
> I'm trying to hide/unhide JSF panels based on UI events.
> More specifically, I have radio buttons and drop down lists.
> Every component exists within its own panel.
> I need to make a panel visible based on radio button click or drop down
> list item select.
> I also need to make another panel invisible based on radio button click
> or drop down list item select.
>
> Thanks in advance,
> Dan
> [Message sent by forum member 'djdanjazz' (djdanjazz)]
>
> http://forums.java.net/jive/thread.jspa?messageID=283401
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
[att1.html]

djdanjazz
Offline
Joined: 2008-05-14
Points: 0

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"%>

smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
groupName="geogScopeGroup"
immediate="true"
id="rbZip"
label="Zip"
value="zip" />  
smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
groupName="geogScopeGroup"
immediate="true"
id="rbCounty"
label="County"
value="county" />  

smartRefreshIds="myOutput2"
dataSource="#{DataBean.zipGeogs}"
id="zipGeogList" />
smartRefreshIds="myOutput3"
dataSource="#{DataBean.countyGeogs}"
id="countyGeogList" />

dataSource="#{DataBean.zipEstimateTypes}"
rendered="#{FormBean.ddlZip}"
id="zipEstimateTypes" />

My FormBean looks like this:

/** 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: 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.

Message was edited by: djdanjazz

Mikael Andersson

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 :

> 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"%>
>
> > http://www.w3.org/TR/html4/loose.dtd">
>
>
>
>
> Select Geography
> >
> smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
> groupName="geogScopeGroup"
> immediate="true"
> id="rbZip"
> label="Zip"
> value="zip" />  
> >
> smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
> groupName="geogScopeGroup"
> immediate="true"
> id="rbCounty"
> label="County"
> value="county" />  
> >
> smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
> groupName="geogScopeGroup"
> immediate="true"
> id="rbDma"
> label="DMA"
> value="dma" />  
> >
> smartRefreshIds="zipDdlPanel,countyDdlPanel,dmaDdlPanel,myOutput1"
> groupName="geogScopeGroup"
> immediate="true"
> id="rbNational"
> label="National"
> value="national" />
>

>
>
>
> > binding="#{FormBean.panelDdlZip}"
> style="#{FormBean.panelDdlZipStyle}">
> > smartRefreshIds="myOutput2"
> dataSource="#{DataBean.zipGeogs}"
> id="zipGeogList" />
>

> > binding="#{FormBean.panelDdlCounty}"
> style="#{FormBean.panelDdlCountyStyle}">
> > smartRefreshIds="myOutput3"
> dataSource="#{DataBean.countyGeogs}"
> id="countyGeogList" />
>

> > binding="#{FormBean.panelDdlDma}"
> style="#{FormBean.panelDdlDmaStyle}">
> > smartRefreshIds="myOutput4"
> dataSource="#{DataBean.dmaGeogs}"
> id="dmaGeogList" />
>

>
>
>
> > dataSource="#{DataBean.zipEstimateTypes}"
> rendered="#{FormBean.ddlZip}"
> id="zipEstimateTypes" />
>
>
>
> myOutput1: > value="#{FormBean.myOutput1}" />
> myOutput2: > value="#{FormBean.myOutput2}" />
> myOutput3: > value="#{FormBean.myOutput3}" />
> myOutput3: > value="#{FormBean.myOutput4}" />
>

>

>
> 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@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
[att1.html]

djdanjazz
Offline
Joined: 2008-05-14
Points: 0

Ok, I did the rendered="#{FormBean.ddlZip.checked}" stuff.
The item never displays, even if I click on the drop down list.
Are there any other properties I should be including in the rendered attribute?

Thanks

Mikael Andersson

What is it that is suppose to update the component with id zipEstimateTypes,
and when ?
Never used the component library but there seems to be the smartRefreshIds
which you use, perhaps you've forgotten to actually refresh the dropdown?

Next thing to test is that the value for #{FormBean.ddlZip.checked}, is
correct (changes from false to true). You could do this by putting it in a
h:outputText and refresh that id.

2008/7/3 :

> Ok, I did the rendered="#{FormBean.ddlZip.checked}" stuff.
> The item never displays, even if I click on the drop down list.
> Are there any other properties I should be including in the rendered
> attribute?
>
> Thanks
> [Message sent by forum member 'djdanjazz' (djdanjazz)]
>
> http://forums.java.net/jive/thread.jspa?messageID=284210
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>
>
[att1.html]