cancel
Showing results for 
Search instead for 
Did you mean: 

Freemarker: Problem accessing to HTML input values

santigt
Champ in-the-making
Champ in-the-making
Hi all!

In Freemarker, how can I access to HTML input values? I put an example: I have this HTML code:

<input type='text' maxlength='1024' size='32' name='searchinst' id='searchinst'/>
<span class="taskAction" onClick="javascript:includeContent();">Búsqueda</span>
<select style='width:240px;' name='inst_derivated' id='inst_derivated' size='4' multiple>
</select></td>

The "includeContent" method execute a search (using the "searchinst" input value) and put the results as select "inst_derivated" options. So, the code is something like this:

alert($('searchinst').value);
<#assign buscar="TEXT:\"" + $('searchinst').value + "\"">
<#assign docs=companyhome.nodeByReference[home].childrenByLuceneSearch["$"]?sort_by('name')>
   var i=0;
   <#list docs as d>
      $('inst_derivated').options[i].text = "${d.name}";
      $('inst_derivated').options[i].value = "${d.nodeRef}";
      i++;
   </#list>

The alert runs correctly, but there is an syntax error in this code: Expression $ is undefined

How can I access to this value?? Thanks so much!

Regards,


Santigt
14 REPLIES 14

kevinr
Star Contributor
Star Contributor
Are you posting your form results to another template? I assume so, try the 'args' object, so something like this might work:
$('args["inst_derivated"]')

Thanks,

Kevin

santigt
Champ in-the-making
Champ in-the-making
Is not another template. I use it in the same template, with JavaScript and OnClick and OnSubmit methods.

kevinr
Star Contributor
Star Contributor
This line looks wrong:
childrenByLuceneSearch["$"]

What are you trying to search for?

mliwski
Champ in-the-making
Champ in-the-making
Hi y started another topic but i need this too, I get literal
args["inst_derivated"] when i put
$('args["inst_derivated"]') 

but i need actually the value for the posted
<input type='text' maxlength='1024' size='32' name='inst_derivated' id='inst_derivated'/>

Thanks a lot.

Matías.

P.D. The other topic can be closed…

mliwski
Champ in-the-making
Champ in-the-making
I research a little more an in the wiki (http://wiki.alfresco.com/wiki/URL_Addressability)

The servlet now also supports POST'ed parameters. As with parameters passed on the URL, these will be collected and supplied to the templating data-model into a Map object called args. The args object is accessable from the root of the templating data-model and contains all the name/value pairs supplied to the servlet (usually via an HTML form). Please note though, that file upload is not supported.

So now i'm sure thats can be done…. (Still can't but certainly sure)

mikeh
Star Contributor
Star Contributor
Hi,

Try this instead:
${args["inst_derivated"]}

Thanks,
Mike

mliwski
Champ in-the-making
Champ in-the-making
I tried but retrieve's me this error, I'm trying to use with a template (can be done that)

ERROR [org.alfresco.web.ui.common.Utils] Se ha producido un Error al procesar la plantilla 'Expression args is undefined on line 15, column 20 in workspace://SpacesStore/a5c275c7-3a0e-11dc-84be-9d63854f02a0.'. Por favor contacte con el administrador del sistema.
org.alfresco.service.cmr.repository.TemplateException: Se ha producido un Error al procesar la plantilla 'Expression args is undefined on line 15, column 20 in workspace://SpacesStore/a5c275c7-3a0e-11dc-84be-9d63854f02a0.'. Por favor contacte con el administrador del sistema.
   at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:194)
   at org.alfresco.repo.processor.TemplateServiceImpl.processTemplate(TemplateServiceImpl.java:177)
   at org.alfresco.repo.processor.TemplateServiceImpl.processTemplate(TemplateServiceImpl.java:107)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
   at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy85.processTemplate(Unknown Source)
   at org.alfresco.web.ui.repo.component.template.UITemplate.encodeBegin(UITemplate.java:158)
   at javax.faces.webapp.UIComponentTag.encodeBegin(UIComponentTag.java:467)
   at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:320)
   at org.apache.jsp.jsp.dialog.document_002ddetails_jsp._jspx_meth_r_template_0(document_002ddetails_jsp.java:1994)
   at org.apache.jsp.jsp.dialog.document_002ddetails_jsp._jspx_meth_a_panel_2(document_002ddetails_jsp.java:1970)
   at org.apache.jsp.jsp.dialog.document_002ddetails_jsp._jspx_meth_a_panel_1(document_002ddetails_jsp.java:1892)
   at org.apache.jsp.jsp.dialog.document_002ddetails_jsp._jspService(document_002ddetails_jsp.java:647)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
   at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
   at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
   at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
   at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Thread.java:595)
Caused by: freemarker.core.InvalidReferenceException: Expression args is undefined on line 15, column 20 in workspace://SpacesStore/a5c275c7-3a0e-11dc-84be-9d63854f02a0.
   at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
   at freemarker.core.DynamicKeyName._getAsTemplateModel(DynamicKeyName.java:75)
   at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
   at freemarker.core.Expression.getStringValue(Expression.java:93)
   at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
   at freemarker.core.Environment.visit(Environment.java:196)
   at freemarker.core.MixedContent.accept(MixedContent.java:92)
   at freemarker.core.Environment.visit(Environment.java:196)
   at freemarker.core.Environment.process(Environment.java:176)
   at freemarker.template.Template.process(Template.java:232)
   at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:190)
   … 62 more

mikeh
Star Contributor
Star Contributor
Hi,

I've just tested this and it works as expected:
mike.html
<form method="post" action="/alfresco/service/mike">
   <input type="text" maxlength="1024" size="32" name="inst_derivated" id="inst_derivated" />
   <input type="submit" />
</form>

mike.post.html.ftl
args["inst_derivated"] = ${args["inst_derivated"]}
which outputs:
args["inst_derivated"] = hello

Could you post the relevant sections of your form HTML and Freemarker template please? Also, which version of Alfresco are you using?

Thanks,
Mike

mliwski
Champ in-the-making
Champ in-the-making
I'm not using web script i'm using "raw" ftl (apply template on document/space details)….   

In fact i'm created the template at presentation templates….   

By the way… Thanks you a lot for your quick answers…