why is g:link ignoring request params? - grails

In my Grails app, I have a URL mapped directly to a view in UrlMappings.groovy
"/geolocation"(view: "/geolocation/index")
I'm trying to generate a link to this view that includes request parameters with:
<g:link elementId="btnSrcDest" uri="/geolocation" class="mapInfo"
params="[mapType: 'foo']">
Click me
</g:link>
But this generates the following HTML
<a class="mapInfo" id="btnSrcDest" href="/myApp/geolocation">
Click me
</a>
Whereas I was expecting this:
<a class="mapInfo" id="btnSrcDest" href="/myApp/geolocation?mapType=foo">
Click me
</a>
Why is the params attribute of g:link being ignored?

If you use a uri attribute then that is assumed to be the complete (webapp-relative) link and no further processing will happen. You could try making it a named URL mapping instead
name geo:"/geolocation" {
view = "/geolocation/index"
}
and then use
<g:link elementId="btnSrcDest" mapping="geo" class="mapInfo"
params="[mapType: 'foo']">

Related

how to redirect to a gsp page( grails)?

I have somme trouble in my app.
there are two domain classes :
1st named patient
2nd named antecedants
When i show a patient ,instance of antecedants is displayed.
when i click it it goes to the antecedants view/show .
the delete button below is clickable
<g:if test="${patientInstance.antecedant == null}">
<li ><g:link class="create" params="[id: patientInstance.id]" controller="Antecedants" action="create" id="${this.id }">Saisir les antecedants</g:link> </li>
</g:if>
so when i do, i sent a parameter within a g:link to the antecedants controller named num (for test) , all of this to get back to the patient it all began with:
redirect (uri: "/patient/show/${y}")
And that's where the issue comes , when i run it and go to the view/antecedant/1 and i click on delete ,it takes me to an 405 error page .description :The specified HTTP method is not allowed for the requested resource.
def y=params.num
antecedantsInstance.delete flush:true
thank you in advance.
Do you send propably a delete http method or is your action declared by a allowed method that is not the same that you sent?? If you do this, you have to add a method declaration to your action in the controller. See http://grails.org/doc/latest/ref/Controllers/allowedMethods.html

Passing url paramaters

Any idea about how can I send parameters in url query and get values of these parameters in next page
In first template I wrote this code
<a href ='r_rss/openOneNews?url={rss_link}'>{rss_title}</a>
Q:How can I get url parameter value in ExpressionEngine and use something like this in following page:
<iframe src = 'url' />
Thanks
See this answer - you want to use Mo' Variables to get the query string, which will then convert to a variable tag:
<iframe src = '{get:url}' />
Ahmed - please don't cross-post your question:
https://expressionengine.stackexchange.com/questions/14546/form-post-values
https://expressionengine.stackexchange.com/questions/14548/sending-paramters-in-url

Special charactes in query parameter

I am using 1 search option on my form. Here when i pass any special
characters like & or $ it does not hold that request parameter in the search box yeah but it is processing my request of search.
You need to URL encode the values in the query string.
I don't know Java but I used code similar to that below when sending user text to Google translate via Google URL parameter. (Assume values for myText, myURL, and myTextURL are already assigned.)
<script>
function transfix(isURL,form) {
if(isURL) window.open( myURL + encodeURIComponent(myText) );
else window.open( myTextURL + decodeURIComponent(myText) );
}
</script>
<form target=_blank id="translate" name="translate">
<input type="button" value="Text" onclick="transfix(false,this.form)">
<input type="button" value="URL" onclick="transfix(true,this.form)">
</form>

Yii framework CHtml::link error jump to a named anchor in another page

I'm use Yii Framework.
I have a named anchor <a name="projet">projet</a> in about.php page.
I've created a link in the index page to the named anchor in the about page like that :
<?php echo CHtml::link('MyLink',array('site/page','view'=>'about#projet')); ?>
But when I click on the link "MyLink", I have an error 404 response with this message :
The requested view "about#projet" was not found.
And in the url I have:
localhost/myApps/index.php?r=site/page&view=about%23projet
I checked default charset application is UTF-8. So I don't understand why my link isn't well encoded.
Someone can help me please?
try this:
echo CHtml::link('MyLink',array('site/page','view'=>'about', '#'=>'projet'));

how to get the parameters passed by URL in my Action?

In my jsp page I got a link like that :
<a href="actionEdit.do?mtitle=<%=f.getMovieTitle()%>">
Everything works fine in the page, but I want to get the value of mtitle in my Action page
I can't get it with request.getparameter()
thx for ur help
You could try:
Request.QueryString["mtitle"]
try following code:
String mtitle = request.getParameter("mtitle");

Resources