I have Facelet component and I have backing bean for it. When I include my component to some page I pass bean from page to my component:
<ui:include src="./WEB-INF/templates/myTemplate.xhtml">
<ui:param name="pageBean" value="#{thisPageBean}" />
</ui:include>
My component also have backing bean and I try to pass value from invoking page bean to my:
<c:set target="#{componentBean}" property="field" value="#{pageBean.field}" />
But this method doesn't work? There is some way to pass value from one bean to another?
I am trying create difficult custom component that must do some validation and other action on things that was pass to it? Maybe I am in wrong way?
You could pass the bean as an attribute on the component (I assume when you say "component" you are using ui:component).
For a component:
<ui:component binding="#{componentBean.myComponent}">
<f:attribute name="foo" value="#{pageBean.field}" />
<h:outputText value="#{componentBean.something}" />
</ui:component>
You could have a backing bean with these methods:
private Object field;
private UIComponent component;
public void setMyComponent(UIComponent c) { component = c; }
public UIComponent getMyComponent() { return component; }
private void lookupFields() {
field = component.getAttributes().get("foo");
}
public String getSomething() {
if (field == null) {
lookupFields();
}
return "" + field;
}
Not very elegant, but I'm not all that familiar with the mechanics of Facelets includes and this is the first thing that occurred to me. Note that the attributes might be persisted when the view is saved - I can't remember for stuff that gets set on the attributes map.