I am trying to get the database values saved from form into Textbox in same form. The values are loaded whenever the form is loaded. I have written a example code what I am doing below. I have 5 rows of textboxes. I have written the below code that get the values from database. But my knowledge is limited about getting those five rows of values to the five rows of textboxes either using JSP or JAVAScript. Tried searching online but didn't fine related answer. Any help will be appreciated. Thank you.
<body>
<%
String processVal = "SELECT * FROM NETWORK_ACCESS WHERE PRD_ID=?";
PreparedStatement pst = conn.prepareStatement(processVal);
pst.setString(1, ProcID);
ResultSet rsProcess=pst.executeQuery();
while(rsProcess.next())
{
SIP=rs.getString(2);
DIP=rs.getString(3);
SP=rs.getString(4);
SD=rs.getString(5);
ED=rs.getString(6);
}
%>
<table>
<tr>
<th>Sl.No</th>
<th>SIP</th>
<th>DIP</th>
<th>SP</th>
<th>Start Date</th>
<th>END Date</th>
</tr>
<tr>
<td style="align:center"> 1 </td>
<td><input type="text" name="name" id="id" size="20"> </td>
<td><input type="text" name="name1" id="id1" size="20"> </td>
<td><input type="text" name="name2" id="id2" size="20"> </td>
<td><input type="text" name="name3" id="id3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name4" id="id4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td style="align:center"> <label> 2 </label> </td>
<td><input type="text" name="name" id="id5" size="20"> </td>
<td><input type="text" name="name1" id="id6" size="20"> </td>
<td><input type="text" name="name2" id="id7" size="20"> </td>
<td><input type="text" name="name3" id="id8" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name4" id="id9" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label> 3 </label> </td>
<td><input type="text" name="name" id="id10" size="20"> </td>
<td><input type="text" name="name1" id="id11" size="20"> </td>
<td><input type="text" name="name2" id="id12" size="20"> </td>
<td><input type="text" name="name3" id="id13" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name4" id="id14" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>4 </label> </td>
<td><input type="text" name="name" id="id15" size="20"> </td>
<td><input type="text" name="name1" id="id15" size="20"> </td>
<td><input type="text" name="name2" id="id16" size="20"> </td>
<td><input type="text" name="name3" id="id17" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name4" id="id18" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>5 </label> </td>
<td><input type="text" name="name" id="id19" size="20"> </td>
<td><input type="text" name="name1" id="id20" size="20"> </td>
<td><input type="text" name="name2" id="id21" size="20"> </td>
<td><input type="text" name="name3" id="id22" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name4" id="id23" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
</table>
//write table header code here
i = 0;
while(rsProcess.next())
{
SIP=rs.getString(2);
DIP=rs.getString(3);
SP=rs.getString(4);
SD=rs.getString(5);
ED=rs.getString(6);
i++;
%>
//write code for each row of db
<tr>
<td style="align:center"> <c:out value=${i}> </td>
<td><input type="text" name="name" id="id" size="20" value="<c:out value=${SIP}>">
..........
</tr>
<%
}
%>
You should assign classes to tags. Later, you should do like these with jQuery :
var abc = $("thclass1").text();
$("input[name=input1]).val(abc);
var abcd = $("thclass2").text();
$("input[name=input2).val(abcd);
...
you should make these each inputs and th tags.
Related
index.scala.html
#(form: Form[applicationmodel.ApplicationModel])
#if(form.hasErrors) {
#for((key, value) <- form.errors) {
<p>#value(0).message</p>
}
} else {
<form action="/search" method="GET">
<label class="search-label">ID</label>
<input type="text" name="empId" id="empId" value="#(form.get().empId)"/>
<label class="search-label">HIRE DATE</label>
<input type="text" name="hireDateFrom" id="hireDateFrom" value="#(form.get().hireDateFrom)" autocomplete="off"/>
<div id="curly-dash">~</div>
<input type="text" name="hireDateTo" id="hireDateTo" value="#(form.get().hireDateTo)" autocomplete="off"/>
<br>
<label class="search-label">FIRST NAME</label>
<input type="text" name="firstName" id="firstName" value="#(form.get().firstName)"/>
<label class="search-label">MANAGER</label>
<input type="text" name="managerName" id="managerName" value="#(form.get().managerName)"/>
<br>
<div>
<label class="search-label">LAST NAME</label>
<input type="text" name="lastName" id="lastName" value="#(form.get().lastName)"/>
<input type="image" src="#routes.Assets.at("images/BtnSearch.jpg")">
</div>
</form>
</div>
<form action="/addEdit" method="POST" id="list-form">
<table id="table-list">
<caption class="position-relative">
<img src="#routes.Assets.at("images/Search.jpg")" id="btn-search" class="btn-size">
<h1 class="inline-block">Employee Records</h1>
<img src="#routes.Assets.at("images/Add.jpg")" id="btn-add" class="btn-size">
</caption>
<thead>
<tr>
<th class="solid-green-border column-title">EMPLOYEE_ID</th>
<th class="solid-green-border column-title">FIRST NAME</th>
<th class="solid-green-border column-title">LAST NAME</th>
<th class="solid-green-border column-title">EMAIL</th>
<th class="solid-green-border column-title">PHONE NUMBER</th>
<th class="solid-green-border column-title">HIRE DATE</th>
<th class="solid-green-border column-title">JOB</th>
<th class="solid-green-border column-title">SALARY</th>
<th class="solid-green-border column-title">COMMISSION_PCT</th>
<th class="solid-green-border column-title">DEPARTMENT</th>
<th class="solid-green-border column-title">MANAGER</th>
<th class="solid-green-border column-title">ACTION</th>
</tr>
</thead>
<tbody>
#for(item <- form.get().emplist) {
<tr>
<td class="solid-green-border column-content">#item.employeeId</td>
<td class="solid-green-border column-content">#item.firstName</td>
<td class="solid-green-border column-content">#item.lastName</td>
<td class="solid-green-border column-content">#item.email</td>
<td class="solid-green-border column-content">#item.phoneNo</td>
<td class="solid-green-border column-content">
<div class="position-relative">
<span class="class-hiredate">#item.displayHiredate</span>
<input type="image" src="/assets/images/imgDate.jpg" class="icon-size date" disabled>
</div>
</td>
<td class="solid-green-border column-content">#item.job.jobTitle</td>
<td class="solid-green-border column-content">#item.displaySalary</td>
<td class="solid-green-border column-content">#item.commission</td>
<td class="solid-green-border column-content department">#item.deptName</td>
<td class="solid-green-border column-content">#item.managerName</td>
<td class="solid-green-border column-content">
<input type="image" src="#routes.Assets.at("images/Edit.jpg")" class="icon-size edit"></td>
</tr>
}
</tbody>
</table>
<input type="image" src="#routes.Assets.at("images/BtnSave.jpg")" id="btn-save">
</form>
}
What syntax should i use to access the form again during bad request and get that emplist,form.get() is of no use whenever it is in bad request it seems like the form itself is not the same during index
Controller
Index
#Transactional
public static Result index() {
System.out.print("asdf");
appModel = new ApplicationModel();
Form<ApplicationModel> form =
Form.form(ApplicationModel.class).fill(appModel.init(appModel));
return ok(index.render(form));
}
Controller
upon submitting i wish to display it all again as is when i submit it with errors,i can only display as of now errors not retain its values
#Transactional
public static Result addEdit() {
Form<ApplicationModel> form =
Form.form(ApplicationModel.class).bindFromRequest();
if (form.hasErrors()) {
return badRequest(index.render(form));
}
form.get().update();
ApplicationModel newAppModel = new ApplicationModel();
form = Form.form(ApplicationModel.class).fill(newAppModel.init(newAppModel));
return ok(index.render(form));
}
Solution: After many trial and errors
Enclose it with this and access the specific value you want to achieve
#for(i <- 0 to {form("emplist").indexes.size.toInt} - 1) {
}
*I personally hope this would help future generations using play framework to help them accessing forms values with iteration :) *
my requirement is based on group of checkbox checks shipping address fields will be disable or enabled.
make clear my requirement:Wicket id:"nonDigital" having 6 check boxes.if any one of check box is checked then only shipping address section is enabled and then only user can enter value.
Here is my code
My HTML code:
<fieldset class="deliveryFormats">
<h2 class="sectionHeading">Delivery Formats</h2>
<span class="required">* Required Field</span>
<br/>
<div class="leftDiv">
<label>Non-digital</label>
<div class="radioLabel" wicket:id="nonDigital" >
<label>
<input class="checkbox" type="checkbox" name="formatType" />Beta SP NTSC
</label>
</div><!-- /.radioLabel non digital -->
</fieldset>
<fieldset class="shippingAddress" style="border-bottom: 0px;" >
<h2 class="sectionHeading">Shipping Address</h2>
<table class="form">
<tbody>
<tr>
<th class="fieldName" scope="row">Company</th>
<td class="fieldEdit">
<input class="organization" type="text" wicket:id="address.organization"/>
</td>
</tr>
<tr>
<th class="fieldName" scope="row">Address 1</th>
<td class="fieldEdit">
<input class="long" type="text" wicket:id="address.line1">
</td>
</tr>
<tr>
<th class="fieldName" scope="row">Address 2</th>
<td class="fieldEdit">
<input class=" long" type="text" wicket:id="address.line2">
</td>
</tr>
<tr>
<th class="fieldName" scope="row">Address 3</th>
<td class="fieldEdit">
<input class="long" type="text" wicket:id="address.line3">
</td>
</tr>
<tr>
<th class="fieldName" scope="row">City</th>
<td class="fieldEdit">
<input class="long" type="text" wicket:id="address.city"/>
</td>
</tr>
<tr>
<th class="fieldName" scope="row">State</th>
<td class="fieldEdit">
<input class="long" type="text" wicket:id="address.state"/>
</td>
</tr>
<tr>
<th class="fieldName" scope="row">Postal Code</th>
<td class="fieldEdit">
<input class="postalcode" type="text" wicket:id="address.postalCode"/>
</td>
</tr>
</tbody>
</table>
Java code:
List<DeliveryFormat> formatChoices = lookupProcessor.getLookupValues(DeliveryFormat.class);
List<DeliveryFormat> nonDigital = new ArrayList<DeliveryFormat>();
List<DeliveryFormat> digital = new ArrayList<DeliveryFormat>();
Iterator<DeliveryFormat> nondigitalIterator = formatChoices.iterator();
while(nondigitalIterator.hasNext()){
DeliveryFormat df = nondigitalIterator.next();
if(df.getLabel().equals("Audio Bundle") || df.getLabel().equals("XDCAM file")|| df.getLabel().equals("FTP")){
digital.add(df);
}
else
{
nonDigital.add(df);
}
}
//Add the check boxes for Delivery format for digital List
// add(new CheckBoxMultipleChoice<DeliveryFormat>("nonDigital", nonDigital, new ChoiceRenderer<DeliveryFormat>("label")));
ChoiceRenderer<DeliveryFormat> deliveryFormatShippment = new ChoiceRenderer<DeliveryFormat>("label", "id");
CheckBoxMultipleChoice<DeliveryFormat> nonDigitalDelivery = new CheckBoxMultipleChoice<DeliveryFormat>(
"nonDigital", nonDigital, deliveryFormatShippment);
CheckBoxMultipleChoice<DeliveryFormat> digitalDelivery = new CheckBoxMultipleChoice<DeliveryFormat>(
"digital", digital, deliveryFormatShippment);
add(nonDigitalDelivery);
/*final CheckBox test = new CheckBox("nonDigital");
test.setOutputMarkupId(true);
nonDigitalDelivery.add(new AjaxEventBehavior("onKeyUp")
{
*//**
*
*//*
private static final long serialVersionUID = 1L;
#Override
protected void onEvent(AjaxRequestTarget target) {
// TODO Auto-generated method stub
test.setEnabled(false);
target.addComponent(test);
}
});*/
You should try to enable the markupid to be written:
textArea.setOutputMarkupId(true);
and then add this component to the target:
textArea.setEnabled(false):
target.add(textArea);
JSP page code:
<c:forEach items="${studentInfoList}" var="studentInfo">
<tr>
<td>${studentInfo.student.surname} ${studentInfo.student.name} ${studentInfo.student.patronymic}</td>
<td> ${studentInfo.group.name} </td>
<td> ${studentInfo.semester.getYear()} </td>
<td> ${studentInfo.speciality.title} </td>
<td>
<form name="changeStudent" method="POST" action="controller">
<input type="hidden" name="command" value="openChangeStudentPage"/>
<imput type="hidden" name="studentId" value="${studentInfo.student.id}"/>
<input type="submit" value="Change"/>
</form>
</td>
</tr>
</c:forEach>
Code generated in browser:
<tr>
<td>Surname Name Patr</td>
<td> KV-01 </td>
<td> 4 </td>
<td> Computer eng. </td>
<td>
<form name="changeStudent" method="POST" action="controller">
<input type="hidden" name="command" value="openChangeStudentPage"/>
<imput type="hidden" name="studentId" value="2"/>
<input type="submit" value="Change"/>
</form>
</td>
</tr>
Now at servlet I try to get "studentId" field by following code and add to request student field:
int studentId = Integer.parseInt(request.getParameter("studentId"));
Student student = DAOFactory.getInstance().getStudentDAO().findStudentById(studentId);
request.setAttribute("student", student);
But on line int studentId = Integer.parseInt(...) occurs error:
java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:454)
java.lang.Integer.parseInt(Integer.java:527)
ua.kpi.fpm.portal.command.administrator.OpenChangeStudentPageCommand.execute(OpenChangeStudentPageCommand.java:26)
ua.kpi.fpm.portal.controller.Controller.processRequest(Controller.java:53)
ua.kpi.fpm.portal.controller.Controller.doPost(Controller.java:85)
javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
I can't find out why this error occures and why studentId from form can be null.
It should be
<input type="hidden" name="studentId" value="${studentInfo.student.id}"/>
instead of
<imput type="hidden" name="studentId" value="${studentInfo.student.id}"/>
Look at imput tag that is not valid.
I want to click a text related input with preceding-sibling node my HTML is the following:
<FORM id="formid" onsubmit="" method=post name="formid" action=>
<TABLE width="100%">
<TR class=foo-even>
<TD rowSpan=3><INPUT onclick="" value=1 type=radio name="formid">upbutton1</TD>
<TD>Pearl</TD>
<TD rowSpan=3></TD>
</TR>
<TR class=foo-even>
<TD>ravenclawn</TD>
</TR>
<TR class=foo-even>
<TD>ravenclawn</TD>
</TR>
</TBODY>
</TABLE>
</TD></TR>
<TR>
<TD> </TD>
</TR>
</TBODY></TABLE>
<TABLE width="100%" >
<TBODY>
<TR>
<TD class="someclass"></TD>
</TR>
<TR>
<TD>
<TABLE class=foo width="100%" border="1px">
<TBODY>
<TR class=foo-header>
<TD></TD>
<TD><BR></TD>
<TD colSpan=3></TD>
<TD></TD>
</TR>
<TR class=foo-odd>
<TD><INPUT value=0 type=radio name="formid.samename">buttonclick1</TD>
<TD>1234</TD>
<TD>blue </TD>
<TD colSpan=2>apple2</TD>
<TD> <INPUT value=0 type=hidden name="samenameagain"></TD>
</TR>
<TR class=foo-even>
<TD><INPUT value=1 type=radio name="formid.samename">buttonclick2</TD>
<TD>1235 </TD>
<TD>blue </TD>
<TD colSpan=2>apple3</TD>
<TD> <INPUT value=0 type=hidden name="samenameagain"> </TD>
</TR>
<TR class=foo-odd>
<TD><INPUT value=2 type=radio name="formid.samename">buttonclick3</TD>
<TD>1235</TD>
<TD>sometext </TD>
<TD>Pearl</TD>
<TD></TD>
<TD> <INPUT value=0 type=hidden name="samenameagain"> </TD>
</TR>
<TR class=foo-even>
<TD><INPUT value=3 type=radio name="formid.samename">buttonclick4</TD>
<TD>1236 </TD>
<TD>blue </TD>
<TD colSpan=2>apple4</TD>
<TD> <INPUT value=0 type=hidden name="samenameagain"> </TD>
</TR>
<TR class=foo-odd>
<TD><INPUT value=4 type=radio name="formid.samename">buttonclick5</TD>
<TD>1236 </TD>
<TD>sometext </TD>
<TD>ravenclawn</TD>
<TD></TD>
<TD> <INPUT value=0 type=hidden name="samenameagain"> </TD>
</TR>
<TR class=foo-even>
<TD><INPUT value=5 type=radio name="formid.samename">buttonclick6</TD>
<TD>1237 </TD>
<TD>blue </TD>
<TD colSpan=2>apple6</TD>
<TD> <INPUT value=0 type=hidden name="samenameagain"> </TD>
</TR>
<TR class=foo-odd>
<TD><INPUT value=6 type=radio name="formid.samename">buttonclick7</TD>
<TD>1237 </TD>
<TD>sometext </TD>
<TD>ravenclawn</TD>
<TD></TD>
<TD> <INPUT value=0 type=hidden name="samenameagain"></tD>
</DIV>
My target is to click on second Pearl text related input field
Selenium code is the following:
driver.findElement(By.xpath(".//td[contains(text(),'Pearl')][1]/preceding-sibling::td")).click();
Problem:
Above code always working with first table that contains Pearl text
Observations:
That case when im modify first Pearl text to something else the code working fine
That case when im working with another text ect:"ravenclawn" its working fine without any modifications
Thanks for any advice
You just include index for table also.
For 1st table
By.xpath("//table[1]//td[contains(text(),'Pearl')]/preceding-sibling::td")
For 2nd table
By.xpath("//table[2]//td[contains(text(),'Pearl')]/preceding-sibling::td")
I have a Map Object,this Map Object has some values and i m populating these values on a jsp page but the problem is that when i post the jsp page to another controller i want the same values to be present in the map Object.
Map(Some values)--->controller--->jsp(Map+some additional values)----post----->another controller[want Map+additional values]
MailContent.java
public class MailContent {
private String from;
private String to;
private String[] toMany;
private Map<String,byte[]> attachements;
//getter setter
}
some.jsp
<f:form action="../hr/sendNotification" commandName="mailHolder">
<table>
<tr>
<td><label>From:</label></td>
<td><input class="inputq" type="text" name="from" /></td>
</tr>
<tr>
<td><label>To:</label></td>
<td><input type="text" class="inputq" name="to" id="to"></input></td>
</tr>
<tr>
<td><label>Subject:</label></td>
<td><input class="inputq" type="text" name="subject" /></td>
</tr>
<c:forEach var="attach" items="${mailHolder.attachements }" varStatus="i">
<tr>
<td><label>Attachement:${i.index+1 }</label></td>
<td><input class="inputq" type="text" value="${attach.value }" name="attachements[${i.index }].value"/>
<input class="inputq" type="text" value="${attach.key }" name="attachements[${i.index }].key"/>
</tr>
</c:forEach>
<tr>
<td><label>Message:</label></td>
<td><textarea class="tarea" cols="60" rows="10" name="message"></textarea></td>
</tr>
<tr>
<td></td>
<td><input class="fancy" type="submit" value="Send" />
<input class="fancy" type="reset"
value="Reset" /></td>
</tr>
</table>
</f:form>
The key value pair is displayed successfully on jsp but when i post it to another controller and get the values then the key part is filled with some index instead of value.
on console:
before:
MailContent [from=null, to=null, attachements={abc=[B#1d37913, xyz=[B#b20ff5}, subject=null, message=null]
Afetr post:
MailContent [from=from, to=to#gmail.com, attachements={0=[B#ebe064, 1=[B#1d90655}, subject=subject, message=message]