set renderer dynamically

i create a gridPanel and want to set a renderer to it, how can i do that?
[80 byte] By [schaeflia] at [2007-11-27 2:41:46]
# 1
You can use the 'rendered' attribute of it. It accepts a boolean expression. If you want to do it in the backing bean, then bind the grid to HtmlPanelGrid and use HtmlPanelGrid#setRendered().
BalusCa at 2007-7-12 3:05:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

if i have in my jsp-file the following code:

<h:panelGrid binding="#{CrosswordPage.gridPanel1}" id="gridPanel1" rendered="#{SessionBean1.showRenderer}" style="height: 200px; left: 0px; top: 0px; position: absolute; width: 300px"/>

and in the backing bean i write:

gridPanel1 = new HtmlPanelGrid();

then i overwrite the settings from the jsp-file is that right?

and if i say gridPanel1.setRendered(false) when i click on a button the gridPanel is still here...

schaeflia at 2007-7-12 3:05:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Don't set it at two different places. Set it in the backing bean or in the JSF. Those which are set already in the JSF will overwrite it.
BalusCa at 2007-7-12 3:05:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
i have deleted the render-attribute in the jsf-file, but it doesn't work if i setRendered(false) in a button-action-method... it is always there
schaeflia at 2007-7-12 3:05:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

It just works here ..

JSF<h:form>

<h:commandButton value="toggle" action="#{myBean.toggle}" />

</h:form>

<h:panelGrid binding="#{myBean.grid}">

<h:outputText value="foo" />

</h:panelGrid>

MyBeanprivate HtmlPanelGrid grid; // + getter + setter

public void toggle() {

grid.setRendered(!grid.isRendered());

}

JSF 1.2_04 by the way.

BalusCa at 2007-7-12 3:05:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

it doesn't work in my example:

crosswordPageForm = new Form();

crosswordPageForm.setId("crosswordPageForm");

gridPanel1 = new HtmlPanelGrid();

// gridPanel1.setStyle("background-color: purple; height: 200px; left: 0px; top: 0px; position: absolute; width: 300px");

gridPanel1.setId("gridPanel1");

gridPanel1.setRendered(true);

public String b_deleteCw_action() {

// TODO: Process the button click action. Return value is a navigation

// case name where null will return to the same page.

// getSessionBean1().setShowRenderer(false);

gridPanel1.setRendered(false);

}

schaeflia at 2007-7-12 3:05:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Are you recreating the grid everytime?Try my snippets. If it works, then there's something wrong in your code logic.
BalusCa at 2007-7-12 3:05:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
no, i only create the grid if in the url is an attribute in my case cwid
schaeflia at 2007-7-12 3:05:55 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...