This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Learn Java with Math: Using Fun Projects and Games and have Ron Dai on-line!
See this thread for details.
Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

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.
 
Are we home yet? Wait, did we forget the tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!