Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-4669

Programmatic Facelet Not Rendering Correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Won't Fix
    • 4.0.2, 5.0.0, 4.1.0-RC3
    • None
    • General
    • None

    Description

      Attached is an example:

      Run 

      mvn clean jetty:run -Pmojarra40

       and navigate to http://localhost:8080/facelet.xhtml you will see the programmatic view renders correctly.

       

      Run 

      mvn clean jetty:run -Pmyfaces40

       and navigate to http://localhost:8080/facelet.xhtml you will see the programmatic view renders incorrectly with ESCAPED HTML tags.  werpu this looks like more double escaping for XML?

      package org.apache.myfaces.core.extensions.quarkus.showcase.view;
      
      import jakarta.enterprise.context.ApplicationScoped;
      import jakarta.faces.annotation.View;
      import jakarta.faces.application.StateManager;
      import jakarta.faces.component.UIComponent;
      import jakarta.faces.component.UIOutput;
      import jakarta.faces.component.html.HtmlBody;
      import jakarta.faces.component.html.HtmlCommandButton;
      import jakarta.faces.component.html.HtmlForm;
      import jakarta.faces.component.html.HtmlOutputText;
      import jakarta.faces.context.FacesContext;
      import jakarta.faces.view.facelets.Facelet;
      
      @View("/facelet.xhtml")
      @ApplicationScoped
      public class FaceletView extends Facelet
      {
      
          @Override
          public void apply(FacesContext facesContext, UIComponent parent)
          {
              if (!facesContext.getAttributes().containsKey(StateManager.IS_BUILDING_INITIAL_STATE))
              {
                  return;
              }
      
              var components = new ComponentBuilder(facesContext);
              var rootChildren = parent.getChildren();
      
              var doctype = new UIOutput();
              doctype.setValue("<!DOCTYPE html>");
              rootChildren.add(doctype);
      
              var htmlTag = new UIOutput();
              htmlTag.setValue("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
              rootChildren.add(htmlTag);
      
              HtmlBody body = components.create(HtmlBody.COMPONENT_TYPE);
              rootChildren.add(body);
      
              HtmlForm form = components.create(HtmlForm.COMPONENT_TYPE);
              form.setId("form");
              body.getChildren().add(form);
      
              HtmlOutputText message = components.create(HtmlOutputText.COMPONENT_TYPE);
              message.setId("message");
      
              HtmlCommandButton actionButton = components.create(HtmlCommandButton.COMPONENT_TYPE);
              actionButton.setId("button");
              actionButton.addActionListener(
                      e -> message.setValue("Hello, World! Welcome to Faces 4.0 on Jakarta EE 10"));
              actionButton.setValue("Greet");
      
              form.getChildren().add(actionButton);
      
              parent.getChildren().add(message);
      
              htmlTag = new UIOutput();
              htmlTag.setValue("</html>");
              rootChildren.add(htmlTag);
          }
      
          private static class ComponentBuilder
          {
              FacesContext facesContext;
      
              ComponentBuilder(FacesContext facesContext)
              {
                  this.facesContext = facesContext;
              }
      
              @SuppressWarnings("unchecked")
              <T> T create(String componentType)
              {
                  try
                  {
                      return (T) facesContext.getApplication().createComponent(componentType);
                  }
                  catch (ClassCastException e)
                  {
                      throw new IllegalArgumentException("Component type " + componentType + " is not valid.", e);
                  }
              }
          }
      }
      

      Attachments

        1. image-2024-05-28-17-42-16-539.png
          12 kB
          Melloware
        2. image-2024-05-28-17-43-37-052.png
          17 kB
          Melloware
        3. programmatic_view.zip
          7 kB
          Melloware

        Activity

          People

            Unassigned Unassigned
            melloware Melloware
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: