Build-in Grails tags do not work - grails

During grails application upgrade from 1.3.8 to 2.3.9 I run into the problem that grails build-in tags are ignored.
For example lets say that GSP page has two tags:
<g:if test="${true}">OK</g:if>
<g:hiddenField name="test" />
then the result of execution will be:
OK
<g:hiddenField name="test" />
but expected result is :
OK
<input type="hidden" name="test" />
Basically tags from grails-web-2.3.9.jar are working fine but from grails-plugin-gsp-2.3.9.jar are completely ignored.
Any clue why this happens is appreciated. Thank you.
UPDATE:
I found that while executing TagLibraryLookup.afterPropertiesSet() method grailsApplication object is null, so the tag lib is not registered. Now it is not clear why it is null...
Solotion:
The problem was that within static constraints = { } of domain object it was a call of
ApplicationHolder?.getApplication().getMainContext()?.getBean(serviceName) method. It prevented the application from initialization of all required spring/grails beans by changing initialization sequence/flow.

You're missing some double-quotes here:
<g:if test=${true}>OK</g:if>
<g:hiddenField name="test" />
If you add them:
<g:if test="${true}">OK</g:if>
<g:hiddenField name="test" />
Does that help? Also, check for any changes to the default encoding that was made in Config.groovy after you upgraded.

Related

How to change a f:field (textField) by a textArea using Grails Fields Plugin

In the documentation changelog of the plugin, at Version 1.1, we can read:
Support `widget:'textarea'` constraint.
Grails has a textArea field. This is the example of the grails documentation:
<g:textArea name="myField" value="myValue" rows="5" cols="40"/>
But, if we are using Grails Fields Plugin, and we have a code like:
<f:field bean="popularExpressionsInstance" property="omg" />
How could we convert it to textArea to allow to type several lines of text?
In your popularExpressions domain class, add the following constraint for omg
static constraints = {
...
omg widget: 'textarea'
}
Note: if you need to control style of textarea, you'll need to include it in the body of the f:field tag, for example
<f:field bean="popularExpressionsInstance" property="omg">
<g:textArea name="omg" cols="40" rows="5" maxlength="40" value="some default text"/>
</f:field>
You can override body of tag directly in GSP, as #user2264997 mentioned, but use ${ property } and ${it.value} variables:
<f:field property="description" widget="textarea">
<g:textArea name="${ property }" cols="40" rows="5"
value="${it.value}" />
</f:field>

Struts2 MessageResources in Apache Tiles

I'm trying unsuccessfully to use a Struts2 message resource in a tiles
2.1.4 expression. For example the following resource is available in
the JSP...
<s:text name="htmlheadHeading1"/><br/>
... but when I attempt to use the same resource in the tiles definition...
<put-attribute name="title" expression="${htmlheadHeading1}" />
... I get the error...
ELResolver cannot handle a null base Object with identifier 'htmlheadHeading1'
... Is there any way to do this??
This solution does not use tiles expressions but will work if you need to display localized text in JSP when key is passed through tiles definitions.
In tiles definition:
<put-attribute name="title" value="htmlheadHeading1" />
In your JSP then use Struts2 <s:set> tag to set title from tiles definition to local variable and then use it in <s:text> tag.
<s:set var="title">
<tiles:getAsString name="title" ignore="true"/>
</s:set>
<s:text name="%{#title}"/>

How Do I get proper error messages from Spring Security UI?

I have been using spring security UI and spring security plugin. We have our register.gsp page which works as expected. We are moving our css to twitter bootstrap so we changed register.gsp file, to match our requriements.
So we changed :
<s2ui:textFieldRow name='username' labelCode='user.username.label' bean="${command}"
size='40' labelCodeDefault='Username' value="${command.username}"/>
To :
<g:textField class="input-large" bean="${command}" name="username"
value = "${command.username}" required = "" />
Now the problem is how I render error messages? I get only default error message as now :
Property {0} ... doesn't pass custom validation.
Actually I need to get the error message of what Spring Security UI offered. How can I do that?
Thanks in advance.
You can to use:
<g:textField class="input-large" bean="${command}" name="username"
value = "${command.username}" required = "" />
<g:eachError bean="${command}">
<span>${it}</span>
</g:eachError>

JSF 2.0 Warning about a component not surronded by an h:form tag [duplicate]

I am getting the following error on my Facelet page, which simply consists of an IceFaces form with two fields and two buttons:
The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>
Here is the form:
<ice:form id="form1" partialSubmit="false">
<ice:panelLayout id="panelLayout3">
<ice:graphicImage id="graphicImage1" url="/resources/images/LoginImage.jpg" width="560" />
<ice:outputLabel for="j_username" id="outputLabel1" value="Username:"/>
<ice:outputLabel for="j_password" id="outputLabel2" value="Password:"/>
<ice:inputText binding="#{login.username}" id="j_username" required="true" />
<ice:inputSecret binding="#{login.password}" id="j_password" required="true" />
<ice:commandButton actionListener="#{login.login}" id="loginBtn" value="Login"/>
<ice:commandButton action="#{login.reset}" id="resetBtn" value="Reset"/>
<ice:outputText id="errorMessage" />
<ice:message errorClass="errorMessage" for="j_username" fatalClass="fatalMessage" id="messages1" infoClass="infoMessage" showSummary="false" warnClass="warnMessage"/>
</ice:panelLayout>
</ice:form>
How is this caused and how can I solve it?
This is not an error. This is a warning. The code looks fine, all input components are inside a form, it seems that it should run and work fine. If it indeed works fine, just ignore the warning. This warning is displayed only when the context parameter javax.faces.PROJECT_STAGE is set to Development anyway .
As to the false warning message itself, this check was introduced in Mojarra 2.1.1 as per issue 1663. However, as per issue 2147 it turns out to have some bugs and is been further improved in Mojarra 2.1.3. I'd imagine that the false warning is in your particular case caused by having an <ice:panelLayout> between the form and the input elements.
If you aren't on Mojarra 2.1.3 yet, you may want to consider upgrading to see if it removes the false warning message.

Grails remoteLink handling error codes

I'm on grails 1.3.6 and I see the following behavior.
<g:javascript library="prototype" />
...
<g:remoteLink action="punch" id="${personInstance.id}" update="damage_${personInstance.id}" on401="alert('foo!');">
generates:
<a on401="alert('foo!');" onclick="new Ajax.Updater('damage_5','/blah/person/punch/5',{asynchronous:true,evalScripts:true});return false;" href="/blah/person/punch/5"></a>
"on401" isn't a supported event attribute for an anchor tag, so is this a bug in grails?
On 1.3.5 for me, it just lost on401 attribute.
Looks like bug GRAILS-7062.

Resources