Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

checkbox submit error

Avatar

Level 3

Hi,

I am a newbee in AEM and I want to realize the function of the multi-select box as shown below, so I created searchResult component which incluede the checkbox function.

krist_wang_0-1700718171911.png

 

when I click the submit button, but the code does not go to sling model and The error as shown below was reported

What's wrong with my code and how to modify it?

 

Best regards!

 

krist_wang_1-1700718378349.png

 

 

 

<form action="${currentPage.path}.html" method="POST" accept-charset="UTF-8">

<input type="checkbox" name="category" id="category-about" value="about" />
<label for="category-about">ABOUT</label>

<input type="checkbox" name="category" id="category-innovation" value="innovation"/>
<label for="category-innovation">INNOVATION</label>

<input type="checkbox" name="category" id="category-investors" value="investors"/>
<label for="category-investors">INVESTORS</label>

<input type="checkbox" name="category" id="category-news" value="news"/>
<label for="category-news">NEWS</label>

<input type="checkbox" name="category" id="category-sustainability" value="sustainability"/>
<label for="category-sustainability">SUSTAINABILITY</label>

<div>
<input type="submit" value="Submit" class="form-submit">
</div>
</form>

@Model(
adaptables = {SlingHttpServletRequest.class, Resource.class},
adapters = SearchResults.class,
resourceType = SearchResultsImpl.RESOURCE_TYPE,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class SearchResultsImpl implements SearchResults {
@Inject
private String[] category;

@PostConstruct
protected void init() {
if ("POST".equals(request.getMethod())) {
handleFormSubmission();
}
}

}
java.lang.IllegalArgumentException: Value '[Ljava.lang.Object;@ea85a90' for property 'category' can't be put into node '/content/astellas/global/en/search'.
	at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:76) [org.apache.sling.jcr.resource:3.2.4]
	at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:37) [org.apache.sling.jcr.resource:3.2.4]
	at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.store(SlingPropertyValueHandler.java:509) [org.apache.sling.servlets.post:2.5.0]
	at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setPropertyAsIs(SlingPropertyValueHandler.java:257) [org.apache.sling.servlets.post:2.5.0]
	at org.apache.sling.servlets.post.impl.helper.SlingPropertyValueHandler.setProperty(SlingPropertyValueHandler.java:124) [org.apache.sling.servlets.post:2.5.0]
	at org.apache.sling.servlets.post.impl.operations.ModifyOperation.writeContent(ModifyOperation.java:372) [org.apache.sling.servlets.post:2.5.0]
	at org.apache.sling.servlets.post.impl.operations.ModifyOperation.doRun(ModifyOperation.java:93) [org.apache.sling.servlets.post:2.5.0]
	at org.apache.sling.servlets.post.impl.operations.AbstractPostOperation.run(AbstractPostOperation.java:103) [org.apache.sling.servlets.post:2.5.0]
	at org.apache.sling.servlets.post.impl.SlingPostServlet.doPost(SlingPostServlet.java:243) [org.apache.sling.servlets.post:2.5.0]
	at org.apache.sling.api.servlets.SlingAllMethodsServlet.mayService(SlingAllMethodsServlet.java:146) [org.apache.sling.api:2.27.0]
	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:342) [org.apache.sling.api:2.27.0]
	at org.apache.sling.api.servlets.SlingSafeMethodsServlet.service(SlingSafeMethodsServlet.java:374) [org.apache.sling.api:2.27.0]
	at org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:518) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:88) [org.apache.sling.engine:2.12.2]
	at com.day.cq.wcm.core.impl.WCMDebugFilter.doFilter(WCMDebugFilter.java:138) [com.day.cq.wcm.cq-wcm-core:5.14.78]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.adobe.cq.dam.cfm.ui.impl.EditorCacheFilter.doFilter(EditorCacheFilter.java:102) [com.adobe.dam.cq-dam-cfm-impl:0.12.296]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.adobe.granite.metrics.knownerrors.impl.ErrorLoggingComponentFilter.doFilter(ErrorLoggingComponentFilter.java:71) [com.adobe.granite.metrics.knownerrors:0.0.24]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.12.2]
	at com.day.cq.wcm.core.impl.WCMComponentFilter.filterRootInclude(WCMComponentFilter.java:375) [com.day.cq.wcm.cq-wcm-core:5.14.78]
	at com.day.cq.wcm.core.impl.WCMComponentFilter.doFilter(WCMComponentFilter.java:190) [com.day.cq.wcm.cq-wcm-core:5.14.78]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.day.cq.wcm.core.impl.page.PageLockFilter.doFilter(PageLockFilter.java:91) [com.day.cq.wcm.cq-wcm-core:5.14.78]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.day.cq.personalization.impl.TargetComponentFilter.doFilter(TargetComponentFilter.java:94) [com.day.cq.cq-personalization:5.13.50]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.processComponent(SlingRequestProcessorImpl.java:334) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.RequestSlingFilterChain.render(RequestSlingFilterChain.java:49) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:88) [org.apache.sling.engine:2.12.2]
	at com.day.cq.dam.core.impl.assetlinkshare.AdhocAssetShareAuthHandler.doFilter(AdhocAssetShareAuthHandler.java:516) [com.day.cq.dam.cq-dam-core:5.13.498]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.12.2]
	at com.day.cq.wcm.core.impl.warp.TimeWarpFilter.doFilter(TimeWarpFilter.java:109) [com.day.cq.wcm.cq-wcm-core:5.14.78]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.12.2]
	at com.day.cq.dam.core.impl.servlet.ActivityRecordHandler.doFilter(ActivityRecordHandler.java:141) [com.day.cq.dam.cq-dam-core:5.13.498]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.adobe.granite.rest.impl.servlet.ApiResourceFilter.doFilter(ApiResourceFilter.java:70) [com.adobe.granite.rest.api:1.1.40]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.adobe.granite.requests.logging.impl.RequestLoggerImpl.doFilter(RequestLoggerImpl.java:135) [com.adobe.granite.requests.logging:1.0.22]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.12.2]
	at com.adobe.granite.rest.assets.impl.AssetContentDispositionFilter.doFilter(AssetContentDispositionFilter.java:96) [com.adobe.granite.rest.assets:1.0.68]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl.doFilter(AuthoringUIModeServiceImpl.java:395) [com.day.cq.wcm.cq-wcm-core:5.14.78]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter.doFilter(RedirectFilter.java:248) [com.day.cq.wcm.cq-wcm-mobile-core:5.11.10]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.astellas.core.filters.LoggingFilter.doFilter(LoggingFilter.java:58) [aem-astellas-project.core:0.0.1.SNAPSHOT]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter.doFilter(RequestProgressTrackerLogFilter.java:109) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.12.2]
	at com.day.cq.dam.core.impl.servlet.DisableLegacyServletFilter.executeFilter(DisableLegacyServletFilter.java:197) [com.day.cq.dam.cq-dam-core:5.13.498]
	at com.day.cq.dam.core.impl.servlet.DisableLegacyServletFilter.doFilter(DisableLegacyServletFilter.java:154) [com.day.cq.dam.cq-dam-core:5.13.498]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:84) [org.apache.sling.engine:2.12.2]
	at com.day.cq.wcm.foundation.forms.FormsHandlingServletHelper.handleFilter(FormsHandlingServletHelper.java:226) [com.day.cq.wcm.cq-wcm-foundation:5.14.28]
	at com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet.doFilter(FormsHandlingServlet.java:138) [com.day.cq.wcm.cq-wcm-foundation:5.14.28]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.adobe.granite.optout.impl.OptOutFilter.doFilter(OptOutFilter.java:76) [com.adobe.granite.optout:1.0.0]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.day.cq.wcm.foundation.forms.FormsHandlingServletHelper.handleFilter(FormsHandlingServletHelper.java:226) [com.day.cq.wcm.cq-wcm-foundation:5.14.28]
	at com.adobe.cq.wcm.core.components.internal.servlets.CoreFormHandlingServlet.doFilter(CoreFormHandlingServlet.java:123) [com.adobe.cq.core.wcm.components.core:2.21.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.day.cq.wcm.core.impl.WCMRequestFilter.doFilter(WCMRequestFilter.java:90) [com.day.cq.wcm.cq-wcm-core:5.14.78]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.adobe.cq.history.impl.HistoryRequestFilter.doFilter(HistoryRequestFilter.java:111) [com.adobe.cq.cq-history:5.12.2]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.rewriter.impl.RewriterFilter.doFilter(RewriterFilter.java:87) [org.apache.sling.rewriter:1.3.4]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.adobe.granite.httpcache.impl.InnerCacheFilter.doFilter(InnerCacheFilter.java:81) [com.adobe.granite.httpcache.core:1.0.8]
	at com.adobe.granite.httpcache.impl.InnerCacheFilter.doFilter(InnerCacheFilter.java:60) [com.adobe.granite.httpcache.core:1.0.8]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:131) [org.apache.sling.i18n:2.5.18]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.adobe.granite.csrf.impl.CSRFFilter.doFilter(CSRFFilter.java:225) [com.adobe.granite.csrf:1.0.26]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.security.impl.ContentDispositionFilter.doFilter(ContentDispositionFilter.java:162) [org.apache.sling.security:1.1.24]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl.doFilter(ResourceResolverHelperImpl.java:79) [com.adobe.granite.resourceresolverhelper:1.0.6]
	at org.apache.sling.engine.impl.filter.AbstractSlingFilterChain.doFilter(AbstractSlingFilterChain.java:78) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.SlingRequestProcessorImpl.doProcessRequest(SlingRequestProcessorImpl.java:220) [org.apache.sling.engine:2.12.2]
	at org.apache.sling.engine.impl.SlingMainServlet.service(SlingMainServlet.java:128) [org.apache.sling.engine:2.12.2]
	at org.apache.felix.http.base.internal.handler.ServletHandler.handle(ServletHandler.java:126) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:86) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.cors.impl.CORSFilter.doFilter(CORSFilter.java:94) [com.adobe.granite.cors:1.0.22]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.metrics.knownerrors.impl.ReportingRequestFilter.doFilter(ReportingRequestFilter.java:100) [com.adobe.granite.metrics.knownerrors:0.0.24]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.license.impl.http.LicenseCheckFilter.doFilter(LicenseCheckFilter.java:301) [com.adobe.granite.license.http:1.0.0]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.i18n.impl.I18NFilter.doFilter(I18NFilter.java:131) [org.apache.sling.i18n:2.5.18]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.featureflags.impl.FeatureManager.doFilter(FeatureManager.java:116) [org.apache.sling.featureflags:1.2.2]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.engine.impl.log.RequestLoggerFilter.doFilter(RequestLoggerFilter.java:73) [org.apache.sling.engine:2.12.2]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.engine.impl.parameters.RequestParameterSupportConfigurer.doFilter(RequestParameterSupportConfigurer.java:67) [org.apache.sling.engine:2.12.2]
	at org.apache.felix.http.base.internal.handler.FilterHandler.handle(FilterHandler.java:149) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.InvocationChain.doFilter(InvocationChain.java:81) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.Dispatcher$1.doFilter(Dispatcher.java:152) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1000) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.cors.impl.CORSFilter.doFilter(CORSFilter.java:94) [com.adobe.granite.cors:1.0.22]
	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1006) [org.apache.felix.http.jetty:4.2.2]
	at com.adobe.granite.auth.oauth.impl.OAuthCallbackFilter.doFilter(OAuthCallbackFilter.java:78) [com.adobe.granite.auth.oauth:1.9.4]
	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1006) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.sling.security.impl.ReferrerFilter.doFilter(ReferrerFilter.java:323) [org.apache.sling.security:1.1.24]
	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1006) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.sslfilter.internal.SslFilter.doFilter(SslFilter.java:97) [org.apache.felix.http.sslfilter:1.2.6]
	at org.apache.felix.http.base.internal.handler.PreprocessorHandler.handle(PreprocessorHandler.java:137) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager$2.doFilter(WhiteboardManager.java:1006) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager.invokePreprocessors(WhiteboardManager.java:1010) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.Dispatcher.dispatch(Dispatcher.java:94) [org.apache.felix.http.jetty:4.2.2]
	at org.apache.felix.http.base.internal.dispatch.DispatcherServlet.service(DispatcherServlet.java:49) [org.apache.felix.http.jetty:4.2.2]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) [org.apache.felix.http.servlet-api:1.2.0]
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:554) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:505) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:191) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:181) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.Server.handle(Server.java:516) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) [org.apache.felix.http.jetty:4.2.2]
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) [org.apache.felix.http.jetty:4.2.2]
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javax.jcr.nodetype.ConstraintViolationException: No matching property definition: category = [about, innovation]
	at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:514) [org.apache.jackrabbit.oak-jcr:1.48.0.T20230202132234-aa49252]
	at org.apache.jackrabbit.oak.jcr.session.NodeImpl$39.perform(NodeImpl.java:1495) [org.apache.jackrabbit.oak-jcr:1.48.0.T20230202132234-aa49252]
	at org.apache.jackrabbit.oak.jcr.session.NodeImpl$39.perform(NodeImpl.java:1482) [org.apache.jackrabbit.oak-jcr:1.48.0.T20230202132234-aa49252]
	at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:229) [org.apache.jackrabbit.oak-jcr:1.48.0.T20230202132234-aa49252]
	at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:113) [org.apache.jackrabbit.oak-jcr:1.48.0.T20230202132234-aa49252]
	at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1482) [org.apache.jackrabbit.oak-jcr:1.48.0.T20230202132234-aa49252]
	at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:404) [org.apache.jackrabbit.oak-jcr:1.48.0.T20230202132234-aa49252]
	at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:71) [org.apache.sling.jcr.resource:3.2.4]
	... 160 common frames omitted
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@krist_wang 

why don't you use a servlet instead of a model. Here is the sample below:

 

<form action="/bin/processFormData" method="POST" accept-charset="UTF-8">
    <input type="checkbox" name="category" id="category-about" value="about" />
    <label for="category-about">ABOUT</label>

    <input type="checkbox" name="category" id="category-innovation" value="innovation"/>
    <label for="category-innovation">INNOVATION</label>

    <input type="checkbox" name="category" id="category-investors" value="investors"/>
    <label for="category-investors">INVESTORS</label>

    <input type="checkbox" name="category" id="category-news" value="news"/>
    <label for="category-news">NEWS</label>

    <input type="checkbox" name="category" id="category-sustainability" value="sustainability"/>
    <label for="category-sustainability">SUSTAINABILITY</label>

    <div>
        <input type="submit" value="Submit" class="form-submit">
    </div>
</form>

 

The servlet to handle post:

 

package com.yourpackage.servlets;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Arrays;

@Component(
        service = { Servlet.class },
        property = {
                "sling.servlet.methods=POST",
                "sling.servlet.paths=/bin/processFormData"
        }
)
public class FormDataProcessorServlet extends SlingAllMethodsServlet {

    @Override
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
        String[] categories = request.getParameterValues("category");

        if (categories != null && categories.length > 0) {
            // Process each selected category
            Arrays.stream(categories).forEach(category -> {
                // Perform actions based on the selected category
                // For example:
                switch (category) {
                    case "about":
                        // Process 'about' category
                        break;
                    case "innovation":
                        // Process 'innovation' category
                        break;
                    case "investors":
                        // Process 'investors' category
                        break;
                    case "news":
                        // Process 'news' category
                        break;
                    case "sustainability":
                        // Process 'sustainability' category
                        break;
                    default:
                        // Handle other cases if necessary
                        break;
                }
            });
        }

        // You can redirect to a different page after processing the form data
        // response.sendRedirect("/your/thank-you-page.html");

        // Or you can simply set a response message
        response.getWriter().write("Form data processed successfully!");
    }
}

 

See if this one makes sense.

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

@krist_wang 

why don't you use a servlet instead of a model. Here is the sample below:

 

<form action="/bin/processFormData" method="POST" accept-charset="UTF-8">
    <input type="checkbox" name="category" id="category-about" value="about" />
    <label for="category-about">ABOUT</label>

    <input type="checkbox" name="category" id="category-innovation" value="innovation"/>
    <label for="category-innovation">INNOVATION</label>

    <input type="checkbox" name="category" id="category-investors" value="investors"/>
    <label for="category-investors">INVESTORS</label>

    <input type="checkbox" name="category" id="category-news" value="news"/>
    <label for="category-news">NEWS</label>

    <input type="checkbox" name="category" id="category-sustainability" value="sustainability"/>
    <label for="category-sustainability">SUSTAINABILITY</label>

    <div>
        <input type="submit" value="Submit" class="form-submit">
    </div>
</form>

 

The servlet to handle post:

 

package com.yourpackage.servlets;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Arrays;

@Component(
        service = { Servlet.class },
        property = {
                "sling.servlet.methods=POST",
                "sling.servlet.paths=/bin/processFormData"
        }
)
public class FormDataProcessorServlet extends SlingAllMethodsServlet {

    @Override
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
        String[] categories = request.getParameterValues("category");

        if (categories != null && categories.length > 0) {
            // Process each selected category
            Arrays.stream(categories).forEach(category -> {
                // Perform actions based on the selected category
                // For example:
                switch (category) {
                    case "about":
                        // Process 'about' category
                        break;
                    case "innovation":
                        // Process 'innovation' category
                        break;
                    case "investors":
                        // Process 'investors' category
                        break;
                    case "news":
                        // Process 'news' category
                        break;
                    case "sustainability":
                        // Process 'sustainability' category
                        break;
                    default:
                        // Handle other cases if necessary
                        break;
                }
            });
        }

        // You can redirect to a different page after processing the form data
        // response.sendRedirect("/your/thank-you-page.html");

        // Or you can simply set a response message
        response.getWriter().write("Form data processed successfully!");
    }
}

 

See if this one makes sense.

Avatar

Administrator

@krist_wang Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni