Hi,

Can someone please help me out with the problem I mentioned below? I am
using Struts 2.0.11.2.

Any help will be greatly appreciated!!
Thanks!
Regards,
Sayali.
 
-----Original Message-----
From: Kanade, Sayali 
Sent: Monday, October 27, 2008 2:47 PM
To: user@struts.apache.org
Subject: SPAM WARNING!: Struts2 : Calling AJAX function on button click
and passing form parameters to the same

Hi All,

I am new to Struts 2, so please forgive me if this question is inane.

I have a very simple form which has some checkboxes and on the click of
the submit button of the form, I want to pass the values of the form to
an AJAX action.

############################CODE SNIPPET
STARTS#####################################################

<script type="text/javascript">
            function getResult(){
 
//document.getElementById("diaryRecords").setAttribute("href",
"/equipment.showHistory.action?serialNumber="+serialNumber);
                //alert('In Get result');
                buildValue = document.myForm.build.value;
                //alert('buildValue : '+buildValue);
                //dojo.event.topic.publish('/example/result.action',
buildValue);
        
document.myForm.hiddenbuild.value=buildValue;
        
//alert('document.myForm.hiddenbuild.value :
'+document.myForm.hiddenbuild.value)
            }
</script>

:
:

<s:form action="/example/homepage.action" method="post" name="myForm"
validate="true">
                           :
                                 :
                        <td width="5%" >
                           <input type="checkbox" name="build" />
                       </td>
                                :
                                :        
                                <tr>
                        <td ><s:submit theme="ajax" targets="resultDiv"
notifyTopics="/example/result.action" formId="myForm"
href="%{ajaxResultUrl}" onclick="getResult()" /> </td>
                                                <td><s:reset
name="reset" /></td>
                    </tr>
                </table>
               </td>

            </tr>
                        <tr>
                                <td colspan="3">
                   <s:url id="ajaxResultUrl"
value="/example/result.action" >
                       <s:param name="build" value="%{'on'}" />
                    </s:url>
                    <s:div theme="ajax" id="resultDiv" formId="myForm"
loadingText="Loading Result..." listenTopics="/example/result.action"
href="%{ajaxResultUrl}" />
                                </td>
                        </tr>
                        :
                        :
</s:form>
######################################CODE SNIPPET
ENDS#####################################

Now, I have two problems in this:
1. I am unable to pass the form parameters to the action. As you can see
that the form submits to homepage.action, but I want the AJAX call to
load from result.action. I have passed the formId to the div, but it
doesn't get the form parameters in the request. To work around this, I
am passing the value of build (build is a checkbox) as a param and
referencing the URL on the div as href.
2. The problem with pass as href : The result.action executes on page
load, I want it to execute on the submit button click and then display
the result.

Ideally, when I click submit, I want these form elements to be submitted
to result.action and the result will be displayed.

The code snippet above submits the build value as 'on' to the form and
the result is displayed on page load.

Please help, I wasn't able to get any good code examples doing this, it
would help immensely if I could get that.

Thanks for reading,
Regards,
Sayali.
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

WARNING! The attached email has been filtered as possible spam. Please
review at your own discretion. 

For additional info: <<http://infosec.web.gs.com/faqs/spam.shtml>>

Cogentrix users go to http://cgxapp/mailinfo for further instructions.

TIP: Don't unsubscribe from spam e-mail.  Unsubscribing confirms to the
spammer that a guessed e-mail address is real, and may cause you to
receive even more spam.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to