You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joanne L Corless <jc...@csc.com> on 2003/10/14 14:37:58 UTC
[REPOST] Best Practice Question - html links
I know this may seem a little rude but no-one picked up on my question and
I really could use some help with this
Regards
Joanne Corless
----- Forwarded by Joanne L Corless/UK/CSC on 14/10/03 13:36 -----
Joanne L Corless
/UK/CSC To: struts-user@jakarta.apache.org
cc:
13/10/03 17:12 Subject: Best Practice Question re: html links
Hi,
I am implementing a struts application with menu lists which need to be
dynamic based on a user role hierarchy, i.e not a simple user role = menu
list. Therefore I cannot set up menu lists in the tile definitions file as
they are
I hold the menu list in a database which I am accessing via an EJB and
returning to the session using a vector of DAO object 's which contain the
basic information about each menu item, i.e name, link,type (we have
different types of links some open a pop-up window, others run an inline
java applet)
Currently I am using standard Java scriptlets to access the vector and
print it out in the JSP tile page example below:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/struts/tiles" prefix="tiles" %>
<%@ taglib uri="/struts/logic" prefix="logic" %>
<%@ taglib uri="/struts/bean" prefix="bean" %>
<%@ taglib uri="/struts/html" prefix="html" %>
<%@ page import="com.csc.ebilling.ejb.common.MenuItemDAO" %>
<%
String commonImagePath= request.getContextPath()
+"/presentation/DEFAULT/images";
String currentPageName = (String)session.getAttribute
("currentPageName");
java.util.Vector topMenu = (java.util.Vector) session.getAttribute
("topMenu");
%>
<table>
<tr>
<%
for (int i=0;i<topMenu.size();i++){
// pageContext.setAttribute("topMenuItem", topMenuItem,
PageContext.PAGE_SCOPE);
MenuItemDAO topMenuItem = (MenuItemDAO) topMenu.get(i);
if (topMenuItem.getMenuItemName().equals(currentPageName))
{
%>
<td valign="bottom" align="right" class="tabselected">
<img src="<%=commonImagePath%>/page_name_left_selected.gif"
border="0">
</td>
<td valign="bottom" background="
<%=commonImagePath%>/page_name_mid_selected.gif" align="center" class
="tabselected" nowrap style="background-repeat: repeat-x;">
<span class="tabselected"><%=topMenuItem.getMenuItemName()%></span>
</td>
<td valign="bottom" align="left" class="tabselected">
<img src="<%=commonImagePath%>/page_name_right_selected.gif" border
="0">
</td>
<%
}
else
{
%>
<td valign="bottom" align="right" class="tabunselected">
<a href="<%=request.getContextPath()%>/changePage.do?pageName
=<%=topMenuItem.getMenuItemName()%>">
<img src="<%=commonImagePath%>/page_name_left_unselected.gif"
border="0">
</a>
</td>
<td valign="bottom" background="
<%=commonImagePath%>/page_name_mid_unselected.gif" align="center" class
="tabunselected" nowrap style="background-repeat: repeat-x;">
<a href="<%=request.getContextPath()%>/changePage.do?pageName
=<%=topMenuItem.getMenuItemName()%>">
<span class="tabunselected"><%=topMenuItem.getMenuItemName
()%></span>
</a>
</td>
<td valign="bottom" align="left" class="tabunselected">
<a href="<%=request.getContextPath()%>/changePage.do?pageName
=<%=topMenuItem.getMenuItemName()%>">
<img src="<%=commonImagePath%>/page_name_right_unselected.gif"
border="0">
</a>
</td>
<%
}
}
%>
</tr>
</table>
I realise that this is not best practice and I should be using the tag-libs
but I'm struggling to make the tag-libs work, I'm also confused about
whether this tile needs to be inside a form as I am not actually submitting
anything (as in a Login page), however I do need to pass a pageName
parameter into the request.
The above example does work (sort of) however I am unable to extract the
pageName parameter in my action class as it keeps returning null
I would really appreciate some pointers as I thought I had struts figured
but I now realise I've gone wrong somewhere along the line
Regards
Joanne Corless
CSC Computer Sciences Limited
( Office +44 (0)1772 318025
( Mobile +44 (0)7767 656588
* email jcorless@csc.com
Based at: CSC, Alliance House, Library Road, Chorley, Lancs, PR6 7EN
CSC Computer Sciences Limited: Registered in England, No. 963578.
Registered office: Royal Pavilion, Wellesley Road, Aldershot, Hampshire,
GU11 1PZ.
----------------------------------------------------------------------------------------
This is a PRIVATE message. If you are not the intended recipient, please
delete without copying and kindly advise us by e-mail of the mistake in
delivery. NOTE: Regardless of content, this e-mail shall not operate to
bind CSC to any order or other contract unless pursuant to explicit written
agreement or government initiative expressly permitting the use of e-mail
for such purpose.
----------------------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: [REPOST] Best Practice Question - html links
Posted by Kris Schneider <kr...@dotech.com>.
If you're using a JSP 1.2 container, JSTL can help out a bit. It doesn't look
like you need an HTML form for any of this, you're constructing a bunch of links
that will issue GETs to the action mapped to "/changePage". As long as that
mapping uses a (Struts) form with a property called "pageName", it should work.
struts-config:
<form-bean name="changePageForm" type="org.apache.struts.action.DynaActionForm">
<form-property name="pageName" type="java.lang.String"/>
</form-bean>
<action path="/changePage"
type="com.csc.ebilling.actions.ChangePageAction"
name="changePageForm"
scope="request"
validate="false"/>
JSP:
<%@ page pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="html" uri="http://jakarta.apache.org/struts/tags-html" %>
<c:set var="commonImagePath"
value="${pageContext.request.contextPath}/presentation/DEFAULT/images"/>
<c:set var="currentPageName" value="${sessionScope.currentPageName}"/>
<c:set var="topMenu" value="${sessionScope.topMenu}"/>
<table>
<tr>
<c:forEach var="topMenuItem" items="${topMenu}">
<c:choose>
<c:when test="${topMenuItem.menuItemName eq currentPageName}">
<td valign="bottom" align="right" class="tabselected">
<img src="<c:out value="${commonImagePath}/page_name_left_selected.gif"/>"
border="0">
</td>
...
</c:when>
<c:otherwise>
<td valign="bottom" align="right" class="tabunselected">
<html:link action="/changePage"
paramId="pageName"
paramName="topMenuItem"
paramProperty="menuItemName">
<img src="<c:out
value="${commonImagePath}/page_name_left_unselected.gif"/>"
border="0">
</html:link>
</td>
...
</c:otherwise>
<c:choose>
</c:forEach>
</tr>
</table>
Quoting Joanne L Corless <jc...@csc.com>:
> I know this may seem a little rude but no-one picked up on my question and
> I really could use some help with this
>
> Regards
> Joanne Corless
>
> ----- Forwarded by Joanne L Corless/UK/CSC on 14/10/03 13:36 -----
>
>
> Joanne L Corless
>
> /UK/CSC To:
> struts-user@jakarta.apache.org
>
> cc:
>
> 13/10/03 17:12 Subject: Best Practice
> Question re: html links
>
>
>
>
>
>
>
> Hi,
>
> I am implementing a struts application with menu lists which need to be
> dynamic based on a user role hierarchy, i.e not a simple user role = menu
> list. Therefore I cannot set up menu lists in the tile definitions file as
> they are
>
> I hold the menu list in a database which I am accessing via an EJB and
> returning to the session using a vector of DAO object 's which contain the
> basic information about each menu item, i.e name, link,type (we have
> different types of links some open a pop-up window, others run an inline
> java applet)
>
> Currently I am using standard Java scriptlets to access the vector and
> print it out in the JSP tile page example below:
>
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <%@ taglib uri="/struts/tiles" prefix="tiles" %>
> <%@ taglib uri="/struts/logic" prefix="logic" %>
> <%@ taglib uri="/struts/bean" prefix="bean" %>
> <%@ taglib uri="/struts/html" prefix="html" %>
> <%@ page import="com.csc.ebilling.ejb.common.MenuItemDAO" %>
> <%
> String commonImagePath= request.getContextPath()
> +"/presentation/DEFAULT/images";
> String currentPageName = (String)session.getAttribute
> ("currentPageName");
> java.util.Vector topMenu = (java.util.Vector) session.getAttribute
> ("topMenu");
> %>
>
> <table>
> <tr>
>
> <%
> for (int i=0;i<topMenu.size();i++){
> // pageContext.setAttribute("topMenuItem", topMenuItem,
> PageContext.PAGE_SCOPE);
> MenuItemDAO topMenuItem = (MenuItemDAO) topMenu.get(i);
> if (topMenuItem.getMenuItemName().equals(currentPageName))
> {
> %>
> <td valign="bottom" align="right" class="tabselected">
> <img src="<%=commonImagePath%>/page_name_left_selected.gif"
> border="0">
> </td>
> <td valign="bottom" background="
> <%=commonImagePath%>/page_name_mid_selected.gif" align="center" class
> ="tabselected" nowrap style="background-repeat: repeat-x;">
> <span class="tabselected"><%=topMenuItem.getMenuItemName()%></span>
> </td>
> <td valign="bottom" align="left" class="tabselected">
> <img src="<%=commonImagePath%>/page_name_right_selected.gif" border
> ="0">
> </td>
> <%
> }
> else
> {
> %>
> <td valign="bottom" align="right" class="tabunselected">
> <a href="<%=request.getContextPath()%>/changePage.do?pageName
> =<%=topMenuItem.getMenuItemName()%>">
> <img src="<%=commonImagePath%>/page_name_left_unselected.gif"
> border="0">
> </a>
> </td>
> <td valign="bottom" background="
> <%=commonImagePath%>/page_name_mid_unselected.gif" align="center" class
> ="tabunselected" nowrap style="background-repeat: repeat-x;">
> <a href="<%=request.getContextPath()%>/changePage.do?pageName
> =<%=topMenuItem.getMenuItemName()%>">
> <span class="tabunselected"><%=topMenuItem.getMenuItemName
> ()%></span>
> </a>
> </td>
> <td valign="bottom" align="left" class="tabunselected">
> <a href="<%=request.getContextPath()%>/changePage.do?pageName
> =<%=topMenuItem.getMenuItemName()%>">
> <img src="<%=commonImagePath%>/page_name_right_unselected.gif"
> border="0">
> </a>
> </td>
>
> <%
> }
> }
> %>
>
> </tr>
> </table>
>
>
> I realise that this is not best practice and I should be using the tag-libs
> but I'm struggling to make the tag-libs work, I'm also confused about
> whether this tile needs to be inside a form as I am not actually submitting
> anything (as in a Login page), however I do need to pass a pageName
> parameter into the request.
>
> The above example does work (sort of) however I am unable to extract the
> pageName parameter in my action class as it keeps returning null
>
> I would really appreciate some pointers as I thought I had struts figured
> but I now realise I've gone wrong somewhere along the line
>
> Regards
>
> Joanne Corless
>
> CSC Computer Sciences Limited
> ( Office +44 (0)1772 318025
> ( Mobile +44 (0)7767 656588
> * email jcorless@csc.com
>
>
> Based at: CSC, Alliance House, Library Road, Chorley, Lancs, PR6 7EN
> CSC Computer Sciences Limited: Registered in England, No. 963578.
> Registered office: Royal Pavilion, Wellesley Road, Aldershot, Hampshire,
> GU11 1PZ.
--
Kris Schneider <ma...@dotech.com>
D.O.Tech <http://www.dotech.com/>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org