4 Replies Latest reply on Apr 10, 2013 5:55 AM by newuser001

    How to display the byte array as string in JSF?

    newuser001

      I need to display byte array as string in a textarea. Is this any way to display, without converting this in BackingBean.

        • 1. Re: How to display the byte array as string in JSF?
          michpetrov

          You'll need to convert it, either in the backing bean or by creating a custom converter.

          • 2. Re: How to display the byte array as string in JSF?
            newuser001

            hi Michal,

             

                    I need to convert it by custom converter.

            • 3. Re: How to display the byte array as string in JSF?
              michpetrov

              Okay, it would look like this:

               

              import javax.enterprise.context.RequestScoped;
              import javax.faces.component.UIComponent;
              import javax.faces.context.FacesContext;
              import javax.faces.convert.Converter;
              import javax.faces.convert.FacesConverter;
              import javax.inject.Named;
              
              @Named
              @RequestScoped
              @FacesConverter("myConverter")
              public class MyConverter implements Converter {
              
                  // textarea -> bean
                  @Override
                  public Object getAsObject(FacesContext context, UIComponent component, String value) {
                      // do conversion…
                  }
              
                  // bean -> textarea
                  @Override
                  public String getAsString(FacesContext context, UIComponent component, Object value) {
                      // do conversion…
                  }
              }
              

              You can ignore the FacesContext and the UIComponent, just take the value and convert it to what you need.

               

               

              Then on your page you can just do this:

              <h:inputTextarea value="#{bean.byteArray}" converter="#{myConverter}" />
              
              • 4. Re: How to display the byte array as string in JSF?
                newuser001

                hi Michal,

                 

                   Thanks a lot. its working well