1 Reply Latest reply on Jul 17, 2008 9:30 AM by Frans Stofberg

    Custom component reRender

    Frans Stofberg Newbie

      Hi Guys.
      I have a custom input component for telephone numbers when I rerender a pannel that contains this component it does not rerender with new values, it stays the same as it was

      here is my encode and decode of the compoment

      public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
       HTMLTelephoneNumber phoneComp = (HTMLTelephoneNumber) component;
       ResponseWriter writer = context.getResponseWriter();
      
       String code = null;
       String number = null;
      
       if (phoneComp.getValue() != null) {
       if (phoneComp.getValue().contains(new StringBuffer("-"))) {
       String[] num = (phoneComp.getValue()).split("-");
       if (num.length == 1) {
       number = num[0];
       } else if (num.length == 2) {
       code = num[0];
       number = num[1];
       } else {
       code = "";
       number = "";
       }
       } else {
       number = phoneComp.getValue();
       }
       }
      
       writer.write("(");
       writer.startElement("input", phoneComp);
       writer.writeAttribute("type", "input", null);
       writer.writeAttribute("id", phoneComp.getClientId(context) + "_code", null);
       writer.writeAttribute("name", phoneComp.getClientId(context) + "_code", null);
       writer.writeAttribute("size", "5", null);
       writer.writeAttribute("maxlength", "5", null);
       writer.writeAttribute("value", code, null);
       writer.writeAttribute("disabled", phoneComp.isDisabled(), null);
       writer.endElement("input");
       writer.write(") - ");
       writer.startElement("input", phoneComp);
       writer.writeAttribute("type", "input", null);
       writer.writeAttribute("id", phoneComp.getClientId(context) + "_number", null);
       writer.writeAttribute("name", phoneComp.getClientId(context) + "_number", null);
       writer.writeAttribute("size", "10", null);
       writer.writeAttribute("maxlength", "10", null);
       writer.writeAttribute("value", number, null);
       writer.writeAttribute("disabled", phoneComp.isDisabled(), null);
       writer.endElement("input");
      
      }
      
      public void decode(FacesContext context, UIComponent component) {
       HTMLTelephoneNumber phoneComp = (HTMLTelephoneNumber) component;
      
       Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
       String clientId = phoneComp.getClientId(context);
      
       String code = requestMap.get(clientId + "_code");
       String number = requestMap.get(clientId + "_number");
      
       phoneComp.setSubmittedValue(code + "-" + number);
       phoneComp.setValue(code + "-" + number);
       phoneComp.getValueExpression("value").setValue(context.getELContext(), code + "-" + number);
      }
      


      any help please
      Thanks