The best way is to use <c:url> from the JSTL. Alternatively, your model class doesn't need to know about the request parameter names if you use an adaptor/wrapper around it.

David



From: "Tarek M. Nabil" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: "Struts (E-mail)" <[EMAIL PROTECTED]>
Subject: <html:link> ties the model to the view
Date: Wed, 12 Mar 2003 21:26:32 +0200

Hi everyone,

I've been using Struts for a while, and I think it's the best thing since servlets.

Today, though, I ran into a problem that when I tried to implement with Struts, I found the solution to be rather dissappointing. Or maybe it's just me, and I couldn't figure out the best way to do it.

I have a JSP that lists a number of elements, and beside each element, there's a link to another page where the user can edit this element.

I use a model class to retrieve a Vector of instances from the class that encapsulates that element.

I use the <logic:iterate> tag to iterate over this Vector and show the elements. When I tried to implement the link that will point to the page where the element can be edited, I found out that the <html:link> tag has a strange way of getting the parameters to be appened to the link. If you want to send more than one parameter then you need to provide a Map of the parameter names and values.

Since I'm iterating over a collection, the only way to do that is to provide this Map from the instances in this collection for every element. But that would mean that my model (Class whose instance is in the Vector) has to know the names of the request parameters I'm sending. Isn't that some sort of coupling between the model and the web tier? Or am I missing something here?

I'll provide the code here to help explain my point...I've only included the element in question.

<logic:iterate id="element" name="listSubcategoryForm" property="visibleCategories" type="<cannot reveal package name>.SubcategoryModel">
<tr><td><html:link name="element" property="params"
page="/editSubcategory.do"><html:img border="0"
srcKey="img.edit"/></html:link></td>
</tr>
</logic:iterate>


So, I need SubcategoryModel to implement a method called getParams() to return a java.util.Map that contains the request parameters and their values. That would essentially mean that SubcategoryModel knows the name of the request parameters, which is not that good.

I don't have another way to do it. Can anyone help?

Thanks in advance.

Tarek M. Nabil
Software Engineer
ITWorx
[EMAIL PROTECTED]
Free Zone, Area 7 (B),
Block (J), Nasr City,
Cairo, Egypt
TEL.: 20-2-2766226
http://www.itworx.com


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to