how to get the value of hyperlink into the action class - struts2-jquery

I want to get hyperlink attribute value in action class in struts.is there any way to get the value of hyperlink attribute value in action class. i have 4 link, if i clicked on any link, invoked single action class.
<s:url id="ajax1" action="totcal" />
<sj:a value="b1" name="b1" href="%{ajax1}" targets="progressbarchange1" >
BreakFast
</sj:a>
In above code value="b1" retrive in action class.
please help

Related

MVC formcollection not getting value set by jquery

On a button click, With Jquery, i am checking some validations & setting a value to Hidden Field & then control is redirected to HTTPPOST.
I am not able to get this value in formcollection.
HTML
<input type="hidden" name="hdnField" id="hdnField" />
Jquery
function validate(){
....
jq("#hdnField").val("somevalue");
}
Controller
HTTPPOST
form["hdnField"].ToString() is getting blank.
All the basic things are correct such as form collection object as i am getting other values of form.
If i do Inspect Element then value is seen to be set correctly to the hidden field.
What is causing this?

How do I make an AJAX call or submit form in ATG

How do I make an AJAX call or submit form in ATG. Here's the code I'm using:
document.getElementById("myP").style.visibility = "hidden";
Will this work in the sense of ATG?
For ajax calls, in applications like spring and standard J2EE, you do a GET or POST call using AJAX for the form's action URL.
In ATG, you dont have action URLs. Rather, you have bean references, somewhat like
<dsp:form id="myForm">
<dsp:input type="myField1" bean="ABCFormHandler.myField1" />
<dsp:input type="myField2" bean="ABCFormHandler.myField2" />
<dsp:input type="submit" bean="ABCFormHandler.myProcess" style="display:none"/>
<dsp:input type="button" id="formSubmitter" value="Submit"/>
</dsp:form>
Here, we have defined a method called handleMyProcess in the ABCFormHandler, which also contains the properties myField1 and myField2.
Notice that the form tag has the id "myForm".
Next, there are two fields viz. "myField1" and "myField2".
There is a submit button which is hidden, by setting the style to "display:none"
Lastly, we have a normal button, for which we have simply set an id called "formSubmitter".
Now, we will use this normal button to submit the form with id "myForm".
We just need to call the form's submit() method using jQuery, which can be done simply as:
$('#formSubmitter').on('click', function(){
$form = $('#myForm');
$form.submit();
});
Hope this helps!

how to click the submit button in the webpage

I'm working on my vb.net application to put the textbox and button as i'm using the webbrowser in my form. I have got a problem with getting the element id from the webpage. When I put the text in the textbox and when I click on the form button, I will get an error: Object reference not set to an instance of an object.
Here is the html source:
<button value="1" class="_42ft _4jy0 _11b _4jy3 _4jy1 selected" type="submit">Post</button>
Here is the code I use:
WebBrowser1.Document.GetElementById("_42ft _4jy0 _11b _4jy3 _4jy1 selected").InvokeMember("click")
Do you know how I can click the button in a webpage who have got the class id?
Your button has a class, not an id, but your code is trying to find it by ID. change your button to:
<button value="1" id="_42ft _4jy0 _11b _4jy3 _4jy1 selected" type="submit">Post</button>
or if you want to get it by class, use getElementsByClassName(""), but this returns a collection of all the buttons with that class. That means you have to know if there are more than 1 with the class name. You get the button by its index, so:
var btn = document.getElementsByClassName("_42ft _4jy0 _11b _4jy3 _4jy1 selected");
btn[0].click();
0 is the first one, 1 is the second and so on

Value of submit button not being passed to ActionForm in Struts 1.x

I am trying to implement multiple submit buttons in a Struts jsp. To do so, I am passing the value of the submit button to the ActionForm and reading that value. My setup is like this:
JSP
...snip...
<form name = "formName" action = "action.do" onSubmit = "return myFunc()" method = "POST">
<input type = "text" name = "myValue" />
<input type = "submit" name = "myButton" value = "Submit" />
</form>
...snip...
MyForm
...snip...
String myButton;
String myValue;
[Generated getters and setters]
...snip...
As far as I can tell, the submit button from the jsp should submit a value of 'Submit' to the myButton variable in MyForm, but when I try to access it in the Action Class I always get a value of null.
I know that my struts-config.xml file is configured properly because the text input in the jsp successfully populates the 'myValue' variable in MyForm, which can be read by my Action Class.
Is there something special about submit buttons in Struts that I am missing? It seems everything should work...
Any help would be appreciated.
You need to use a input type hidden for that, value property of submit buttons is only used for text on the button not for sending that value with the rest of the form data.
It is possible by using Struts JSP tags to define the form and the submit button. Why dont you use Struts JSP tags?
<html:form action="action.do">
<html:submit property="myButton" value="Submit"/>
Hope it helps

Resetting a field to its default value

I want to be able to reset all text fields to their default values when a button is clicked.
What I've done so far is query for all text fields and bind a function I wrote called 'textChanged' to the change event as follows:
require(["dojo/on","dojo/query"], function(on,query){
query(".Text").on("change",textChanged);
});
The function is defined as follows:
function textChanged(newVal)
{
...
}
I found I can reset the value in the body of the function by doing the assignment:
newVal.target.value = newVal.target.defaultValue;
If this function is triggered by a change event.
What I want to do is if a button is clicked, then I want to execute the newVal.target.value = newVal.target.defaultValue and am having trouble getting the context correct.
I've tried preserving the 'this' variable when it is called as well as preserving the 'newVal' parameter. If I try setting the value outside of the the context, then the update doesn't preserve. I've tried setting the 'this' value to some other value (nt = this) and the newValue to another variable (nv = newValue) and then I want to execute:
nv.target.value = nv.target.defaultValue;
and although it clears the field on the form, when the form is submitted, its actual value is still the manually modified value. I noticed that the 'this' is different from when I textChanged is called from the change event verses when I call it directly in my button clicked context.
I tried calling it using 'hitch' to set the context of this to its value that it had from the change event, but that doesn't seem to set the correct context:
require(["dojo/on", "dojo/_base/lang"], function(on, lang) {
lang.hitch(nt, textChanged(nv));
});
To be precise - inside textChanged I display the value of 'this' using console.log(this);
When textChanged is invoked when the text changes from the UI, 'this' is:
Yet when it is invoked from clicking my button that calls it via the
lang.hitch(nt, textChanged(nv));
'this' is:
Window fauxRedirect.lsw?applicationInstanceId=guid%3A1eae6af09bf6f543%3A-6644aeb4%3A13a8a4c429e%3A-7ffe&zWorkflowState=2&zTaskId=p1&applicationId=2&zComponentName=CoachNG&zComponentId=3028.b1094dc3-da2b-461a-8d56-f6444891c174&zDbg=2#%20%20
I've confirmed that 'nt' is indeed the same '
So, I'm trying to execute the textChanged function such that 'this' is set to that value.
Or, if there is a better way to reset a field to its default from another control - that would work as well.
Thanks in advance.
I'm not sure of the full context of what you are trying to do, so don't know if this answers your question?
You can reset all of the widgets within a form to their default value as long as they are wrapped in a dijit/form/Form widget. If all the widgets are wrapped correctly it should be a simple matter of calling reset() on the form.
NB: This will not work for native elements (ie. standard <input> or <textarea> fields, they must be dijit/form/TextBox ...etc).
eg:
<form data-dojo-type="dijit/form/Form" data-dojo-id="theForm">
<label for="field1">Field 1:</label>
<input
type="text" id="field1" name="field1"
data-dojo-type="dijit/form/TextBox" value="default1"
/><br />
<label for="field2">Field 1:</label>
<input
type="text" id="field2" name="field2"
data-dojo-type="dijit/form/TextBox" value="default2"
/>
<br /><br />
<button
type="button"
data-dojo-type="dijit/form/Button"
onclick="theForm.reset();"
>Reset</button>
</form>
Clicking the reset button here should reset the fields to: field1="default1" and feield2="default2".
The form is calling each widget's reset() method. If you create your own widgets you need to ensure that their reset() method works correctly (as well as the _getValueAttr() method for setting their value).