You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Tarek M. Nabil" <Ta...@itworx.com> on 2003/03/12 20:26:32 UTC

ties the model to the view

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
Tarek.Nabil@itworx.com
Free Zone, Area 7 (B),
Block (J), Nasr City,
Cairo, Egypt
TEL.: 20-2-2766226
http://www.itworx.com
 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: ties the model to the view

Posted by Sloan Seaman <sl...@sgi.net>.
Take a look at <html-el:link>
as it may provide exactly what you are looking for..

Example:
<logic:iterate id="element" name="listSubcategoryForm"
property="visibleCategories" type="<cannot reveal package
name>.SubcategoryModel">
<tr><td>
<html-el:link name="element" property="params"
page="/editSubcategory.do?${visibleCategories}"><html:img border="0"
srcKey="img.edit"/></html-el:link>
</td>
</tr>
</logic:iterate>
----- Original Message -----
From: "Tarek M. Nabil" <Ta...@itworx.com>
To: "Struts (E-mail)" <st...@jakarta.apache.org>
Sent: Wednesday, March 12, 2003 2:26 PM
Subject: <html:link> ties the model to the view


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
Tarek.Nabil@itworx.com
Free Zone, Area 7 (B),
Block (J), Nasr City,
Cairo, Egypt
TEL.: 20-2-2766226
http://www.itworx.com


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org