Richfaces Custom Component Renderer Problem
I've create a custom component, and below is the renderer of the component, at start the component get rendered OK, but the AjaxOuputPanel never get rendered again with each ajax request... so what is the problem with the code
Also the case repeat at any component that add a child component of type HtmlAjaxOutputPanel, the component rendered OK at start but the ajax out panel never rendered again...the component code :
package eg.com.etisalat.web.rich.components.inputtext;
import java.io.IOException;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.faces.application.Application;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlGraphicImage;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.component.UIAjaxOutputPanel;
import org.ajax4jsf.component.html.HtmlAjaxOutputPanel;
import org.ajax4jsf.renderkit.AjaxComponentRendererBase;
public class InputTextRenderer extends AjaxComponentRendererBase {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected Class getComponentClass() {
return eg.com.etisalat.web.rich.components.inputtext.HtmlInputText.class;
}
public void doEncodeBegin(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
ELContext elContext = context.getELContext();
Application app = context.getApplication();
ExpressionFactory exprFactory = app.getExpressionFactory();
String clientId = component.getClientId(context);
String componentId = component.getId();
component.getChildren().clear();
String readonly = (String) component.getAttributes().get(Constants.ATT_READ_ONLY);
String styleClass = (String) component.getAttributes().get(Constants.ATT_STYLE_CLASS);
String required = (String) component.getAttributes().get(Constants.ATT_REQUIRED);
String requiredMessage = (String) component.getAttributes().get(Constants.ATT_REQUIRED_MESSAGE);
writer.startElement("div", component);
getUtils().writeAttribute(writer, "id", clientId);
String inputFieldId = componentId + "InputField";
javax.faces.component.html.HtmlInputText inputTextCom = new HtmlInputText();
inputTextCom.setId(inputFieldId);
inputTextCom.setOnchange(inputFieldId + "StoredValue = this.value");
if (null != readonly) inputTextCom.setReadonly(Boolean.parseBoolean(readonly));
if (null != styleClass) inputTextCom.setStyleClass(styleClass);
if (null != required) inputTextCom.setRequired(Boolean.parseBoolean(required));
if (null != requiredMessage) inputTextCom.setRequiredMessage(requiredMessage);
component.getChildren().add(inputTextCom);
if(null != requ开发者_开发知识库ired && Boolean.parseBoolean(required)) {
HtmlAjaxOutputPanel outpanel = new HtmlAjaxOutputPanel();
outpanel.setId(componentId + "InputFieldValidation");
outpanel.setAjaxRendered(true);
HtmlGraphicImage icon = new HtmlGraphicImage();
icon.setUrl((String)exprFactory.createValueExpression(elContext, "" +
"#{(not empty webUtil.messagesMap['" + inputFieldId + "']) ? '/images/info_red_16_16_.png' : " +
"'/images/info_yellow_16_16_.png'}"
, String.class).getValue(elContext));
icon.setStyleClass("errorIcon");
icon.setTitle(requiredMessage);
outpanel.getChildren().add(icon);
component.getChildren().add(outpanel);
}
String elementId = inputTextCom.getClientId(context);
writer.startElement("script", component);
writer.writeAttribute("type", "text/javascript", null);
writer.write("if(typeof " + inputFieldId + "StoredValue != \"undefined\") document.getElementById('" +
elementId + "').value = " + inputFieldId + "StoredValue;");
writer.endElement("script");
}
@Override
protected void doEncodeEnd(ResponseWriter writer, FacesContext context,
UIComponent component) throws IOException {
writer.endElement("div");
}
}
Ok I've found the problem, it is with the facelets.REFRESH_PERIOD, this property if with positive value will make the ui tree to be rebuilt with every request from the original document (calling facelets refresh method)
so the solution was to disable that property with setting it to -1
精彩评论