struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <ja...@metastuff.com>
Subject Re: Patch: LinkTag for a single bean property
Date Fri, 01 Sep 2000 16:41:10 GMT
Whoops, ignore the extra stuff at the top of the example JSP, I cut n =
pasted by mistake. The example should have read:-

  <struts:iterate id=3D"bean" name=3D"collectionOfBeans">
  <tr>   =20
    <td align=3D"left"><struts:htmlProperty name=3D"bean" =
property=3D"id"/>    </td>
    <td align=3D"left"><struts:htmlProperty name=3D"bean" =
property=3D"name"/></td>
    <td align=3D"center">
      <struts:link href=3D"editBean.do?action=3DEdit" id=3D"bean_id" =
name=3D"bean" property=3D"id">
            <struts:message key=3D"edit.bean"/>
      </struts:link>
    </td>
  </struts>

Regards
James

James Strachan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
web: http://www.metastuff.com
mail: james@metastuff.com

  ----- Original Message -----=20
  From: James Strachan=20
  To: struts-dev@jakarta.apache.org=20
  Sent: 01 September 2000 17:35
  Subject: Patch: LinkTag for a single bean property


  I've just started using Struts and have just subscribed to this list =
so excuse me if this has been asked/answered before - I couldn't find a =
faq / archive of this list anywhere. (I'm trawling through the ezm lists =
which is a bit grim).

  I've attached a small patch to LinkTag.java which allows it to be used =
to construct a link when only one query argument is needed to be applied =
to a URL. I've found this to be particularly useful when using something =
like <struts:iterate>.=20

  For example consider the following JSP:-

  <%
    Collection teams =3D ..;
    pageContext =3D userModel.getUserTeams( username );
    if ( teams !=3D null && ! teams.isEmpty() ) {
      pageContext.setAttribute( "teams", teams );
  %>


    <struts:iterate id=3D"bean" name=3D"collectionOfBeans">
    <tr>   =20
      <td align=3D"left"><struts:htmlProperty name=3D"bean" =
property=3D"id"/>    </td>
      <td align=3D"left"><struts:htmlProperty name=3D"bean" =
property=3D"name"/></td>
      <td align=3D"center">
        <struts:link href=3D"editBean.do?action=3DEdit" id=3D"bean_id" =
name=3D"bean" property=3D"id">
              <struts:message key=3D"edit.bean"/>
        </struts:link>
      </td>

  It would generate the following hrefs in the table

      editBean.do?action=3DEdit&bean_id=3D1=20
      editBean.do?action=3DEdit&bean_id=3D2=20
      editBean.do?action=3DEdit&bean_id=3D3

  Note that the new 'id' tag attribute in the call of <struts:link> is =
optional to allow the property name to be redefined to the name of the =
query argument in cases where the property and URL parameter names =
differ.

  If there is a more elegant way of doing the above let me know - I must =
have missed it. Otherwise this makes the <struts:link> tag more flexible =
& reusable, as adding a single query argument is quite common.=20

  Regards
  James

  James Strachan
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  web: http://www.metastuff.com
  mail: james@metastuff.com


Mime
View raw message