• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

dynamic anchor value inside html:link

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never used anchors inside of the html:link (or nested:link) tags before, but am trying to do so now. Any ideas how I can specify an anchor from a bean value, as opposed to typing a string value into the tag?
Right now it looks like I'm going to have to test for one of three values inside that bean, then provide three alternate html:link tags depending on that value.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeagh, I struggled with this for a while...
I eventually came up with this, but dont know if it is the best way or not. I basically put the dynamic paramter in a bean and then use a scriptlet

<html:link paramId="expand_table" paramName="table" anchor="<%= (String) session.getAttribute("tab") %>" forward="getmetadata">
[Expand]
</html:link>

The full JSP is below
HTH
Tim
[CODE SAMPLE]
An outerloop specifies elements with anchors and an innerloop and tags locations. the scriptlet is to test your session variables.
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"; %>
<%@ taglib uri="/tags/tiles-defs" prefix="tiles" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.util.*" %>

Database Name : <c ut value="${dbmetaview.dbMeta.dbAtomicName}"/><br>
<table border cellpadding="1" cellspacing="1" >
<font color="red">
<c:forEach var="table" items="${dbmetaview.tables}" varStatus="table_status">
<tr>
<%-- Start: Outer Rows --%>
<th width="20%" align="left" valign="top">

<c ut value="${table_status.count}"/>

<c:set var="count" value="${table_status.count}" scope="session"/>
<c:set var="tab" value="${dbmetaview.tables[count]}" scope="session"/>

<%
System.out.println("Scriptlet");
HttpSession localSession = request.getSession();

Enumeration enum = localSession.getAttributeNames();
System.out.println("Session Paramters");
while (enum.hasMoreElements()) {
String pName = (String) enum.nextElement();
System.out.println("PropertyName JSP-> " + pName);
System.out.println("Value JSP-> " + localSession.getAttribute(pName));
}
%>


<html:link linkName="<%= (String) session.getAttribute("tab") %>" >
<c ut value="${table}"/><br>
</html:link>


<html:link paramId="expand_table" paramName="table" anchor="<%= (String) session.getAttribute("tab") %>" forward="getmetadata">
[Expand]
</html:link>

<html:link paramId="collapse_table" paramName="table" anchor="<%= (String) session.getAttribute("tab") %>" forward="getmetadata">
[Collapse]
</html:link>


<c:if test="${dbmetaview. == }">


</td></th>


<c:if test="${dbmetaview.displayAttrib[table_status.index] == true}">
<td>
<table border cellpadding="1" cellspacing="1" >
<%-- Start: Inner Rows --%>
<tr>
<c:set var="attribVector" value="${dbmetaview.attribMetaData[table_status.index]}"/>
<c:forEach var="attrib" items="${attribVector}">
<tr>
<td><c ut value="${attrib.attributeName}"/></td>
<td><c ut value="${attrib.typeString}"/></td>
<td><c ut value="${attrib.sizeString}"/></td>
<td>
DEANO
</td>
</tr>
</c:forEach>
</tr>
<%-- End: Inner Rows --%>
</table>
</td>
</c:if>

</tr>
<%-- End: Outer Rows --%>
</c:forEach>
</font>
</table>
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many of the struts tags were ported to JSTL in the Struts-EL tag library. That will allow you to use the JSTL expression language in the tag. I believe all of the html tags were ported, so you should be able to do something like <html:link . . . anchor="${tab}"> to dynamically set the anchor. I haven't tried it yet, so I can't verify that it works. You have to use the html-el taglib instead of the html taglib to do this.
 
Paul Woods
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for both of your replies. I have it working, though w/o the JSTL for now.
 
I don't always make ads but when I do they're tiny
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic