I have this:
<!-- <div class="fieldcontain ${hasErrors(bean: azafataInstance, field: 'localidad', 'error')} required" style="margin-left: 10px">-->
<!--<label for="localidad">Localidad</label> -->
<!--<g:if test="${params?.localidad }">-->
<!--<g:select id="localidad" title="${g.message(code: 'infoPersonal.localidad')}" name="localidad" value="${params?.localidad}" from="${[' ',params.localidad]}" noSelection="${['':message(code:'localidadSelect')]}" onClick="this.style.color='black'" onFocus="this.style.color='black'" style="max-width:168px" />-->
<!--</g:if>-->
<!--<g:else>-->
<!--<g:select id="localidad" title="${g.message(code: 'infoPersonal.localidad')}" name="localidad" value="${params?.localidad}" from="${['']}" noSelection="${['':message(code:'localidadSelect')]}" onClick="this.style.color='black'" onFocus="this.style.color='black'" style="max-width:168px" />-->
<!--</g:else>-->
<!--</div>-->
As you can see... lines are commented. I run the project and i got this:
URI
/com.publidirecta.azafatas/azafataCertificada/registro_page
Class
org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException
Message
Tag [else] cannot have non-whitespace characters directly preceding it.
Around line 95 of grails-app/views/azafataCertificada/registro.gsp
92:<!--<g:if test="${params?.localidad }">-->
93:<!--<g:select id="localidad" title="${g.message(code: 'infoPersonal.localidad')}" name="localidad" value="${params?.localidad}" from="${[' ',params.localidad]}" noSelection="${['':message(code:'localidadSelect')]}" onClick="this.style.color='black'" onFocus="this.style.color='black'" style="max-width:168px" />-->
94: <!--</g:if>-->
95: <!--<g:else>-->
96: <!--<g:select id="localidad" title="${g.message(code: 'infoPersonal.localidad')}" name="localidad" value="${params?.localidad}" from="${['']}" noSelection="${['':message(code:'localidadSelect')]}" onClick="this.style.color='black'" onFocus="this.style.color='black'" style="max-width:168px" />-->
97:<!--</g:else>-->
98:<!--</div>-->
Trace
Line | Method
->> 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 908 | run in ''
^ 680 | run . . in java.lang.Thread
Caused by GrailsTagException: Tag [else] cannot have non-whitespace characters directly preceding it.
->> 95 | runTask in /grails-app/views/azafataCertificada/registro.gsp
The question is, obviously...
How is it possible, in a decent framework, can a commented line throw an exception!!!
Because <!-- isn't a comment in GSP.
As you have discovered, the GSP parser treats HTML-style comments as normal content, to make it possible to generate output that contains HTML comments such as within script tags
<script type="text/javascript><!--
js goes here;
//--></script>
or IE conditional comments
<!--[if IE 6]>
<script type="text/javascript" src="${resource(dir:'css', file:'ie6-fixup.js')}"></script>
<![endif]-->
The syntax for GSP comments is
<%-- this is commented out --%>
the GSP parser will ignore anything inside this sort of comment.
Related
I got this error when I wanted to add another menu to my drop-down menu.
I am not sure why this error came up.
I added dropdown.avatar. because that what other menus also had. But it didn't work. What could I be missing here?
circle CI said it's a 33:41 error Parsing error: Unexpected token
31 | <Link route="/stats">
32 | <a>
> 33 | <Icon type="profile" /> {{t("dropdown.avatar.viewMoreStats")}}
| ^
34 | </a>
35 | </Link>
36 | </li>
I have a domain
class Node {
String nodeId
String label
Node parent
}
In the GSP page I want to start with the root and print all its children (note I have a reference to parent and not the child). Any idea how to do this ?
I am sorry but I am new and really confused. I want to print everything going down from root(not root) and root has no parent(its null). So i have written
<g:each in="${nodes}" var="node">
<g:if test="${node.parent!=null}">
${node.label}
<g:render template="node" model="[nodes:Node.findAllByParent(node)]" />
</g:if>
</g:each>
In the above code not sure what parent_node_intance should be. The nodes list starts with root. I dont want to print that but start from everything else that has root as parent.
node.gsp
<g:if test="${nodes}">
<ul>
<g:each in="${nodes}" var="node">
<li>
${node.label}
<g:render template="node" model="[nodes:Node.findAllByParent(node)]" />
</li>
</g:each>
</ul>
</g:if>
Getting the following error which I am sure is caused by the root
2014-10-02 12:28:21,693 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /taxonomy - parameters:
outputFormat: concept
hierarchyId: lp
Cannot invoke method findAllByParent() on null object. Stacktrace follows:
Message: Error evaluating expression [[nodes:Node.findAllByParent(node)]] on line [11]: Cannot invoke method findAllByParent() on null object
Line | Method
->> 11 | run in C:/Users/U6021072/Documents/workspace-ggts-3.6.0.RELEASE/ae-and-sdx-analysis-ui/target/work/plugins/taxonomy-toolkit-for-grails-0.02-SNAPSHOT/grails-app/views/taxonomy/concept.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by NullPointerException: Cannot invoke method findAllByParent() on null object
->> 11 | doCall in C__Users_U6021072_Documents_workspace_ggts_3_6_0_RELEASE_ae_and_sdx_analysis_ui_target_work_plugins_taxonomy_toolkit_for_grails_0_02_SNAPSHOT_grails_app_views_taxonomy_concept_gsp$_run_closure4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
So, you want to print all the nodes that have the known parent?
What about something like:
<g:each in="${Node.findAllByParent(parent_node_instance)}" var="node">
${node}<br>
</g:each>
But since you are talking about recursion, I think you also want to print all descendants.
Create a _node.gsp template:
<g:each in="${nodes}" var="node">
${node}<br>
<g:render template="node" model="[nodes:Node.findAllByParent(node)]" />
</g:each>
And call with:
<g:render template="node" model="[nodes:Node.findAllByParent(parent_node_instance)]" />
You can easily add a depth variable to the model to indent each generation properly, or use the <ul> and <li> elements in the template.
parent_node_instance is the root you want to start printing your tree from, it can be the absolute root or any node in the tree.
findAllByParent() is a dynamic finder function. See http://grails.org/doc/latest/guide/GORM.html#finders for details.
you can also use the #collection/#bean:
_node.gsp
<div class="fancy nested">
id:${it.nodeId} - label:${it.label}
<g:render template="node" collection="${Node.findAllByParent(it.node)}" />
</div>
main.gsp
<g:render template="node" bean="${rootNode}" />
I'm trying to add a static block (which is actually a text link) after my site's home page only, by using the Layout update XML box on the CMS pages interface.
--------------
| |
| Content |
| |
---------------
| Footer |
| Copyright |
---------------
| My Block |
---------------
I've tried adding the block using this code:
<reference name="footer">
<block type="cms/block" name="credits" after="-">
<action method="setBlockId"><block_id>my_block</block_id></action>
</block>
</reference>
The problem is: #1 that my block shows between the Footer and Copyright and #2: the change is visible on all the pages, whereas I only want it to show on my home page and not in the rest of the site...
Note: I'm running a Magento 1.4.0.1
In order to display it only at your home page you have to add your XML under <cms_index_index>.
To adjust positioning use <?php echo $this->getChildHtml('credits') ?> inside of your page/html/footer.phtml.
I'm trying to generate a comment on a single line at the end of an HTML file:
<!-- generated by SERVER1 -->
I have tried
/
generated by #{#server_name}
But this outputs it over 3 lines -
<!--
generated by SERVER1
-->
I've tried
/ generated by #{#server_name}
But that doesn't evaluate the #server_name var -
<!-- generated by #{#server_name} -->
Any ideas?
Just as you can drop back to raw HTML output when you want, so you can drop in raw HTML comments, even with interpolation.
This template:
- #foo = 42
#test1
/
Hello #{#foo}
#test2
<!-- Hello #{#foo} -->
Produces this output:
<div id='test1'>
<!--
Hello 42
-->
</div>
<div id='test2'>
<!-- Hello 42 -->
</div>
Tested with Haml v3.1.4 (Separated Sally)
It's still an open issue: github.com/haml/haml/issues/313. I think you're stuck with the multiline comment for now, even though nex3 says single line interpolation should work.
I am passing a variable logo which contains the file name of an image file from my controller to the GSP and then I try to display the image like this:
<img src="${resource(dir:'images',file:"${logo}")}" alt="Logo" border="0" />
Even though the variable logo contains the correct value I get an Unclosed GSP expression error:
java.lang.RuntimeException: Error initializing GroovyPageView
at org.grails.plugin.resource.DevModeSanityFilter.doFilter(DevModeSanityFilter.groovy:26) ~[plugin-classes/:na]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_26]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_26]
at java.lang.Thread.run(Thread.java:662) [na:1.6.0_26]
Caused by: org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Unclosed GSP expression
... 4 common frames omitted
Replacing ${logo} with the file name works.
What am I doing wrong?
Thanks a lot
Jonas
You are trying to embeed Expresion Language inside Expresion Language.
Replace:
<img src="${resource(dir:'images',file:"${logo}")}" alt="Logo" border="0" />
By
<img src="${resource(dir:'images',file:logo)}" alt="Logo" border="0" />
Inside EL you can refer to variables directly
Ernest is right that you shouldn't use a GString in this case. The actual error is that values aren't correctly quoted.
You could also do
<img src='${resource(dir:"images",file:"${logo}")}' alt="Logo" border="0" />
(notice the single-quotes and double-quotes, they are properly closed)