I am trying to access multiple checkbox values from the jsp page.. But i am ending up with wrong bindings..
jsp page:
<c:forEach items="${employees}" var="employee">
<tr>
<td><spring:checkbox path="selectedMails" value="<c:out value='${employee.emailid}'/>"/> </td>
<td><spring:label path="employeeId">${employee.employeeId}</spring:label></td>
<td><spring:label path="employeeName">${employee.employeeName}</spring:label></td>
<td><spring:label path="emailid" >${employee.emailid}</spring:label></td>
<td><spring:label path="reportmanager">${employee.reportmanager}</spring:label></td>
</tr>
</c:forEach>
dto page
//Invitation Beans
private String [] selectedMails;
public String [] getSelectedMails() {
return selectedMails;
}
public void setSelectedMails(String [] selectedMails) {
this.selectedMails = selectedMails;
}
i am able to print ${employee.emailid} on jsp page.. but i am not able to getting back, and i need more than one values to be saved.. Please help me out
You should give the arrayindex in the path attribute for each checkbox you create.
Following changes you need to do in your jsp code.
<c:forEach items="${employees}" var="employee" varStatus="cnt">
<tr>
<td><spring:checkbox path="selectedMails[${cnt.index}]" value="<c:out value='${employee.emailid}'/>"/> </td>
<td><spring:label path="employeeId">${employee.employeeId}</spring:label></td>
<td><spring:label path="employeeName">${employee.employeeName}</spring:label></td>
<td><spring:label path="emailid" >${employee.emailid}</spring:label></td>
<td><spring:label path="reportmanager">${employee.reportmanager}</spring:label></td>
</tr>
</c:forEach>
I think this should work for you.
Hope this helps you.
Cheers.
To get more than one value you should have more than one checkbox with same name. In that case it will be putted in request as an array and you can get this values as array.
If you have single checkbox - you will get single value. Or no value at all if checkbox not checked. It not put any value to request in case if checkbox is not checked.
Related
I have a #Controller with the following #RequestMapping annotation
#RequestMapping(value={"somevalue"},
method=RequestMethod.GET,
produces=MediaType.TEXT_HTML_VALUE)
public String findOneById(#PathVariable String id, Model model){
model.addAttribute(findOneById(id));
return "some view";
}
Observe it uses #PathVariable, based on URI, it works around /persons/{id}, for example for:
/persons/100
/persons/200
it retrieves an expected person.
that #RequestMapping method works fine when:
I put the URL/URI in the same Web Browser address bar (.../persons/200)
when I generate a report of items including for each one a link to see the details (.../persons/200).
I am trying to create a search form such as follows:
<body>
<spring:url var="findOne" value="/persons/" >
</spring:url>
<form action="${findOne}" method="get">
<table>
<tr>
<td><label for="id"><spring:message code="persona.id.label"/></label></td>
<td><input name="id" id="id" value=""/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="search"/></td>
</tr>
</table>
</form>
</body>
My problem is, when I press submit the form always generates/creates the URL to do the search in the format /persons?id=100. I know it is normal and is expected.
But just being curious and of course if is possible:
Question:
What would be the new configuration to generate a URI pattern such as /persons/100 instead of /persons?id=100 when I press the submit button?
I want avoid create a new #RequestMapping method working around with a #RequestParam (it for ?id=100). It to complement the #RequesMapping method working with #PathVariable (it for /100) version.
Thanks
I have the below code in html for a WebTable(Web Grid).
<table width="90%">
<div class="greybox" style="margin-top:2%;">
<table class="datagrid" width ="100%">....<table>
</div>
</table>
I tried providing exactly the same(all) properties in my descriptive programming but the Web Element(DIV) is not being identified by QTP. Is there a unique way to identify this?
Note: The Web page is developed a single page application
Edit:
So I think I have resolved the issue with the below code. There were two Objects being identified without the "Unique Text" if clause. First Object was parent of the DIV object so had to use a "Unique text" from the first object which wouldn't be part of any other object. I am currently trying with different data to see if it's working fine
Browsername = Browser("micClass:=Browser").GetROProperty("name")
Pagename = Browser("micClass:=Browser").Page("micClass:=Page").GetROProperty("name")
Set desc = Description.Create()
desc("micclass").Value = "Webelement"
Set ChildObject=Browser("name:="&BrowserName).Page("name:="&PageName).ChildObjects(desc)
Set Child_Table_Value = nothing
For i=0 to ChildObject.Count-1
innerhtmlvalue = ChildObject(i).GetRoproperty("innerhtml")
htmltag = ChildObject(i).GetRoproperty("micclass")
if(Instr(innerhtmlvalue, "MARGIN-TOP: 2%")<>0) then
if(Instr(innerhtmlvalue, "UniqueText")=0) then
if(Instr(htmltag, "WebElement")<>0) then
Set Child_Table_Value = ChildObject(i)
End If
End If
End IF
Next
Set Table_Value = Child_Table_Value.WebTable("html tag:=Table")
Ok, so assuming you have an HTML structure something like this:
<table width="90%">
<tr>
<td>
<div class="greybox" style="margin-top:2%;">
<table class="datagrid" width="100%">
<tr>
<td>UniqueText</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
...and as per your current solution you can rely on "UniqueText" being present, then you could try the following XPath statement:
(//table[contains(., 'UniqueText')])[last()]
So in QTP/UFT you'd be doing:
Browser("micClass:=Browser").Page("micClass:=Page").WebTable("xpath:=(//table[contains(., 'UniqueText')])[last()]")
Try to use like below.(Try to identify the div block using the "class")
Browser("micClass:=Browser").Page("micClass:=Page").Webelement("class:=greybox").Webtable("class:=datagrid")
Please let me know
I am using hibernate + spring MVC. In My project there is one column in table such as :
#Column(name = "CLM_DSCRIPTION")
private Text desc;
And getter & setter Method for this
public Text getDesc() {
return desc;
}
public void setDesc(Text desc) {
this.desc = desc;
}
now i used this table in jsp where i want to show this column data into table.
M doing as below
<c:forEach items="${tbleObjs}" var="tbl" varStatus="status">
<tr>
<td>${status.index+1}</td>
<td class="labels2">${tbl.desc}</td>
</tr>
</c:forEach>
but it is not geting ${tbl.desc} here.
if i did desc.getValue() then it will work but i don't know, which is the best way to achieve this.
Please suggest me a better way.
i have achieve with following code :
<c:forEach items="${entityObjs}" var="tbl" varStatus="status">
<tr>
<%
Entity entityObj = (Entity)pageContext.getAttribute("tbl");
String disc = project.getDesc().getValue();
pageContext.setAttribute("disc",disc);
%>
<td>${status.index+1}</td>
<td class="labels2">${disc}</td>
</tr>
</c:forEach>
All -
I'm using stripes to do some form input for a problem I'm working on and I'm stuck on how best to submit a a pair of data using stripes and checkboxes.. for example my page looks like the following:
I have a list of options where users can enable a selection by clicking the box, and also supply some input for that item by entering data into the text field next to it:
<tr>
<td><stripes:checkbox name="item.enable" value="${item.id}"/></td>
<td><stripes:text name="item.value" value="${item.value}"/></td>
</tr>
.....
next item...
When the form is submitted I'd expect my Collection<Item> to be populated yet that's not the case..
How can I best submit a pair of items using the check box fields.
Thanks in advance.
..Chris
Read the documentation on indexed properties. You need to tell Stripes that you have multiple items, by naming them items[0], items[1], etc.:
<tr>
<td><stripes:checkbox name="items[0].enable" value="${item.id}"/></td>
<td><stripes:text name="items[0].value" value="${item.value}"/></td>
</tr>
<tr>
<td><stripes:checkbox name="items[1].enable" value="${item.id}"/></td>
<td><stripes:text name="items[1].value" value="${item.value}"/></td>
</tr>
This supposes that you action bean has a setItems(List<Item> items) method, that the Item class has a public no-arg constructor, and has a setEnable(String itemId) and a setValue(String value) method.
I would wrap this in a JSTL 'forEach' tag and I would put the items in a List. Similar to what JB Nizet said, you also need public setters in the action bean. If you are using Collection<Item> with some implementation other than List<Item> the below snippet won't work.
<c:forEach var='itemIndex' begin='0' end='2'>
<c:set scope='page' var='item' value='${items[itemIndex]}'>
<tr>
<td><stripes:checkbox name="items[${itemIndex}].enable" value="${item.id}"/></td>
<td><stripes:text name="items[${itemIndex}].value" value="${item.value}"/></td>
</tr>
</c:forEach>
There is another case when you don't want the list to default to 3 items. The one I'm thinking of is when the list is already populated. If that is the case I would change the 'end' attribute of the <c:forEach> to be: ${fn:length(actionBean.items) == 0 ? 3 : fn:length(actionBean.items)-1}
I have the following class that I am attempting to use as a command object
public class Member {
private String datePeriod;
private String status;
private ArrayList <Project> projectList;
}
On the JSP, I would like the form to prefill with a pre-existing values.
<c:forEach items="${member.projectList}" var="project">
<tr>
<td><form:input path="**<var???>**" value="${project.projectEntry.projectDesc}" /></td>
</tr>
</c:forEach>
I am making an error with path which is causing an error in jsp. Does anyone know the proper syntax with regards to each iteration? Thanks.
My Spring MVC is bit rusty but if I remember correctly, path gets translated as the input name property in HTML eventually. So you can put any Label value in there and that should work.
<form:input path="ProjectDescription" value="${project.projectEntry.projectDesc}" type="text" />
This should get translated to:
<input name="ProjectDescription" type="text" value="<whatever_you_have_in_backing_bean>"/>
Do you want to look up name from a backing bean instead? If so you should be able to do something like below. Without knowing your data structure I am assuming it to be status.
<form:input path="member.status" value="${project.projectEntry.projectDesc}" type="text" />
More on the form tag here.