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.