views:

1034

answers:

1

Hi

I am developing a custom component using JSF 1.2 . My tag class extends UIComponentELTag and has variables of data type ValueExpression. The values for these are getting set from the corresponding attributes of the tag. (Using setProperties function) Example,

<sr:show name="#{backingBean.name}" ...> #{backingBean.mainContent}</sr:show>

I am stuck when I try to get the bodyContent of the tag as a binding value. This is how far I have proceeded: This is the code in doAfterBody()

public int doAfterBody() throws JspException{
if(bodyContent!=null) {
String body = bodyContent.getString();
FacesContext context = FacesContext.getCurrentInstance();
UIComponent component = super.findComponent(context);
MyComp myComp= (MyComp) component;
myComp.setMain(body);

}
bodyContent.clearBody();
return SKIP_BODY;
}

If the body of the tag does not contain binding value, this code works fine. I want to check if the body has binding value and then set the value from the bean. In JSF 1.1, I checked this using isValueReference(body). How do I achieve this in JSF 1.2?

I could not find any examples of getting the body content as binding value anywhere. Please help me out.

Thanks.

A: 

Why not simply add another variable e.g. "contents" and bind that to the body text you want to render?

<sr:show name="#{backingBean.name}" text="#{backingBean.mainContent}" />

Or simply:

<sr:show bean="#{backingBean} />

and render the whole lot.

Simon Gibbs
If the user wants to provide the value directly without a bean, is it advisable to put a whole lot of content as part of tag attribute?(like, text=mainContent, where mainContent may contain huge content or xml or anything else)The custom tag should support both binding value as well as direct value.
Srividya Sharma
I'm just learning this stuff myself - sorry. Depending on how much logic you have vs formatting, you could just use facelets composition components for this. Also, you can separate presentation logic into one tag and have it set a variable with the result, then use other elements for formatting
Simon Gibbs