I'm trying to pass an arry into a new HashMap and then pass it into a jsp file. Problem is that it doesn't seem to be working. There is no output of my array on the jsp display. This is someof the code for the HashMap declaration.
Map<String, Object> params = new HashMap<String, Object>();
for (int x = 0; x < nl3.getLength(); x++){
Node currentItem3 = nl3.item(x);
String key3 = currentItem3.getAttributes().getNamedItem("name").getNodeValue();
if (requirement.equals(key3)) {
matchingID[x] = build;
params.put("message", matchingID[x]);}}
My jsp file looks like this
<%# include file="/include.jsp" %>
<bs:page>
<p>Please Input an Agent-Requirement</p>
<form method="get" action="/QueueStat.html">
Agent Requirement: <input type ="text" id='agentPram' name="requirement" value="${requirement}"/> <br/>
<input type="submit" value="Submit" />
List of Matching builds:
<c:forEach items="${mathcingId}" var="mathcingId">
<br><span class="mono mono-12px"><c:out value="${message}"/></span>
</c:forEach>
</jsp:attribute>
</bs:page>
Any ideas on what I'm doing wrong? I suspect that the prams.put might be incorrect. Or maybe the jsp file?
Related
I have a form:
<f:form>
<f:select path="refmap" onchange="myMethod();" name="tableName" id="tableName" >
<f:options items="${valmap}"/>
</f:select>
<input type="submit" value="Submit" formAction="return constructUrl()"/></f:form>
Mentioned functions, but guess they aren't the big issue here:
function myMethod(){
var e = document.getElementById("tableName");
var tableName = e.options[e.selectedIndex].value;
}
function constructUrl(){
var e = document.getElementById("tableName");
var tableName = e.options[e.selectedIndex].value;
return "/spravochnik/list/"+tableName;
part of my controller leading to this page:
Map refmap = new LinkedHashMap<>();
refmap.put("tableMap", valmap);
mod.addAttribute("refmap", refmap);
mod.addAttribute("command", refmap);
valMap just has names of tables (that's what I'm using in dropdown);
The thing is, the jsp is swearing at me for refmap not having valid gettter/setter. I just want to pass along the dropdown value and nothing else. What backing object should I choose?
Can you do similar to this with your code and try ? It works for me.
<select name="country">
<c:forEach items="${countries}" var="country">
<option value="${country.key}">${country.value}</option>
</c:forEach>
</select>
My Java code,
public ModelAndView getDefault(ModelAndView mav,#RequestParam(value = "QueryCode",
required = false, defaultValue = "207") String QueryCode) {
List<String> list= columnService.getColumnName(QueryCode);
mav.addObject("columnList",list);
return mav;
}
I tried something like this in JSP,
<c:set var="jspList" value="${columnList}" />
<%
for(int i = 0; i < jspList.length; i++){
%>
<input type="checkbox" name="<%= jspList[i]%>"><br/>
<%
}
%>
but it didn't work and I am getting error like,
cannot resolve symbol jspList.
You can use c:forEach:
<c:forEach items="${columnList}" var="item">
<input type="checkbox" name="${item}">
</c:forEach>
I've data in the below format.
Map<String, Map<String,List<String>>>
example - {ProfileAdaptarRepository={active=[true,false,true,true]}}}
I did set page context in mymap in the below scriptlets and it works absolutely fine.
<% pageContext.setAttribute("mymap",example);%>
I need data in the below html tabular format:
Sample HTML source code for the above image.
<html>
<body>
<table border="1">
<tr>
<th>Component</th>
<th>Properties</th>
<th>J01</th>
<th>J02</th>
<th>W01</th>
<th>W02</th>
</tr>
<tr>
<td>StoreConfiguration</td>
<td>active</td>
<td>true</td>
<td>false</td>
<td>true</td>
<td>false</td>
</tr>
<tr>
<td>DynamoConfiguration</td>
<td>enabled</td>
<td>true</td>
<td>false</td>
<td>true</td>
<td>false</td>
</tr>
</table>
</body>
</html>
I tried to present the above data in webpage using the below jstl code, but it didn't work for plural component values (more than 1 components)
<c:forEach var = "comp" items="${mymap}">
<tr>
<td>${comp.key}</td>
<c:forEach var="prop" items="${comp.value}">
<td>${prop.key}</td>
<c:forEach var="val" items="${prop.value}">
<td>${val}</td>
</c:forEach>
</c:forEach>
</tr>
</c:forEach>
Can someone please help or guide me in achieving the desired tabular format?
Many Thanks in advance..:)
I was able to run your code with multiple components. I created a data structure like yours with
List<String> myListStore = new ArrayList<>();
List<String> myListDynamo = new ArrayList<>();
List<String> myListProfile = new ArrayList<>();
Map<String, List<String>> myMapStore = new HashMap<>();
Map<String, List<String>> myMapDynamo = new HashMap<>();
Map<String, List<String>> myMapProfile = new HashMap<>();
Map<String, Map<String, List<String>>> myBigMap = new HashMap<>();
myListDynamo.add("true");
myListDynamo.add("false");
myListDynamo.add("true");
myListDynamo.add("false");
myMapDynamo.put("enabled", myListDynamo);
myBigMap.put("Dynamo", myMapDynamo);
myListStore.add("true");
myListStore.add("false");
myListStore.add("true");
myListStore.add("true");
myMapStore.put("disabled", myListStore);
myBigMap.put("Store", myMapStore);
myListProfile.add("true");
myListProfile.add("false");
myListProfile.add("true");
myListProfile.add("true");
myMapProfile.put("disabled", myListProfile);
myBigMap.put("Profile", myMapProfile);
request.setAttribute("mymap", myBigMap);
I used your exact jstl code and was able to generate the table. Are you sure that your data is in the correct format in the data structure?
I have written code in struts for fetch data from database, set in a list and show in .jsp page. I also want take some more data from user and work with it.
My list and jsp is here
ArrayList area = new ArrayList();
session.setAttribute("areaList",area);
jsp page is
<html:form action="calculate.do?parameter=doCalculate" method="post">
<logic:iterate id="rows" name="areaList" scope="session">
<tr><td><html:text name="rows" property="userGroup"/></td>
<td><html:text name="rows" property="totalArea"/></td>
<td><html:text name="rows" property="areaComplete"/></td>
<td><html:text name="rows" property="areaOccupied"/></td></tr>
</logic:iterate>
<html:submit value="Calculate"/>
Action class:
ArrayList area = (ArrayList)session.getAttribute("areaList");
for (int i=0; i<area.size(); i++) {
AreaDetails ad = (AreaDetails)area.get(i);
System.out.println("UseGRp: "+ad.getUserGroup()+" Total Area:"+ad.getTotalArea()+" Complete :"+ad.getAreaComplete()+" Ocupaid: "+ad.getAreaOccupied());
But get null "ad.getTotalArea()" and "ad.getAreaComplete()".
What will be the solution??
I'm trying to pass an ArrayList from handle.jsp to main.jsp, but it doesn't let me do it. It keeps saying "Type mismatch: cannot convert from Object to ArrayList".
main.jsp:
<%# page import="java.util.ArrayList" %>
<html>
<body>
<h1>Hobby Manager</h1>
<%
ArrayList<String> hobbies = session.getAttribute("hobbies");
out.println(hobbies.size());
out.println(session.getAttribute("hobbies"));
%>
<h2>Add new hobby!</h2>
<FORM action="handleAddHobby.jsp" method="get">
What new hobby are you wishing to add? <INPUT TYPE=text name=hobbyName /> <br/>
<INPUT TYPE=submit name=addHobby value="Add Hobby" />
</FORM>
</body>
</html>
handle.jsp:
<%# page import="java.util.ArrayList" %>
<html>
<body>
<%
ArrayList<String> hobbies = new ArrayList<String>();
String hobbyName = request.getParameter("hobbyName");
if(hobbyName == null){
out.println("Please enter a hobby before clicking add! Dummy.<br/>");
}
else{
hobbies.add(hobbyName);
for(int index = 0; index < hobbies.size(); index ++){
out.println(hobbies.get(index) + "<br/>");
}
session.setAttribute("hobbies", hobbies);
}
%>
</body>
</html>
I have tried passing it as a string object, and passing it as an object alone but nothing seems to work.
the problem is here ..
ArrayList<String> hobbies = session.getAttribute("hobbies");
Try typecasting it as getAttribute always returns Object.
ArrayList<String> hobbies = (ArrayList<String>)session.getAttribute("hobbies");