I have the following code in edit.jsp
<%
while (rs.next())
{
%>
<tr>
<TD><%=rs.getString(1)%></TD> //for text box name
<TD><%=rs.getString(2)%></TD> //for text box address
<TD><%=rs.getString(3)%></TD> //for text box origin
<td> <img src="images/editdetail.png"></td>
</tr>
while clicking the image/editdetail.png i am redirecting the page to create.jsp, where i have three text boxes("name", "address" and "origin").
how to get the getString value also getting displayed in the text box when i click the png image, so that i can edit the details.
You could pass this as params as TJ mentioned. But if you think its kinda insecure, because the details are present in the URL, you could save the details as an object in the session. using session.setAttribute().
In the create.jsp, read the object against the key and populate the text boxes accordingly.
A usecase similar to your's is illustrated in this example : http://www.jsptut.com/sessions.jsp
I believe, the create.jsp will submit the detials to another JSP. say... submit_details.jsp
in submit_details.jsp, after processing the details, do remember to remove the attribute from the session.
Related
How to handle this kind of pop-up. My goal is to get the message when Submit button clicked then validate it againts my own text (maybe using assert). I've tried to locate the element using firepath (xpath) but when i click locate Element button on firebug, the pop-up disappear.
Here is the screenshot of the pop-up.
popUp
Here is the code :
<p class="errors"></p>
<input id="email" class="form-control" type="email" value="" name="email" required="" oninput="setCustomValidity('')" oninvalid="this.setCustomValidity('Email Cannot Be Empty')" placeholder="Email *" data-placeholder="X" data-format="">
Thank you in advance.
From the scrrenshot it looks like a tooltip. Something like when we mouse over Google title in https://www.google.co.in/.
To verify tooltip we can get the attribute 'title' and verify.
Example : in https://www.google.co.in/. tooltip is placed in title attribute as below.
title="Google"
<div id="hplogo" style="background-size:272px 92px;height:92px;width:272px" title="Google" onload="window.lol&&lol()" align="left">
For your scenario, the displayed tip message is available in 'oninvalid' attribute as below. So get this attribute value and validate it.
oninvalid="this.setCustomValidity('Email Cannot Be Empty')"
If the element is not inside a iframe, then you can directly try as follows:
String emailId = driver.findElement(By.id("email")).getText()
// write string equals login here comparing emailId that is captured and the one you want to compare to.
if not, first find the iframeand switch to it and then use above code to find the element. More detailed answer related to switching b/w frame is here
Finding the elements in the Pop-up:
Instead of clicking on the Locate Element button (of Firebug) first, Right click on the element you want to find in the Pop-up, and select Inspect with Firebug, which gives the corresponding HTML code for the element.
This is a bit late in the game but the way you get the custom validity message and not the generic one you have to call the reportValidity() event within JavaScript in Selenium. You'll see a driver.executeScript() method and this is where you must call the reportValidity event on the element being validated. This is how I did it:
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions
.ElementToBeClickable(By.CssSelector("input#NewPassword.form-control")));
IWebElement input = driver.FindElement(By.CssSelector("input#NewPassword.form-control"));
input.SendKeys(string.Empty);
IWebElement form = driver.FindElement(By.TagName("form"));
form.Submit();
driver.ExecuteScript("document.getElementById('NewPassword').reportValidity();");
Assert.AreEqual("New password required", input.GetAttribute("validationMessage"));
My html page is divided in two and contains sidebar and content, in sidebar I have two dropdown boxes, one for school year and another for student name in respective school year selected in 1st dropdown and next is submit button. When I click on submit button it will redirect to next page and next page also looks same but in content page it shows selected student profile, in side bar the same two dropdowns will be there. The problem I am facing here is, first I will select school year and name. Its fine, when it goes to next page the dropdowns will be at initial stage but I want the selected year and name to be displayed on dropdown box, how can I do this?
Some one suggested me to keep the values selected in session after it goes to next page set the value of the dropdown.
Here is my code for dropdown,
<select style='width: 200px;'
id="combo_zone11" name="alfa1">
<c:forEach var="grade" items="${gradeInfo}">
<option id='syear' value="" selected="selected">
<option value=${grade.getDropDownId()}>${grade.getDropDownName()}</option>
</c:forEach>
</select>
How can I keep selected value in next page dropdown. please help me in this.
You could do this in many ways.
Since you're working in java, you can set the selected values to a hidden field, and while redirecting to next page you can set the values to request object.
Or if the target browsers support HTML5 localStorage, you can make use of it - on dropdown change, save the selected option to local storage using javascript. in the second pages load event, get the values from local storage and set the drop downs respectively.
Something like -
//Script in page1
window.onload = function(){
var dd = document.getElementById('combo_zone11');
dd.addEventListener('change',function(){
localStorage.setItem('ddValue', this.value)
});
}
//Script in page2
window.onload = function(){
var ddValue= localStorage.getItem('ddValue');
var dd= document.getElementById('combo_zone11');
for(var i = 0;i < dd.options.length;i++){
if(dd.options[i].value == ddValue ){
dd.options[i].selected = true;
break;
}
}
}
You can also make use of cookies, sessionStorage, queryStrings etc each method has it's own advantages and disadvantages...
Use select=selected by passing the id
like
<option value="${GroupLi.partyClassificationTypeId if_exists}" selected="selected"> ${GroupLi.description?if_exists}</option>
GroupLi is the list name used to iterate
as:
<#list Group as GroupLi>
i have a question about using request.getParameter(), i knew that it can use to post the value using request.getParameter, Is it necessary match request.getParameter and <input>???
My original code in HTML:
<INPUT type=submit name="submit" value="download">
In JSP:
String start = request.getParameter("submit");
Now I want to change a button and use div
div name="submit"id="submit" class="btnStyleFunc"
onclick="document.body.style.cursor='wait';this.disabled='true';
document.getElementById('form').submit();">
But it doesn't work, anyone can help me ?
Now i use the method below, but another problem is raised...the action does not stop...
String start = request.getParameter("submit1");
<input type=hidden name=submit1 value=download>
<div class="btnStyleFunc" onclick="document.body.style.cursor='wait';
this.disabled='true';document.getElementById('form').submit();">
Does anyone know what the problem is ?
A clicked submit button is a successful form control and its name/value pair will be submitted to the server in the form data.
If you submit a form with JavaScript, there is no clicked submit button, so it won't appear in the data. A div cannot have a name and is not a form control anyway — it isn't a submit button, even if it triggers JavaScript that submits the form.
Using a div with JavaScript also breaks the form for:
Anyone not using a mouse/trackpad/etc to navigate the page (a div won't get the focus when tabbing through interactive elements)
Anyone with JavaScript disabled
Anyone using a screen reader in forms mode (div elements are not form controls).
Use a real submit button instead.
I am working on struts framework in java and I have a jsp which has a select box. Onchange of this select box I am displaying some values in a second select box. The first select box is displaying the Hindi characters properly. I select some value and the onchange function is called and it goes to ajax and gets the values in second select box. THe second select box is displaying question marks.The follwing is the jsp code
District(ज़िला)
Municipality(नगर)
<html:select property="municipalitycode" bundle="utf-8"
styleId="mun_List" style="width:180px;"
onchange="getzones('myajax.do?action=getzones',this);getsections('myajax.do?action=getsections',this);">
<html:option value="">Select</html:option>
<html:optionsCollection property="municipalities" />
</html:select>
</tr>
Onchange of district, I get muncipalities.
Please help?
Character encoding can be quite tricky, make sure you haven't missed out on anything.
Refer the link below:
http://balusc.blogspot.com/2009/05/unicode-how-to-get-characters-right.html
I have a combobox with an option "other". user can select an entry from the list or select option "other". if they select "other" a text box will disply below to enter a new account number. see the code below:
<td>1. Account Number<span class="bodyCopy"><font color="#ff0000"> * </font></span>:
<html:select name="reDataForm" property="Member.accountNumber" styleClass="formContent"
style="width:80px" onchange="showfield(this.options[this.selectedIndex].value)">
<html:options collection="<%= WorkConstants.NewDropdowns.PACCT %>" property="value" labelProperty="label" styleClass="formContent"/>
</html:select>
<div id="div1"></div>
It works fine. But when the page refreshes, the text box disappears as no code to keep it there.
1)how do I keep the text box if the use was selected "Other" and entered a new account number in the text box ? OR if we can add the text box value into the dropdown list, that will also work.
2) Also how to set the text box value into the same variable Member.accountNumber ?
please help me !!!!
Use a little bit of javascript on an onLoad event to check if other is selected, and display the text box
You can't submit the value as the same name as the select box. instead, submit as a second name and process accordingly in your ActionForm on the serverside.