• 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

pass value from struts2 form to javascript

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

I try to implement UI block functionality.

I have a s:form and I call a struts2 action when submit button is clicked. I use javascript to call a struts2 action as ajax. I unblock UI when the action is finished. Blow is a simple example.

I would like to know:
1.how can i pass the field values from form to javascript call of struts2 action
2.is there another way to implement UI block functionality. I would prefer a working example.

Best regards,
Javanus

<sj:head jqueryui="true"/>
<script type="text/javascript" src="jquery.blockUI.js"></script>

<script type="text/javascript">
function funcBlockUI()
{

$.blockUI('<h1><img src="ajax-loader.gif" />Longaction...</h1>');
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
$.unblockUI();
document.write(xmlhttp.responseText);
}
}
//???how to pass value from username textfield to action???
xmlhttp.open("POST","doLongAction",true);
xmlhttp.send();
}
</script>

<s:form action="doLongAction">
<s:textfield label="User" name="username" maxlength="10" />
<s:submit onclick="funcBlockUI()"></s:submit>
</s:form>

 
Ranch Hand
Posts: 67
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you include the jQuery Head but make AJAX with plain javascript?

Use jQuery for ajax or the <sj:submit ../> button.

when using the <sj:submit ../> button you can use an onBeforeTopics to block the ui
and an onCompleteTopics to unblock it.

http://code.google.com/p/struts2-jquery/wiki/SubmitTag#AJAX_from_submit_with_Highlight_Effects_and_Events

When using the the sj:submit tag the params of your form was submitted like normal
request params. when using plain javascript you must deserialize the form and attach it to you request.

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

First I would like to thank you for your help.

I have decided to use AJAX with plain javascript because I almost give up with block UI implementation and I try to find out all possible solutions.

I am using a firefox as a default browser and unfortunately the code below does not work with firefox. Today I try to launch the code with IE and I was suprised to find it worked with IE.

The application starts to work with firefox and chrome if I comment out the <script type="text/javascript" src="jquery.blockUI.js"></script>
It looks like using jquery.blockUI.js breaks down the struts-jquery-plugin using with firefox and chrome. I found out that System.out.println from longAction works also with firefox but the redirection to done.jsp does not work with firefox.

Best regards,
http://www.javanus.com/blogs

My code snippets consist from four parts:
1.index jsp

2.done.jsp is used to display success page


3.LongAction


4.struts.xml

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

I found out that I have used an old jquery.blockUI version.

I have downloaded the latest jquery.blockUI version now but now the automatic redirection to done.jsp after completed action does not work anymore. The action called from index.jsp is finished successfully but the user is note redirected to done.jsp.

The redirection to done.jsp page works if I comment <script type="text/javascript" src="jquery.blockUI.js"></script> but then I loose the blockUI functionallity.

Does anyone know how to solve this problem? Below is my code.

Best regards,
Javanus

1.index.jsp


2.done.jsp


3.struts.xml


4.LongAction.java
 
Johannes Geppert
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have specified a target result in you submit tag.
but a html element with id result is not abailable in your jsp.

change your index.jsp to this and it should work.

 
Armin Vetek
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.



It is almost perfect after spending more then 10*n hours (n???)

Done.jsp page is presented but I would not like to include Done.jsp page inside index.jsp.

Test jQuery Block UI
User: Javanus_____
[SUBMIT]

The successful action produces the following layout. Text "Test jQuery Block UI" is from index.jsp and should not be presented. I would like to include blockUI functionality when the user click save button on the entry form. Entry form display only one record and it is used to insert/edit a record. The list of all records should be displayed after the action is successfully completed. The list of all records is displayed in another jsp page.

Test jQuery Block UI
Action Finished
Hello Javanus!

If I do not use blockUI then I got the following content. Done.jsp is not included into index.jsp but it is own page.
Action Finished
Hello javanus!

Best regards,
Javanus
 
Johannes Geppert
Ranch Hand
Posts: 67
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you not want to use ajax then remove the targets attribute from your submit tag.

Johannes
 
Armin Vetek
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I have modified the code like below. And....It works!!!

<sj:submit onClickTopics="before" value="Submit" />

Danke schön!!!

Best regards,
Javanus

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

I Am working on struts 2 to be deployed on IBM portal server. Need to use ajax. when a textfield is populated an action has to be invoked. based on the result a dropdown has to be enabled or disabled. I have tried the other samples provided in the thread but with no result. Need help asap. Thanks in advance.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to add javascript on the file tag in struts 2
when the user upload the image the javascript call
in javascript I want to calculate the %of red color in the image if it is greater then 50 then it will be uploaded
please reply soon thanks in advance
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic