I'm using the <s:label>-tag from Struts 2, but it seems to render the wrong HTML code.
The two lines
<p><label for="for1" name="lable1">first content</label></p>
<p><s:label for="for2" name="lable2">second content</s:label></p>
results in
<p><label for="for1" name="lable1">first content</label></p>
<p>second content<label id="lable2" for="for2"></label></p>
Am I missing something or is this a bug? I'm using the simple theme.
Related
I am integrating a template into Rails. Every thing has been set up but I have a problem in slider.
This portion of slider is causing problems. I am passing images from assets to data attributes 1: data-thumb & 2: data-lazyload but it says Error 404 resource not found.
Static Template HTML
<li data-transition="zoomout" data-slotamount="7" data-easein="default" data-easeout="default" data-masterspeed="300" data-thumb="images/slider/bg4.jpg" data-rotate="0" data-saveperformance="off" data-title="Slide" data-description="on">
<!-- MAIN IMAGE -->
<img src="images/dummy.png" alt="laptopmockup_sliderdy" data-lazyload="images/slider/bg1.jpg">
Rails Template
<li data-transition="zoomout" data-slotamount="7" data- easein="default" data-easeout="default" data-masterspeed="300" data: {thumb: image_path("bg5.jpg")} data-rotate="0" data-saveperformance="off" data-title="Slide" data-description="on">
<!-- MAIN IMAGE -->
<%= image_tag("dummy.png", alt:"laptopmockup_sliderdy", data: { lazyload: 'slider/bg1.jpg'}) %>
I have tried these methods
data-thumb="<%= image_tag('slider/bg4.jpg")
data-thumb="<%= image_path('slider/bg4.jpg")
data-thumb="<%= asset_path('slider/bg4.jpg")
&
data: {lazyload: 'slider/bg1.jpg'}
but none of this work.Kindly guide me to make this correct.
I am trying to save a JSON object to a data- field in a gsp page.
Mock controller:
def test(){
['comments': ["1": 1, "3":40 ] ]
}
GSP (I also tried (comments as JSON) )
<%# page import="grails.converters.JSON" %>
<div class='findme' data-comments="${comments as JSON}">
Result:
<div class='findme' data-comments="{" 1":1,"3":40}">
As you can see the quotes are all messed up. I tried using encodeAsHTML but it didn't work.
I ran into this recently as well and came up with two solutions:
Solution One: in the template do this:
<div class="comments" data-comments="${comments.encodeAsJSON().encodeAsHTML()}">
Solution Two: in the controller do this:
def test(){
['comments': ["1": 1, "3":40 ] as JSON]
}
and in the template do this:
<div class="comments" data-comments="${comments.encodeAsHTML()}">
I'm using jQuery to do the parsing. With either solution I get the JSON like so:
$.parseJSON($('.comments').attr('data-comments'));
I found a couple ways to do it.
<div class='findme' data-comments="${(new JSON(comments)).toString().encodeAsURL()}">
Then I have to pull it out like:
JSON.parse(unescape($('.findme').data('comments')))
Found another way to do it, but it will cause problems if you have anything that has a " in it. I think encoding it is the way to go.
${(comments as JSON).toString().replace("\"", "'")}
I have found an easy way to do that.
First you do:
<div class="comments" data-comments="${comments.encodeAsJSON()}">
And then in javascript:
eval($('.comments').attr('data-comments'));
Since we've updated to grails 2.0.1 (from 2.0.0) all of our beans shown via bean fields are incorrectly displayed as the first property of that "withBean" field. In the example I've posted below, all of [firstName, lastName, dateOfBirth, contactNumber] are shown as just 'firstName' (we know it's not just the messages which are wrong because otherwise the 3rd property (dateOfBirth) would be a date picker, not just a text field).
Any potential workarounds or suggestions?
(plugins.bean-fields=1.0-RC3)
I encountered the same problem, and have a work-around.
I has customised beanfield templates extracted into a gsp template called /shared/_beanfieldConfig.gsp , which I then included by rendering before calling any beans tags. e.g.
<g:render template="/shared/beanFieldConfig" />
<bean:withBean beanName='command'>
<bean:input property='username' />
This worked nicely in 1.3.7, and meant I could share beanFieldConfig between views.
When upgrading to 2.0.3, I enountered the same issue as the original question. I've found I can work around this by inlining the content of my _beanFieldConfig in each view.
Yuk, but at least it means I don't need rewrite all my views to use the replacement plugin (yet).
(edit)
Interestingly, although beanField config in a render'd template doesn't work, sticking it in a taglib DOES.
so, while previously I had in beanFieldConfig
<bean:inputTemplate>
<div class='input ${errors ? 'errors' : '' }'>
${label}
${field}
<g:if test="${errors}">
${errors}
</g:if>
</div>
</bean:inputTemplate>
If I define the equivalent tag -
def beanFieldConfig = {
bean.inputTemplate { m ->
m.with {
""" <div class='input ${errors ? 'errors' : '' }'>
${label}
${field}
${errors ?: ''}
</div>"""}
}
}
and then in my gsp replace <g:render template="/shared/beanFieldConfig" /> with <g:beanFieldConfig/>, it works.
I face a problem using Grails 2 submitToRemote tag.
The following code is what I use in the controller:
def getProposal = {
def layouts = importService.getLayoutsFor(params.product as int)
render(contentType: "text/xml") {
for (layout in layouts) {
option("${layout}")
}
}
}
and in the GSP:
<g:submitToRemote action="getProposal" update="layouts"
onLoading="showProgress();" onComplete="hideProgress();"
value="Do It" />
<select id="layouts" name="layout" required="">
</select>
Using jquery this results in:
showProgress();;jQuery.ajax({type:'POST',data:jQuery(this).parents('form:first').serialize(), url:'/app/controller/getProposal',success:function(data,textStatus){jQuery('#layouts').html(data);},error:function(XMLHttpRequest,textStatus,errorThrown){},complete:function(XMLHttpRequest,textStatus){hideProgress();}});return false
which not works and returns am error:
Node cannot be inserted at the specified point in the hierarchy
But if I use another render method like:
render(status: 0, text: "<option value='1'>Layout 1</option>")
it works.
In both cases the expected answer is transmitted back.
I did not understand why it will not work with the first nicer method. Could anyone explain what I do wrong?
Thx
Edit:
I noted that if I use render(contentType: "text/text") instead it will work. May be it has something to do, that the xml is not properly formatted (no root node?). But why does it work in Grails 1.3.7?
Grails 1.3.7 had a different default javascript provider (prototype). The jquery ajax call trys to infer the type of the response based on what it receives
All,
Doing some experimenting with Spark and MVC within NerdDinner. The normal/aspx view works well, and I haven't touched any of the controller code so I'm pretty sure it's not that.
<viewdata model="System.Collections.Generic.IEnumerable[[NerdDinner.Models.Dinner]]"/>
<set Title="'Upcoming Dinners'"/>
<content:main>
<li each="p in Model">
!{Html.ActionLink(p.Title, 'Details', 'Dinners')}
</li>
</content:main>
Given the code above, the ActionLink gets rendered as http://serverName/Controller/Action/
Which is good. I start hitting a wall when I try to provide the ID to my action method. As far as I can tell from the Spark sample docs, I should be able to do something like this:
!{Html.ActionLink(p.Title, 'Details', 'Dinners', new {id = p.DinnerID} )}
However, that throws an exception:
" unexpected token '{' "
I'm hoping it's something silly I'm missing...any suggestions?
I believe there should be another parameter to Html.ActionLink for HTML attributes on the action link. Try:
!{Html.ActionLink(p.Title, 'Details', 'Dinners', new {id = p.DinnerID}, null )}