0

The foundation component from AEM are just plain JSP without much logic in any java bean. I now try to convert the form components java logic into Sling Models. But the start component again is not easy as there are two things to be done (copied from /libs/foundation/components/form/start/start.jsp). First:

FormsHelper.startForm(slingRequest, new JspSlingHttpServletResponseWrapper(pageContext));

Second:

componentContext.setDecorate(true);

The slingRequest is easy, when I adapt my model from it, but where to I get the pageContext from? I also need it to get the componentContext which can be retrieved through the pageContext.

I tried the following while adapting through SlingHttpServletRequest:

@SlingObject
private PageContext pc;

But this doesn't work.

EDIT:

I figured out how to create the form start component without the pageContext. Though together with the form start, there is the form end and there is one part that uses the pageContext directly (copied from /libs/foundation/components/form/end/end.jsp)

final boolean isSubmittable = FormsHelper.checkRule(resource, slingRequest, pageContext, "submittableRule");
if (isSubmittable || isEditMode) {

Not sure what this boolean is for or rather why it is checked before rendering the buttons.

So either I need a way to inject the pageContext or I need another way to build this form component with Sling Models.

Thomas
  • 6,325
  • 4
  • 30
  • 65
  • I don't think its possible.(injecting pagecontext the way you are trying to do) - pageContext cannot be created without a jsp. I am not 100% sure about this though. – awd Dec 10 '16 at 03:44
  • @awadheshv I did it with my own Annotaions attempt before SlingModels were available. Though it only works with a custom tag, but the sling:adaptTo Tag is a custom tag, so they could inject it there. But they probably don't because it is driven from Adobe and they want to promote the Sightly templating engine (no JSP) where the PageContext wont be available. – Thomas Dec 12 '16 at 09:28

1 Answers1

1

You don't necessarily need to follow same approach, if you look at javadocs, you can use startForm(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException

Ameesh Trikha
  • 1,652
  • 2
  • 12
  • 18
  • Thanks I figured this out after a few try and errors as well. I thought I need the wrapper or else the response would be committed to early. I also figured out, that you can get the componentContext via WCMUtils. Though I need to change the question as the form end component has one more pageContext reference, I couldn't get rid of by now. – Thomas Dec 09 '16 at 12:20