I have two <p:dailog>s and based on the condition of a bean property I want to show one of them. I have used the following code
onclick="#{empty groupBean.selectionGroup?dialog_empty.show():groupDialog.show()}"
But it is not working as it says there is an error in EL expression. I am not sure where the error is. Am I doing it the correct way?
You're treating JavaScript code as part of the EL expression. This would only result in a syntax error because EL cannot find #{dialog_empty} nor #{groupDialog} in the scope. You have to treat JavaScript code as strings by quoting them because they ultimately needs to be written to the HTML response as-is:
onclick="#{empty groupBean.selectionGroup ? 'dialog_empty.show()' : 'groupDialog.show()'}"
Related
I've seen a lot of answers about how to send PUT/DELETE/PATCH HTTP requests with thymeleaf, and it's by using th:method = "the_specific_method", but i haven't found the thymeleaf specification about that. Can anyone help showing me where is it?
Thanks in advance.
I've tried to google for the answer, but no luck.
th:method isn't special to Thymeleaf -- it's just like any other plain old attribute which will output the result of an expression to the method attribute. It doesn't do (or care about) anything else. You can put any string and/or string expression into it, and Thymeleaf will happily output it.
th:method="${'the_specific_method'}"
will output
method="the_specific_method"
without regards to whether or not it's valid. If you want to learn about the method attribute, you just need to learn about how method works in plain old regular html and how browsers (and/or Spring) work with it.
I am trying to create a variable name in thymeleaf by using another variable as prefix:
th:with="appOverview = ${__${tabId}__AppOverview}"
It works most of the times, but in the case where tabId contains dashes (i.e., "my-test-tab"), thymeleaf throws the following exception:
The operator 'SUBTRACT' is not supported between objects of type 'null' and 'null'
I guess that the dashes confuse thymeleaf into believing it's an arithmetic operation between non-existing variables.
I tested adding a variable with th:with="my-var='bad dashes'" and it worked fine, so I suppose dashes are generally accepted as characters in variable names.
Is there a way to tackle this issue?
Ah, I finally found it!
The thing I was missing is that all model variables are stored in thymeleaf in the #vars object, so accessing them from there won't confuse thymeleaf. Here's what worked:
th:with="appOverview = ${#vars.get('__${tabId}__AppOverview')}"
I don't know if the following change is an issue or it is intended.
<g:include view="line.gsp" params="['label':'test', 'progress':false]"/>
Then the expression in line.gsp aways evaluates to true, because the type of the 'progress' param is String, not Boolean.
class is: ${params.progress.getClass()}
<g:if test="${params.progress}">
this should not be displayed
</g:if>
Note that the same is applicable for other types, not just Boolean.
I am using grails 3.3.8
This didn't happen in grails 2.5.2.
I didn't find anything about this online so that's why I am asking here. Thanks.
Edit:
As suggested by Daniel, I've tried with grails 3.3.2 also.
I just created an app with grails create-app and modified the existing index.gsp to include line.gsp, as shown in the code above.
Here is a screenshot:
I realize you have already found a workaround to this, but it was bothering me that your code was not working the same way mine was, so I decided to investigate a bit further in case anyone else runs into this issue.
As other people here have mentioned, params.anything will typically return a String value. This is because params are typically encoded as URI parameters (like ?progress=false) and not autoboxed into any other type. (This is perfectly reasonable; there would be no good way for Grails to know what type they should be.) However, it is possible (and occasionally reasonable) to render your view or template from a controller like render view: whatever, model: [your: model, params: params] where you specifically include params in the model. (Perhaps you have a lot of parameters that you do not need to individually recreate in the model.) In this case, the params map will exist as both URI parameters (?progress=false) and page-scoped model entry (params: [progress: Boolean.FALSE]). Page scope takes priority over URI parameters, and so your types will be preserved.
In my testing, I added your code to an existing page where I was already passing params into the model, and so type was preserved for a newly added parameter as well. (Note that once params are in page scope, they're there for included templates or views as well.) Consequently, I saw progress type of Boolean, while in a basic example it would be type String.
TL/DR: either assume params are strings, or explicitly include params in your page-scoped model when rendering.
Yes, this is true. When you are calling params.something, you are actually accessing GrailsParameterMap which is a Map. So your condition actually evaluates as Map->get() which will be Object->toString() and of course it is true cause it's not null and not empty. So the solution will be the following:
<g:if test="${params.getBoolean("progress")}">
this should not be displayed
</g:if>
You can test this as follows
<g:if test="${params.progress && params.progress == 'false'}">
this should not be displayed
</g:if>
I am facing problem with the query parameters if they are in camelCase format.
for ex : http://localhost:9000/api/hello?personName=test
This format doesnt work with the Swagger UI. Swagger is not able to pickup any parameter defined in camelCase. It shows error "missing required params: presonName".
Hope this is clear now.
Adding one more screen shot with error
thanks
Wierd but true. I ended up finding something which is a very rare case. As you can see in the screen shot, I was using nodeType as a parameter and to my surprise, the word nodeType is a reserved word in "document" object of html. and thats the reason it creates a problem. I just changed the nodeType to nodeTypeStr and it works fine for me. But still it will be good if Swagger developers take care of handling the reserved words.
I came across some .xhtml files where for some components the expression language used was like rendered="#{empty from}", rendered="#{empty create}" etc.
I know that empty is an operator in EL, used to check whether a value is null or empty, but I did not understand the meaning of above mentioned ELs.
Can somebody explain to me what above EL's mean?
The rendered attribute is a signal whether JSF should generate HTML for the component or not. If it evaluates false, then it won't generate HTML for the component (nor for its children). The #{empty form} will evaluate false when the #{form} is not null nor empty.
Simple as that. You can find another examples of boolean expressions here: Conditionally displaying JSF components