Hello,
I have a custom component - a class extending UIComponentTag, a class extending UIComponentBase, and a class extending Renderer. The entire control works as it should, that is until I hit refresh. Upon a refresh, my UIComponentBase class getter functions suddenly return nulls. For instance, my tag can look like this:
<myapp:sometag myatt="somevalue"></myapp:sometag>
And when the page containing this is first loaded, in my renderer I have:
String someValue = ((UIPermissions) component).getSomeValue();
This works flawlessly the first time the page loads, but getSomeValue() returns null upon refresh. Any ideas? Thanks everyone... code is listed below.
public class PermissionsTag extends UIComponentTag {
public static final String COMPONENT_TYPE = "com.comp.UIPermissions";
public static final String COMPONENT_RENDERER = "com.comp.PermissionsRenderer";
private String sectionName;
public String getComponentType() {
return (COMPONENT_TYPE);
}
public String getRendererType() {
return (COMPONENT_RENDERER);
}
/**
* @jsp.attribute
name="sectionName" required="true" rtexprvalue="false" type="java.lang.String"
*/
public void setSectionName(String sectionName) {
this.sectionName = sectionName;
}
protected void setProperties(UIComponent component) {
super.setProperties(component);
if (sectionName != null) {
((UIPermissions) component).setSectionName(sectionName);
}
}
}
public class UIPermissions extends UIComponentBase {
protected final Log log = LogFactory.getLog(UIPermissions.class);
public static final String COMPONENT_FAMILY = "UIPermissions";
private String sectionName;
public UIPermissions() {
super();
}
public String getFamily() {
return COMPONENT_FAMILY;
}
public String getSectionName() {
return sectionName;
}
public void setSectionName(String sectionName) {
this.sectionName = sectionName;
}
}
public class PermissionsRenderer extends Renderer {
protected final Log log = LogFactory.getLog(PermissionsRenderer.class);
public boolean getRendersChildren() {
return true;
}
public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
String sectionName = ((UIPermissions) component).getSectionName();
User user = (User) ((UsernamePasswordAuthenticationToken) context.getExternalContext().getUserPrincipal()).getPrincipal();
log.info("Section Name:");
log.info(sectionName);
if (user.getUsername().equals(sectionName)) {
for (Iterator iter = component.getChildren
().iterator(); iter.hasNext();) {
UIComponent child = (UIComponent) iter.next();
encodeRecursive(context, child);
}
}
}
protected void encodeRecursive(FacesContext context, UIComponent component)
throws IOException {
if (!component.isRendered())
return;
component.encodeBegin(context);
if (component.getRendersChildren()) {
component.encodeChildren
(context);
} else {
List children = component.getChildren();
for (Iterator iter = children.iterator(); iter.hasNext();) {
UIComponent child = (UIComponent) iter.next
();
encodeRecursive(context, child);
}
}
component.encodeEnd(context);
}
}
- Custom component, loses attribute value? Robert Campbell
- Re: Custom component, loses attribute value? Gary VanMatre
- Re: Custom component, loses attribute value? Robert Campbell

