i have following code in jsp used with struts2 radio button i want to know which radio button is selected in my action class so can anyone give me solution on this.
code:
<div>
<s:radio cssClass="formFieldRadio" name="selectAction" list="{'Postponed To'}"/>
<s:radio cssClass="formFieldRadio" name="selectAction" list="{'Suspended'}"/>
<s:radio cssClass="formFieldRadio" name="selectAction" list="{'cancelled'}"/>
</div>
i use diffrent radio with same name so that are displayed each in new row...
I dint understand why you need all the radio buttons with the same name.. If the names are different add the getter/setter for all the radio buttons in the actions with there same names, the in action exectute() method check the values of the radio button for true or false as
if(formFieldRadio == true)
u get to know its checked or not
You are doing it wrong, you should do it like this:
<s:radio name="selectAction" list="#{1:'Postponed To', 2: 'Suspended', 3: 'cancelled'}" />
Then in your action you should expect a numeric value (in this case, 1, 2 or 3) in an selectAction variable.
make sure you have the theme="simple" attribute so you can play freely with your css.
Related
Basically there are 3 types of Save button in a page. Now, the button which I'm trying to click on is a type="button" and remaining types of save are not defined as type="button".For all three save buttons LinkText is defined as Save. So, is there any way to click on type="button" by linkText.
HTML:
<button class="btn btn-md bgm-blue m-r-10 waves-effect" ng-click="updateUser()" type="button">Save</button>
Code which I tried:
List<WebElement> list = Util.getWebDriver().findElements(By.xpath("//*[text()='Save']"));
System.out.println("SaveButton"+list.size()); ///Returning 3 save button in a page
list.get(3).click();
Now, suppose in one page there are 4 save buttons and in another page there are 3 save buttons. So, it is not possible to make a method because each time index will differ.
If there is any way to find xpath by type="button". Will be easy for me to make a method and call it each time I want to click on"Save".
Please let me know in case of clarification.
is there any way to click on type="button" by linkText
Actually By.linkText() is use to locates <a> elements only that contain the given link text while you're trying to locate <button> element. So you can not locate desire element using By.linkText().
button which I'm trying to click on is a type="button" and remaining types of save are not defined as type="button"
As you are saying only desire button contains attribute type="button", So it is very easy to find that element using other locator as below :-
By.cssSelector() :
button[type='button']
button[type='button'][ng-click='updateUser()']
button.btn.btn-md.bgm-blue.waves-effect[type='button'][ng-click='updateUser()']
By.xpath() :
//button[text()='Save' and #type='button']
//button[.='Save' and #type='button']
//button[text()='Save' and #type='button' and #ng-click='updateUser()']
//button[.='Save' and #type='button' and #ng-click='updateUser()']
As the Save button contains class attribute you can construct an xpath as follows:
findElements(By.xpath("//button[#class='btn btn-md bgm-blue m-r-10 waves-effect'][contains(text(),'Save')]"));
I have below html code snippet for radio button .
<label for="exceptionTrue">
<span/>
<span class="check" style="background: #F3565D;"/>
<span class="box"/>
Yes
</label>
HTML displayed is the same if the radio button is selected or if not selected in the page.
Element is in span class='check' if the radio button is selected and is in span class='box if not selected.
Since the html code is present in page if the radio button is selected or not selected.So i cannot user verifying if class='check' .
.Any idea how i can verify this...I have tried is.Selected and it doesn't work
Well I don't see a problem here, you know how this radio button works and you just need to implement this verification. Find your radio button element and than:
if (element.getAttribute("class").equals("check")){
return true; }
else {
return false; }
This is just an example, you can adjust this to your code.
EDIT: When I read your question again it's really unclear so I'm not sure if this helps. You need to provide more details on this.
I am trying to click on some button (which becomes enabled after all of the fields are fill in):
<div class="savCancelContainer">
<input type="button"
value="Save"
translatekey="ACTVITY_DETAILS_SAVE_BUTTON"
class="translate" id="submitActivityDetails"
style="background-color: rgb(0, 125, 195);">
The programmers of the web-page have changed it for some reason, and now my code is no longer working correctly (the button doesn't get clicked on):
driver.findElement(By.id("submitActivityDetails")).click();
I also tried finding it by xpath, with no success.
Is there any way to click the button using the Id and Value attributes together?
Any other ideas?
Similar pages and dialogs are still working fine...
You need to create a xpath which will contain both the attribute:
//input[#id='submitActivityDetails'][#value='Save']
And Click event can be triggered in the following way:
driver.findElement(By.xpath("//input[#id='submitActivityDetails'][#value='Save']")).click();
Lemme know if it helps!
Additionally you can use css seelctor to perform that action too.
[id='submitActivityDetails'][value='Save']
I need to disable the button based on the selected row of t:dataTable.
This is the javascript method I'm calling on the row selection event
(the button should be disabled if an item in the selected row has a tooltip... it's ugly, but it was the easiest thing to do):
function processUpdateButton() {
if (!$(".selectedRow").length
|| $(".selectedRow").children().find(".tooltip").length){
$(".Update").button({disabled:true});
} else {
$(".Update").button({disabled:false});
};
}
This is the JSF commandLink:
<h:commandLink id="update" styleClass="Update iconButton"
action="#{myBB.update}"
value="#{gui['button.update']}"
tabindex="301"/>
Setting disabled attribute to the button works. The button is greyed out and if I hover the mouse over it, the cursor doesn't change as it does for other links. The problem is, that I can still click it and the method in the backing bean is called. Is there some way to prevent that?
Here's the rendered disabled button:
<a id="mainForm:update"
class="iconButton ... ui-button-disabled ui-state-disabled"
onclick="return myfaces.oam.submitForm('mainForm','mainForm:update');"
href="#" role="button" aria-disabled="true" disabled="disabled">
<span class="ui-button-text">Update</span>
</a>
I should probably remove the onClick attribute, but I don't know how I would be able to reenable it again.
Of course I can check the condition on the server after clicking the Update button, but that's the last resort. It would be nice if I could completely disable the button generated by JSF only from javascript without call to the server.
So I've found the solution. I copied the onclick attribute to another attribute on disabling button and vice versa:
var onclick;
if (!$(".selectedRow").length
|| $(".selectedRow").children().find(".tooltip").length){
$(".Update").button({disabled:true});
onclick=$(".Update").attr('onclick');
$(".Update").attr('onclick2',onclick);
$(".Update").removeAttr('onclick');
} else {
$(".Update").button({disabled:false});
onclick=$(".Update").attr('onclick2');
$(".Update").attr('onclick',onclick);
$(".Update").removeAttr('onclick2');
};
As you can see the generated html code is not a button but hyperlink. So you need to remove the link from link tag. Could try follows:
$(".Update").removeAttr('href');
I have 2 items:
radiobuttons
outputtext
What I'm trying to do is: When the user checks a radiobutton -> get the itemLabel of the checked radiobutton in my outputtext. (not itemValue)
I have following code which shows the itemValue in the output text:
<h:form>
<p:selectOneRadio layout="pageDirection" id="test" name="testy" value="#{myBean.testValue}">
<p:ajax update="testOutput"/>
<p:selectItems value="#{myBean.getAllTestItems()}" var="selecter" itemLabel="#{selecter.label}" itemValue="#{selecter.val}"/>
</p:selectOneRadio>
<h:outputText id="testOutput" value="#{myBean.testValue}"/>
</h:form>
When i select one of the radiobuttons, I get the itemValue in the outputText. However I would like to get the itemLabel of the selected item in the outputText.
How do I get the label instead of the value of the radiobutton?
Several ways.
Get it based on the collection behind #{myBean.getAllTestItems()} which already contains the items with both the label and the value. Find the item matching the selected value in there and then get the label.
Submit #{selecter} instead of #{selecter.val} as radio button item value. This way you can display the label by #{myBean.testValue.label}. You only need to provide a Converter to convert between String (in HTML and HTTP request parameter) and Selecter (in Java model).
See also:
Our selectOneMenu wiki page
How to create Primefaces radioButtons from List? (for the case you'd like to use Selecter as value)