Grails GSP doesn't generate intended HTML under Geronimo - grails

When running my Grails 1.1-M2 app as a WAR under Geronimo 2.1.4 (jetty6, javaee5), the HTML generated from the GSPs do not include my dynamic content.
Specifically, this GSP snippet:
<tr class="prop">
<td valign="top" class="name">
<label for="type">
<g:message code="album.type.label" default="Type" />
</label>
</td>
<td valign="top" class="value ${hasErrors(bean:albumInstance,field:'type','errors')}">
<g:select from="${AlbumType?.values()}" value="${albumInstance?.type}" name="type" ></g:select>
</td>
</tr>
...produces this HTML when running under Geronimo:
<tr class="prop">
<td valign="top" class="name">
<label for="type">
Type
</label>
</td>
<td valign="top" class="value ">
<select name="type" id="type" ></select>
</td>
</tr>
...however when running as 'grails run-app' or 'grails run-war', this, correct HTML is produced:
<tr class="prop">
<td valign="top" class="name">
<label for="type">
Type
</label>
</td>
<td valign="top" class="value ">
<select name="type" id="type" >
<option value="EP" >EP</option>
<option value="LP" >LP</option>
<option value="SINGLE" >SINGLE</option>
</select>
</td>
</tr>
AlbumType.groovy is defined in src/groovy as:
public enum AlbumType {
EP,
LP,
SINGLE
}
I've turned on all logging within Grails and don't see any error or exceptions. This issue is confusing as I only see it while running my Grails WAR under Geronimo. Granted, I haven't tried any other app servers though it is curious that everything works fine with 'grails run-app' and 'grails run-war'.
Any ideas as to the problem?

I would highly recommend keeping code out of the the default package and putting it into a good package structure. I suspect this is your issue.

Related

URL found in auth.gsp - beginner

I need to know the following. I copied the following code from auth.gsp. I need to know what:
1.) I need to know what '${postUrl}' means?
2.) I did copy this code and paste it in another GSP called index.gsp, but the page didn't login successfully.
<form action='${postUrl}' method='POST' id="loginForm" name="loginForm" autocomplete='off'>
<div class="sign-in">
<h1><g:message code='spring.security.ui.login.signin'/></h1>
<table>
<tr>
<td><label for="username"><g:message code='spring.security.ui.login.username'/></label></td>
<td><input name="j_username" id="username" size="20" /></td>
</tr>
<tr>
<td><label for="password"><g:message code='spring.security.ui.login.password'/></label></td>
<td><input type="password" name="j_password" id="password" size="20" /></td>
</tr>
<tr>
<td colspan='2'>
<input type="checkbox" class="checkbox" name="${rememberMeParameter}" id="remember_me" checked="checked" />
<label for='remember_me'><g:message code='spring.security.ui.login.rememberme'/></label> |
<span class="forgot-link">
<g:link controller='register' action='forgotPassword'><g:message code='spring.security.ui.login.forgotPassword'/></g:link>
</span>
</td>
</tr>
<tr>
<td colspan='2'>
<s2ui:linkButton elementId='register' controller='register' messageCode='spring.security.ui.login.register'/>
<s2ui:submitButton elementId='loginButton' form='loginForm' messageCode='spring.security.ui.login.login'/>
</td>
</tr>
</table>
</div>
</form>
Spring security work on filters. If you print postUrl in your gsp file then it looks like /myApp/j_spring_security_check, only /j_spring_security_check URL is processed by Spring Security filter.
If you past auth.gap and not sending this url then cannot login. Change your gsp slightly to make this run, replace ${postUrl} with ${createLink(uri: '/j_spring_security_check')}.

Is there a way for me to strip away div classes and other CSS stuff when generating grails views?

Well, there goes my question. I really don't like the UI, and if there was a way to auto generate only the essential things like the fields but no divs and classes. I know about removing the css, but I really just want the raw html like what rails gives me. Anybody know how?
For example, grails generate-views myStuff generates code that looks like this:
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name">
<label for="name">Name:</label>
</td>
<td valign="top" class="value ${hasErrors(bean:feedback,field:'name','errors')}">
<input type="text" id="name" name="name" value="${fieldValue(bean:feedback,field:'name')}"/>
</td>
</tr>
<tr class="prop">
<td valign="top" class="name">
<label for="feedback">Feedback:</label>
</td>
<td valign="top" class="value ${hasErrors(bean:feedback,field:'feedback','errors')}">
<input type="text" id="feedback" name="feedback" value="${fieldValue(bean:feedback,field:'feedback')}"/>
</td>
</tr>
</tbody>
</table>
When I'm only interested in getting this:
<input type="text" id="name" name="name" value="${fieldValue(bean:feedback,field:'name')}"/>
<input type="text" id="feedback" name="feedback" value="${fieldValue(bean:feedback,field:'feedback')}"/>
Well, I could always do stuff manually and not auto-generate, but, no it's not practical when the fields are too many. :(
Use the install-templates command to install the templates. Then you can edit/modify the templates to meet your needs.

Convert automatically all forms to Grails Fields Plugin

With Grails Fields Plugin you can write an actually shorter, cleaner, DRY code:
<bean:withBean beanName="person">
<bean:field property="username" label="Login Name:"/>
<bean:field property="userRealName" label="Full Name:"/> >
</bean:withBean>
The code above would do the same than the following:
<tr class="prop">
<td valign="top" class="name"><label for="username">Login Name:</label></td>
<td valign="top" class="value ${hasErrors(bean: person, field: 'username', 'errors')}">
<input type="text" id="username" name="username" value="${person.username?.encodeAsHTML()}"/>
</td>
</tr>
<tr class="prop">
<td valign="top" class="name"><label for="userRealName">Full Name:</label></td>
<td valign="top" class="value ${hasErrors(bean: person, field: 'userRealName', 'errors')}">
<input type="text" id="userRealName" name="userRealName" value="${person.userRealName?.encodeAsHTML()}"/>
</td>
</tr>
But, must I change all my already written code manually?
If I were you, I would have stuck to one word
CONSISTENCY
I would rather convert all of them using the plugin or do not use the plugin and convert none. So that in future, I would not have to deal with two types of handling. On the other hand, if you have a lot of views to be converted and you have a short deadline, then I would add this task to my backlog.
But again, it differs from person to person. This was my opinion. I hope this could be useful.
Grails fields plugin have an option for scaffolding, so at least you can regenerate your scaffolded code.
I agree with #dmahapatro about the consistency of the code, if you choose to use the plugin, it's an effort that must be made, to make all your views have the same pattern.

Nested Form Model in Rails not saving items added with jQuery

I'm following Ryan Bate's RailsCast (#197) for Nested Model Forms.
If I submit a form that has 3 fields added in the controller:
3.times { #prof.experiences.build }
...they save properly. If the field, however, is added via jQuery, it isn't saved.
Has anyone else had experience with this sort of problem before?
EDIT: HTML Generated without jQuery:
<div class="fields">
<table>
<tbody><tr>
<td>Position Title:</td>
<td><input id="applicant_profile_experiences_attributes_0_title" name="applicant_profile[experiences_attributes][0][title]" size="30" type="text"></td>
</tr>
<tr>
<td>Employer:</td>
<td><input id="applicant_profile_experiences_attributes_0_employer" name="applicant_profile[experiences_attributes][0][employer]" size="30" type="text"></td>
</tr>
<tr>
<td>Responsibilities</td>
<td><textarea cols="40" id="applicant_profile_experiences_attributes_0_description" name="applicant_profile[experiences_attributes][0][description]" rows="4"></textarea></td>
</tr>
<tr>
<td>Start Date:</td>
<td><select id="experience_from_date_1i" name="experience[from_date(1i)]">
<option value="1970">1970</option>
<option value="1971">1971</option>
</select>
</td>
</tr>
</tbody></table>
<p><input id="applicant_profile_experiences_attributes_0__destroy" name="applicant_profile[experiences_attributes][0][_destroy]" type="hidden" value="false">Remove</p>
</div>
Code added with jQuery:
<div class="fields">
<table>
<tbody><tr>
<td>Position Title:</td>
<td><input id="applicant_profile_experiences_attributes_1366407307283_title" name="applicant_profile[experiences_attributes][1366407307283][title]" size="30" type="text"></td>
</tr>
<tr>
<td>Employer:</td>
<td><input id="applicant_profile_experiences_attributes_1366407307283_employer" name="applicant_profile[experiences_attributes][1366407307283][employer]" size="30" type="text"></td>
</tr>
<tr>
<td>Responsibilities</td>
<td><textarea cols="40" id="applicant_profile_experiences_attributes_1366407307283_description" name="applicant_profile[experiences_attributes][1366407307283][description]" rows="4"></textarea></td>
</tr>
<tr>
<td>Start Date:</td>
<td><select id="experience_from_date_1i" name="experience[from_date(1i)]">
<option value="1970">1970</option>
<option value="1971">1971</option>
<!-- removed big date list -->
</select>
</td>
</tr>
</tbody></table>
<p><input id="applicant_profile_experiences_attributes_1366407307283__destroy" name="applicant_profile[experiences_attributes][1366407307283][_destroy]" type="hidden" value="false">Remove</p>
</div>

How to define in Grails an uploadForm and 2 different actions?

I have a gsp view, with an , and 2 input text.
I have a button to save and submit.
Now I would like to add another button with a new action, in my case a button to schedule save.
Note : in my controller I have define : def save (corresponding to button action save) and def schedule (corresponding to button action schedule).
What is the best way to add Schedule in this gsp view :
<g:uploadForm action="save" method="post" >
<div class="dialog">
<table>
<tbody>
<tr class="prop">
<td valign="top" class="name">
<label for="payload">File:</label>
</td>
<td valign="top">
<input type="file" id="payload" name="payload"/>
</td>
<td valign="top">
<input type="file" id="payload2" name="payload2"/>
</td>
</tr>
<tr class="prop">
<td valign="top" class="name">
<label for="lvalue">Lvalue:</label>
</td>
<td valign="top" class="value ${hasErrors(bean:rmmInstance,field:'lvalue','errors')}">
<input type="text" id="lvalue" name="lvalue" value="${fieldValue(bean:rmmInstance,field:'lvalue')}" />
</td>
</tr>
<tr class="prop">
<td valign="top" class="name">
<label for="wvalue">Wvalue:</label>
</td>
<td valign="top" class="value ${hasErrors(bean:rmmInstance,field:'wvalue','errors')}">
<input type="text" id="wvalue" name="wvalue" value="${fieldValue(bean:rmmInstance,field:'wvalue')}" />
</td>
</tr>
</tbody>
</table>
</div>
<div class="buttons">
<span class="button"><input class="save" type="submit" value="Run Now" /></span>
</div>
</g:uploadForm>
I have just one form, but 2 different actions.
Thanks !
With an actionSubmit:
Purpose
Creates a submit button that maps to a
specific action, which allows you to
have multiple submit buttons in a
single form. Javascript event handlers
can be added using the same parameter
names as in HTML.
From the Grails reference docs.

Resources