its me again. Basically Im checking the roles of a user once they hit a page. Its an array, lets say 1,2,3. The contents of the last column on the jsp for testing has the role #'s that are attached to each individual attachment. The last column wont be on the finished product, but I need to do some sort of IF on that array to see if any of the values in the array:
<c:forEach items = "${hotPartRoles}" var = "hpRole">
${hpRole.id}
</c:forEach>
are in the array of the attachment roles:
<c:forEach items = "${item.roles}" var = "role">
${role.id}
</c:forEach>
jsp:
<table class="data_table">
<tr>
<th>Attachments</th>
//These are the user's Roles
<c:forEach items = "${hotPartRoles}" var = "hpRole">
${hpRole.id}
</c:forEach>
</tr>
<tr>
<td class="subtable">
<table class="data_table">
<c:choose>
<c:when test='${empty attachList}'>
<tr>
<td>No Attachments</td>
</tr>
</c:when>
<c:otherwise>
<tr>
<th>Remove Attachment</th>
<th>File Name</th>
<th>File Type</th>
<th>File Size (bytes)</th>
<th>File Attached By</th>
<th>Date/Time File Attached</th>
<th>Roles</th>
</tr>
<c:forEach var="item" items="${attachList}" varStatus="loopCount">
<tr>
<td class="button">
<rbac:check operation="<%=Operation.DELETE%>">
<button type="button" onclick="javascript:delete_prompt(${item.id});">Delete</button>
</rbac:check>
</td>
<td>${item.fileName}</td>
<td>${item.fileType}</td>
<td><fmt:formatNumber value="${item.fileSize}" /></td>
<td>${item.auditable.createdBy.lastName}, ${item.auditable.createdBy.firstName}</td>
<td><fmt:formatDate value="${item.auditable.createdDate}" pattern="${date_time_pattern}" /></td>
<td>
<c:forEach items = "${item.roles}" var = "role">
${role.id}
</c:forEach>
</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
</table>
Now the arrays ont need to match exactly, just a value in the array of user roles is in the array of attachment roles....
I need to do the check here to determin whether or not to put a disable flag on the "delete" button:
<rbac:check operation="<%=Operation.DELETE%>">
<button type="button" onclick="javascript:delete_prompt(${item.id});">Delete</button>
</rbac:check>
</td>
<td>
Doing 2 nested for loops and having a var set to false initially, then set to true and checking on that var seemed to work
<c:forEach var="item" items="${attachList}" varStatus="loopCount">
<c:set var="dispVal" value="false"/>
<c:forEach items = "${item.roles}" var = "role">
<c:forEach items = "${hotPartRoles}" var = "hpRole">
<c:if test="${hpRole.id == role.id}">
<c:set var="dispVal" value="true"/>
</c:if>
</c:forEach>
</c:forEach>
<tr>
<td class="button">
<rbac:check operation="<%=Operation.DELETE%>">
<button type="button"<c:if test="${dispVal != 'true'}"> disabled="disabled"</c:if>
onclick="javascript:delete_prompt(${item.id});">Delete</button>
Create a custom EL function (which shall be an static method in a class, and a proper descriptor in your TLD file). For example a method with signature boolean contains(Collection collection, Object object). And then call it as <c:if test="x:contains(list, object)">
Related
So i have this JSP page which having data from table and forming a GET request to render more data on another page , by clicking one of the table line
Problem is i have to transforming it into POST method , to avoid getting information in the http request link
i know how to use post with form, but here i have to take the date from a table line and not a form
Any idea how to do that. i'm new to JSP so i don't know how to do it
<table border=0 bgcolor=#92ADC2 cellspacing=1 cellpadding=3 width=95% align=center>
<tr class=entete>
<td class=texte8 align=center> <spring:message code="nom"/></td>
<td class=texte8 align=center> <spring:message code="date_naissance"/></td>
<td class=texte8 align=center> <spring:message code="numero"/></td>
</tr>
<%
String v_Person = "";
String v_date = "";
String v_numero = "";
for (int i = 0; i < PersonListeBean.getPerson(); i++)
{
Gen_rechBean cb = PersonListeBean.getPerson(i);
v_Person = cb.getname();
v_date=cb.getdate();
v_numero=cb.getNumero();
}
%>
<tr class="<%=class_cell%>" onMouseOver="this.className='over';" onMouseOut="this.className='<%=class_cell%>';" onclick="javascript:parent['gauche'].document.location='ResultServlet?name=<%=v_Person%>&numero=<%=v_numero%>&date_naissance=<%=v_date%>">
<td class=texte7 align=left > <%=cb.getname()%></td>
<td class=texte7 align=left > <%=cb.getdate()%></td>
<td class=texte7 align=left > <%=cb.getNumero()%></td>
</tr>
</table>
<br>
<table width="95%" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right">
<a target="corps" href="rechResult.jsp" class="rub2" </a>
</td>
</tr>
</table>
I see what are you trying to do.
The easiest way to do that is using a form. So you can call a js method when you click the
<tr onclick="myMethod()">
that you want.
The method can fill your form and send the submit. Using this you can be redirected without sending data in you url.
A basic example could be:
(Supposing these are elements printed by server-side)
<tr onclick="myMethod(<%=getName()%>, <%=getDate()%>, <%=getNumero()%>)">
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<form id="myForm" action="targetFile.jsp" method="post">
//Hidden inputs to prevent users form touching this fields
<input type="hidden" name="name" id="data1">
<input type="hidden" name="date" id="data2">
<input type="hidden" name="numero" id="data3">
</form>
<script>
function myMethod(data1, data2, data3){
//Im gonna use jQuery. Is like javascript but quite faster to use
//Filling the form
$("#data1").val(data1);
$("#data2").val(data2);
$("#data3").val(data3);
//Submiting it
$("myForm").submit();
}
</script>
Let me know if it was helpful.
c:
when i search specific word only first page is classified. it shows pages and posts well on first page.
but when i go to page 2 or next page, seaching keyword doesn't apply on
is this address problem?
i guess this is sql or Paging.java problem because when i print log of page at BDAO it shows page well which i clicked.
also I don't know how can i transfer keyWord &keyField for that..!
I use oracle DB.
<%
String keyWord = (String)request.getParameter("keyWord");
String keyField = (String)request.getParameter("keyField");
%>
<script>
function searchCheck(frm){
//검색
if(frm.keyWord.value ==""){
alert("검색 단어를 입력하세요.");
frm.keyWord.focus();
return;
}
frm.submit();
}
function PageMove(page){
var keyWord = '<%=keyWord%>'
var keyField = '<%=keyField%>'
console.log(keyWord);
if(keyWord !=''){
location.href = "list.do?page="+page+"&keyWord=" + keyWord + "&keyField=" + keyField;
}
location.href = "list.do?page="+page;
}
</script>
</head>
<body>
<table width="800" cellpadding="0" cellspacing="0" border="1">
<tr>
<td>번호</td>
<td>이름</td>
<td>제목</td>
<td>날짜</td>
<td>히트</td>
</tr>
<c:forEach items="${list}" var="dto">
<tr>
<td>${dto.bId}</td>
<td>${dto.bName}</td>
<td>
<c:forEach begin="1" end="${dto.bIndent}">-</c:forEach>
${dto.bTitle}</td>
<td>${dto.bDate}</td>
<td>${dto.bHit}</td>
</tr>
</c:forEach>
<tr>
<td colspan="5">
<form action="list.do" method="post" name="search">
<select name="keyField">
<option value="bTitle">글 제목</option>
<option value="bContent">글 내용</option>
<option value="bName">작성자</option>
</select>
<input type="text" name="keyWord">
<input type="button" value="검색" onclick="searchCheck(form)">
</form>
</td>
</tr>
<tr>
<td colspan="5"> 글작성 </td>
</tr>
</table>
<div class="toolbar-bottom">
<div class="toolbar mt-lg">
<div class="sorter">
<ul class="pagination">
<li>맨앞으로</li>
<li>앞으로</li>
<c:forEach var="i" begin="${paging.startPageNo}" end="${paging.endPageNo}" step="1">
<c:choose>
<c:when test="${i eq paging.pageNo}">
<li class="active">${i}</li>
</c:when>
<c:otherwise>
<li>${i}</li>
</c:otherwise>
</c:choose>
</c:forEach>
<li>뒤로</li>
<li>맨뒤로</li>
</ul>
</div>
</div>
</div>
You never seem to be passing the keyword or keyfield when you call pageMove(). You might as well look up their values inside the function instead of having them as parameters:
function PageMove(page){
var keyWord = document.getElementById("keyWord").value;
var keyField = document.getElementById("keyField").value;
location.href = "list.do?page=" + page + "&keyWord=" + keyWord + "&keyField=" + keyField;
}
I have a list which holds data of LinkedHashMap type as:-
LinkedHashMap<Date,Double> map21 = new LinkedHashMap<Date,Double>();
List<LinkedHashMap<Date,Double>>l=new ArrayList<LinkedHashMap<Date,Double>>();
{
rs.absolute(43);
map20.put(rs.getDate(1),rs.getDouble(2));
l.add(map20);
rs.absolute(45);
map21.put(rs.getDate(1),rs.getDouble(2));
l.add(map21);
l.addAll(l);
}
return l
I display it in jsp as:
<table width = "300px" border = "1" cellspacing="2">
<tr>
<th>logtime</th>
<th>beam_current</th>
</tr>
<c:forEach var="row" items="${ref.reference()}">
<tr>
<c:forEach var="column" items="${row}">
<td>
${column}
</td>
</c:forEach>
</tr>
</c:forEach>
</table>
Now the output displayed after executing JSP page is a table with two columns but the values of both the columns are filled or displayed in first column namely logtime.How to show logtime value in first column and second column value in beam_current column.
The right way
iterate the Map is to get its key and value. Therefore iterate it as ,
<table width = "300px" border = "1" cellspacing="2">
<tr>
<th>logtime</th>
<th>beam_current</th>
</tr>
<c:forEach var="row" items="${ref.reference()}">
<tr>
<c:forEach var="column" items="${row}">
<td>
${column.key}
</td>
<td>
${column.value}
</td>
</c:forEach>
</tr>
</c:forEach>
</table>
will display the desired result in the tabular form
I have a JSP page where I am showing all the products that fall under a specific category. The problem is that all of them either end up showing either vertically or horizontally based on whether I loop my "td" or "tr". I want to show them in grid where 3 products are in row 1, another 3 in row 2 and so on. Any idea on how this can be achieved?
ProductController.java
List<Product> productsLst = MasterDao.getAllProductsByCategory(new Integer(categoryId));
products.jsp
<table>
<tr>
<%
for (Product p : productsLst) {
%>
<td align="center">
<img src="../images/<%= p.getImage()%>" class="product-grid-img"/>
<br/><div id="product-name"><%= p.getName()%></div>
<br/><div id="money">$ <%= p.getListPrice()%></div>
</td>
<%
}
%>
</tr>
</table>
Just use a counter, if you got 3 products close the tr and open a new tr
Using Guava's Lists.partition() method:
List<List<Product>> rows = Lists.partition(productList);
page.setAttribute("rows", rows);
...
<c:forEach var="row" items="rows">
<tr>
<c:forEach var="product" items="row">
<td> ... details of the product ... </td>
</c:forEach>
</tr>
</c:forEach>
Already answer in this thread
<table>
<s:iterator value="productList" status="status">
<s:if test="#status.index %4 == 0">
<tr>
</s:if>
<td>
<img src="../product/image?imageID=<s:property value="productID"/>&type=thumbnail" />
</td>
<s:if test="#status.index %4 == 0">
</tr>
</s:if>
</s:iterator>
<table>
I have a Java bean which stores what I am calling meta data (week start day, any holidays) that my JSP view will use to display a Calendar Month. I am using JSTL, not EL, since company only has jsp 1.2
<table align="center" border="1" cellpadding="3" cellspacing="0" width="100%" class="tableInternalBorder">
<tbody>
<tr>
<th width="180px" class="optionYellow">Sun</th>
<th width="180px">Mon</th>
<th width="180px">Tue</th>
<th width="180px">Wed</th>
<th width="180px">Thu</th>
<th width="180px">Fri</th>
<th width="180px" class="optionYellow">Sat</th>
</tr>
<c:forEach var="week" begin="1" end="${calendar.totalWeeks}" varStatus="status">
<tr>
<c:forEach var="cell" begin="${1+7*(week-1)}" end="${7+7*(week-1)}" step="1" varStatus="status"><c:set var="dayNo" value="${cell-calendar.weekStartDay+1}" />
<c:choose><c:when test="${calendar.weekStartDay>cell || (cell-calendar.weekStartDay+1)>calendar.totalDays}">
<td height="50" class="<c:out value="${calendar.cellColor[cell]}" />">* </td>
</c:when>
<c:otherwise>
<td valign="Top" height="75px" class="<c:out value="${calendar.cellColor[dayNo]}" />"><span class="calDayNo"><c:out value="${dayNo}" /></span><span class="calDayName"> <c:out value="${calendar.holidayName[dayNo]}" /></span><br>
<c:forEach var="dayEvent" items="${eventMap.byDay[dayNo]}" varStatus="status"><div class="eventContent" ><c:out value="${status.count}" />) <c:out value="${dayEvent.event_type_name}" />: <c:out value="${dayEvent.eventUser.lastName}" /></div></c:forEach></td>
</c:otherwise>
</c:choose>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
In this bean I also storing an array of month names so that I can do this in my view.
<c:forEach var="month" items="${calendar.monthList}" varStatus="status">
<option value="<c:out value="${status.index}" />" <c:if test="${month == calendar.monthName}">selected</c:if>><c:out value="${month}" /></option>
</c:forEach>
My question is do I set the month list in my javabean or the method which generates the meta data for the calendar. Here is the method that returns to meta data bean (with logic removed for clarity). Should I set it in this method, this class, or in the Java bean. If it should go in the Java bean, I am not sure how to do that.
public EBCalendar getCalendarMeta (HttpServletRequest request) {
//Get any request parameters
int iYear = STKStringUtils.nullIntconv(request.getParameter("iYear"));
int iMonth = STKStringUtils.nullIntconv(request.getParameter("iMonth"));
EBCalendar ebCal = new EBCalendar();
// Get the current month and year
Calendar ca = new GregorianCalendar();
int curYear = ca.get(Calendar.YEAR);
int curMonth = ca.get(Calendar.MONTH);
// If request parameters are null use todays calendar
if (iYear == 0) {
iYear = curYear;
iMonth = curMonth;
}
ebCal.setCurYear(curYear);
ebCal.setCurMonth(curMonth);
ebCal.setSelYear(iYear);
ebCal.setSelMonth(iMonth);
ebCal.setTotalWeeks(iTotalweeks);
ebCal.setTotalDays(totalDays);
ebCal.setWeekStartDay(weekStartDay);
ebCal.setAbvMonthName(abvMonthName);
ebCal.setMonthName(monthName);
ebCal.setMonthList(monthList);
ebCal.setHolidayName(getEBHolidayNameInMonth(iYear, iMonth));
ebCal.setCellColor(getWeekendHolidayColorMap(iYear, iMonth));
return ebCal;
}
EDIT: Here is what I did based on the accepted answer
I changed this:
<c:forEach var="month" items="${calendar.monthList}" varStatus="status">
<option value="<c:out value="${status.index}" />" <c:if test="${month == calendar.monthName}">selected</c:if>><c:out value="${month}" /></option>
</c:forEach>
to this:
<c:set var="months">January,February,March,April,May,June,July,August,September,October,November,December</c:set>
<c:forTokens var="month" items="${months}" delims="," varStatus="status">
<option value="<c:out value="${status.index}" />" <c:if test="${month == calendar.monthName}">selected</c:if>><c:out value="${month}" /></option>
</c:forTokens>
I think the question here is should you put the default with the view or the model. I am a bigger fan of putting the default with the model because you may have a different jsp that will have different defaults in the future. Then you have to go back and change the default in your model. I vote for in JSP. :)