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

Quarkus: Programmatic Views not working

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 4.0.2, 4.1.0-RC1, 5.0.0
    • 5.0.0, 4.0.3, 4.1.0-RC3
    • Extension Feature
    • None

    Description

      Original report: https://github.com/melloware/quarkus-faces/issues/444

       

      I tried to add a programmatic view with the `@View` annotation, but when I access http://localhost:8080/facelet.xhml it returns 404

       

      @View("/facelet.xhtml")
      @ApplicationScoped
      public class FaceletView extends Facelet {
          @Override
          public void apply(FacesContext facesContext, UIComponent parent) {
              if (!facesContext.getAttributes().containsKey(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) {
                  return (T) facesContext.getApplication().createComponent(facesContext, componentType, null);
              }
          }
      }
       
      

       

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: