• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

use javascript variable as query string in <s:url action

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

How to user javascript varibale as querystring in s:url

Eg:

method1(){
acridsDiv.href ='<s:url id="acrid_url" action="SearchAcridAction?acridTypeIdAjax='+tempControlId+'" namespace="/problemrecord"></s:url>';
}

I want to pass querystring into the action so 'tempControlId' variable is javascript variable. I have been trying for last two days and get not find it.

Help would be really appreciated.

Regards
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't really work like that: custom tags are run on the server, JavaScript is run on the client.

You'll need to come up with a different mechanism.
 
T Ponraj
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok,

Here is the different Mechanism,

I have got a sx:div

I want to change the div href using java script, I have tried it for two days and could not find it.



I have sx:div and In my javascript

div.href="firstaction?target=1";

alert prints the div object and proper href value

but it is not calling the action.

if I use href diectly in sx:div then it is working. Please help me.


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can't you just include the actual code so it's obvious what you're doing?
 
T Ponraj
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my code

it is calling the action and alert is printing the querystring, but the querystring is not getting passed. If I append the querystring in sx:div href, it is getting passed.

function showDialog(tempControlId){

var acridsDiv = document.getElementById("acrids");
acridsDiv.href = '/SMS/problemrecord/SearchAcridAction.action?acridTypeIdAjax='+tempControlId;
alert(acridsDiv.href); //alert is printing the href
dojo.event.topic.publish("show_acrids");
dlg.show();
}



<sx:div id="acrids"
listenTopics="show_acrids" theme="ajax"
href="/SMS/problemrecord/SearchAcridAction.action"
showLoadingText="false"
>

</sx:div>



Please see the below URL and pasted content. I m exactly trying the same. But it is not calling the action.
http://struts.apache.org/2.0.11/docs/ajax-div-template.html

JavaScript Examples:

To further illustrate these concepts here is an example. Say you want to change the url of a div at runtime via javascript. Here is what you need to do:
What you will need to do is add a JS function that listens to a JS event that publishes the id from the select box that was selected. It will modify the URL for the div (adding the id so the correct data is obtained) and then bind() the AJAX div so it refreshes.

<saf:head theme="ajax" />

<script type="text/javascript">
function updateReports(id) {
var reportDiv= window['reportDivId'];
reportDiv.href = '/../reportListRemote.action?selectedId='+id;
reportDiv.refresh();
}
dojo.event.topic.getTopic("updateReportsListTopic").subscribe(null, "updateReports");
</script>

<form ... >
<saf:select .... onchange="javascript: dojo.event.topic.publish("updateReportsListTopic", this.value); " />

<saf:div id="reportDivId" theme="ajax" href="/.../reportListRemote.action" >
Loading reports...
</saf:div>
</form>

 
T Ponraj
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got a answer:

One small mistake, it took two days to resolve.

var acridsDiv = document.getElementById("acrids"); should be

var acridsDiv = dojo.widget.byId('acrids');


Many thanks.



T Ponraj wrote:Here is my code

it is calling the action and alert is printing the querystring, but the querystring is not getting passed. If I append the querystring in sx:div href, it is getting passed.

function showDialog(tempControlId){

var acridsDiv = document.getElementById("acrids");
acridsDiv.href = '/SMS/problemrecord/SearchAcridAction.action?acridTypeIdAjax='+tempControlId;
alert(acridsDiv.href); //alert is printing the href
dojo.event.topic.publish("show_acrids");
dlg.show();
}



<sx:div id="acrids"
listenTopics="show_acrids" theme="ajax"
href="/SMS/problemrecord/SearchAcridAction.action"
showLoadingText="false"
>

</sx:div>



Please see the below URL and pasted content. I m exactly trying the same. But it is not calling the action.
http://struts.apache.org/2.0.11/docs/ajax-div-template.html

JavaScript Examples:

To further illustrate these concepts here is an example. Say you want to change the url of a div at runtime via javascript. Here is what you need to do:
What you will need to do is add a JS function that listens to a JS event that publishes the id from the select box that was selected. It will modify the URL for the div (adding the id so the correct data is obtained) and then bind() the AJAX div so it refreshes.

<saf:head theme="ajax" />

<script type="text/javascript">
function updateReports(id) {
var reportDiv= window['reportDivId'];
reportDiv.href = '/../reportListRemote.action?selectedId='+id;
reportDiv.refresh();
}
dojo.event.topic.getTopic("updateReportsListTopic").subscribe(null, "updateReports");
</script>

<form ... >
<saf:select .... onchange="javascript: dojo.event.topic.publish("updateReportsListTopic", this.value); " />

<saf:div id="reportDivId" theme="ajax" href="/.../reportListRemote.action" >
Loading reports...
</saf:div>
</form>

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, I was going to say--you'll need to access Dojo widgets through Dojo.

Please UseCodeTags when posting code fragments!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic