aspose file tools*
The moose likes Struts and the fly likes Problem in using property of a bean  in composing a html link Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem in using property of a bean  in composing a html link" Watch "Problem in using property of a bean  in composing a html link" New topic
Author

Problem in using property of a bean in composing a html link

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
I have a bad problem here .
I want to use a property from a bean which i am iteratiting over a collection of that bean.
i want to use that property as a Parameter for a link.
imageine somethin like this :


where :
prod is my iterator item , nid is the property I need to pass as prodID to ShowGallery Action
can you pleas help me about this ?

I tried many ways but none of them works
i tried to use ' instead of " , and any other ways . it seems it need a trick
how i can use Scriptlet to do this ? can some one help me ?


thank you
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

You can't embed a custom tag as the attribute of another custom tag.

This would probably be fairly straight-forward using JSTL tags, but as these are Struts tags that you are using, I'm going to shift this over the the Struts forum where someone more familiar with those tags might be able to help you out.
[ August 02, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd recommend that you use the struts-el version of the html tags, and then this will be much easier.

put the following taglib definition in your jsp in place of the one you currently have:

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el" prefix="html" %>

Make sure struts-el.jar is in WEB-INF/lib

Once you have done this, you can embed an EL expression in your html:link tag, something like this:

<html:link href='showGallery.do?prodID=${prod.nid}'</html:link>


Merrill
Consultant, Sima Solutions
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
The html:link tag does have support for this.
If you have one parameter, you can use the param* attributes: paramId, paramName, paramProperty, paramScope
Your equivalent code:


If you have more than one parameter you can use the "name" attribute to specify a Map of parameter name/value pairs to be appended to the link.

Reference html:link tag

Cheers,
evnafets
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
thank you very much for answering my first question
I solve it by using

when i tried to use struts el it said that href can not accept expressions.
is it true or i did something wrong ?


Now i have another problem : I showld show an image by using same method , i mean like this :

what this tag mean ? as i write it probably very poor : it means
I want to load an image , its source is a JPG file located in prodPics directory in my webContent
image name is same as nid of my bean (which im iterating over a collection of that bean.)

Now how should i use Tags , scriptlet or any other tricks to load my image file ?


Thank you.
Thomas V�lk
Greenhorn

Joined: Jul 26, 2005
Posts: 7
Marc Peabody gave me a very valueable hint here.

Just use plain HTML instead of the Struts-Tags. In your case it should work if you use the <img>-tag instead of the <html:img>-tag
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
hi
thank you very much thomas
it works .
Thanks
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
>when i tried to use struts el it said that href can not accept expressions.
>is it true or i did something wrong ?
It is correct that the struts-el tags do not accept expressions.
Struts-el is only intended for use in a JSP1.2 container (eg Tomcat 4)

In a JSP2.0 container (eg Tomcat 5) EL is understood by default, and ${expr} is a runtime expression
As long as you declare your web.xml file as being version 2.4, you can use EL expressions in your page with the struts tags.

Which could have done like this:
<html:img src="prodPics/${prod.nid"}.jpg"/>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in using property of a bean in composing a html link