Pass argument to rendered attribute?
Hi,
Is it possible to pass an argument to the rendered-attribute? Or is it a must to point to a no-arg public boolean returning method?
If so, does anybody have any other idea on how to set a value on a bean in the beginning of page rendering, and check this value later on on the page in the rendered attribute?
Best regards
Pichdude
[365 byte] By [
Pichdudea] at [2007-11-27 5:22:46]

# 1
Use f:attribute of the component. Also see http://balusc.xs4all.nl/srv/dev-jep-com.html Through the componentbinding you can retrieve this attribute and use it in the valuebinding behind the rendered attribute.
# 2
Does it really work to check that attribute upon rendering. Is that attribute not only available when posting the form?
# 3
POST values are applied in the 4th phase of the JSF lifecycle. Rendering happens in the 6th phase. The values are likely available then :)
# 4
Nice,
But I cannot find out from your link, how do I retreive the attribute value from FacesContext in my "rendered method" getHasPermission?
jsf-page:
<t:commandButton action="validateTransfer" rendered="#{registerTransferUseCaseBean.hasPermission}" value="#{bundle['buttonRegisterTransfer']}" styleClass="portlet-form-button">
<f:attribute name="permission" value="validatetransfer" />
</t:commandButton>
code:
public boolean getHasPermission() {
// How do I retrived attribute "permission"?
}
Message was edited by:
Pichdude
# 5
You're using a commandButton here. That makes things more easy. Add an actionListener to the button, and retrieve the attribute value through the ActionEvent.
# 6
Perhaps a dumm question again, but will the actionlistener fire when the page renders?
# 7
When you invokes the button, right before the action method.
What exactly do you want to achieve? Now I think twice about it, the design may be somewhat odd. You just want to pass an argument to the rendered attribute regardless of action?
If so:<h:someComponent binding="#{myBean.someComponent}" rendered="#{myBean.renderSomeComponent}">
<f:attribute name="attributeName" value="attributeValue" />
</h:someComponent>
MyBeanprivate HtmlSomeComponent someComponent; // + getter + setter
public boolean renderSomeComponent() {
String attributeName = (String) someComponent.getAttributes().get("attributeName"); // "attributeValue"
// Implement return.
}
# 8
Actually, I thought the first solution was nice. So is it possible to retrieve the attribute from FacesContext?
# 9
Yeah, you can retrieve anything which is inside the FacesContext through the FacesContext ;)Also see http://balusc.xs4all.nl/srv/dev-jep-com.html#PassingComponentAttributesFromJSFToBackingBeans
# 10
Hi again!
For different reason I do not have the possibility in my project to use the binding attribute an use getAttribute() on that component.
So therefore my question is: Is it possible to find the f:attribute value directy on the FacesContext? E.g. is there a way lookup a component name without knowing its position in the component tree? And from there retrieve the attribute?
Best regards
Pichdude
Message was edited by:
Pichdude
# 11
Which reason? Maybe you're binding to the wrong object type. I see that you're using t:commandButton instead of h:commandButton, so javax.faces.component.html.HtmlCommandButton *might* not work correctly. Lookup the Tomahawk's implementation of it in their API documentation and use it instead.
You can lookup a component by ID as follows however:UIComponent component = FacesContext.getCurrentInstance().getViewRoot().findComponent("componentId");
# 12
Hi,
I started another aproach on this to get a little bit more dynamic into this. I declared a viewhandler that goes through all components and childrens components checking for the attribute "permission". If it is found I do some stuff finding out if this component should be rendered. If no, i setRendered(false) on the component.
However, it the component still gets rendered and I do not know why? I have tried doing this in the writeState-method of my ViewHandler. Do you know why the setting of rendered to false does not have any impact?
Best regards
Pichdude