*
The moose likes Struts and the fly likes howto pass parameter to struts tag ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "howto pass parameter to struts tag ?" Watch "howto pass parameter to struts tag ?" New topic
Author

howto pass parameter to struts tag ?

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 439
hi good day,

i having a problem which due to passing parameter to struts tag <html:image>

the parameters(calMonth&dateFormat) is need to call the calendar and are dynamic, and i use to pass it by defined it in scriptlet in <head>





the problem is calMonth and dateFormat is not detect in struts link tag, howto i solve this problem ?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You can use scriptlets with Struts tags, but the rule is "all or nothing", meaning that the entire contents of the attribute must be a scriptlet, or none of it must be a scriptlet. So, something like the following would work:

<html:link href='<%="javascript:show_calendar('document.forms[0].pre_fitdate','"+calMonth+"', '', '"+dateFormat+"');" %>'><html:img page="/pages/images/cal.gif" width="16" height="16" border="0" /> </html:link>

Note that no such restriction applies to the Struts-el version of the taglib. It allows you to sprikle in EL expressions with literals.


Merrill
Consultant, Sima Solutions
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 439
thank you for guidance, Merrill Higginson , i will try it later, what if if i use struts-el? how it should be ? in fact, i confuse what is struts-el ?
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 439
hi Merrill Higginson, i have try it , ans it work , thank you

but somehow, i need to add more script into it

original :


new addon script


test1 is from scriptlet , where it initialise as follow


note : onMouseeover and onMouseeOut word have been modified in order to allow save in this thread

in source ,



when i run it, it doesn't show the img anymore



[ October 28, 2006: Message edited by: Nakata kokuyo ]

[ October 28, 2006: Message edited by: Nakata kokuyo ]
[ October 28, 2006: Message edited by: Nakata kokuyo ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I think you've misunderstood what I was trying to get across with the "all or nothing" comment. What I mean is that in a single attribute it's either all a scriptlet or not a scriptlet. onmouseover and onmouseout are each separate attributes of the tag, so they can each have their own scriplets. Since they don't appear to have variable information in them, just code them as part of the tag. Example:

<html:link href='<%="javascript:show_calendar('document.forms[0].pre_fitdate','"+calMonth+"', '', '"+dateFormat+"');" %>' oonMouseeOver="window.status='Date Picker';return true;" oonMouseeOut="window.status='';return true;" ><html:img page="/pages/images/cal.gif" width="16" height="16" border="0" /> </html:link>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Nakata kokuyo:
what if if i use struts-el? how it should be ? in fact, i confuse what is struts-el ?

When the Java Standard Tag Library (JSTL) was introduced a few years ago, it also introduced an Expression Language (EL) which was a way of referring to JavaBeans and their properties on a JSP page, along with some simple string and numeric expressions.

Struts has a separate tag library called html-el that has all the same tags as the <html:xxx> tags. The only difference being that these tags will allow EL expressions to be used in attributes of the tags instead of scriptlets.

To use these tags, the struts-el.jar file must be in the WEB-INF/lib directory, and you must have the following taglib definition:

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

Joined: Apr 13, 2005
Posts: 439
thank you Merrill Higginson again, you are simply too good

how to become struts expert like you , do you mind to share your secret recipe to become struts guru
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Thanks Nakata,

I'm no "Guru". I've just worked with Struts for quite a while -- nearly since it was first released. One thing I've found that has increased my knowledge is answering others' questions, especially when I have to do a little research before answering. I'd suggest you join in this forum and others on JavaRanch. See if there are questions you can answer, or might be able to answer with a little research. You'll be amazed at how fast your knowledge of the subject grows.
 
GeeCON Prague 2014
 
subject: howto pass parameter to struts tag ?