aspose file tools*
The moose likes Struts and the fly likes struts-jstl-struts 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 "struts-jstl-struts" Watch "struts-jstl-struts" New topic
Author

struts-jstl-struts

Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hello
Is/how it possible to write a struts bean member value into a struts html tag?
I have tried all types of syntax from jstl to get the value and can get the value of other session/page scope elements. I am using TC5.0.28, Struts1.2 & JSTL1.1.1. Can someone help with the proper syntax/framework? tia
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you use the struts-el version of the tags, you can substitue EL expressions in tag attributes. Look in the "contrib" folder of the downloaded materials. Note that you should use EL expressions only without cut tags.


Merrill
Consultant, Sima Solutions
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hi Merrill
Is the EL a set of jars and tag/tld files? What is the syntax? I am really just trying to get out the members of the <bean age name="context" value=".."/> and <bean efine name="myBean" toScope="page">stuff</bean efine> Do I really need EL for that? tia.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Your last post left me totally confused as to what you are trying to accomplish. Can you please explain in as much detail as possible what it is you are trying to do with an example or two?

To answer your question, to use Struts-el, you just include the struts-el.jar file in your WEB-INF/lib folder. The tags are all the same as regular struts tags with the same syntax with the only difference being they will accept an EL expression as an attribute. Example:

The TLDs are in the jar file. Just reference them by their namespace. Example:

[ July 10, 2008: Message edited by: Merrill Higginson ]
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hi Merrill
Sorry. I simply did a
<bean age id="context" property="request"/>
and I want to get the serverPort into a struts html tag. So I tried
<html:text property="port" value="${context.serverPort}"/> Now I am able to get the value with <bean:write name="context" property="serverPort"/> But I unable to get it into the tag. I have even tried
<html:text property="port" value="<c ut value='pageContext.context.serverPort'/>"/>Where/what is the syntax wrong? tia
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This won't work because you can't use one custom tag as an attribute of another. However, as I metioned, you can use an EL expression if you use the Struts-el tags.

If you want to set a value for an html:text tag it's best not to use the value attribute at all, but just set the corresponding ActionForm bean property to the desired value.
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hi Merrill
I thought the entire idea about jstl was to use it as a preprocessor and to permit the output of the tag to be dynamically computed and serve as the static input value for a struts tag which then get computed and then javascript. Where is that wrong, I would like to clearly understand this.

How can I set the ActionForm bean value without access to an expression that will pull out the serverPort? Is the only way to populate the value with struts-el? Also where can I dn the struts-el jars? Sorry for all the questions, still just a newbie.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Chris Pat:

I thought the entire idea about jstl was to use it as a preprocessor and to permit the output of the tag to be dynamically computed and serve as the static input value for a struts tag which then get computed and then javascript. Where is that wrong, I would like to clearly understand this.

All I can tell you is that your statement above is in fact wrong. You can use a JSTL tag as an attribute of a plain HTML tag because plain HTML tags require no preprocessing (The goal of a JSP is to produce plain HTML). However, both JSTL tags and Struts tags are custom tags and both do require preprocessing to produce plain HTML. It's a hard and fast rule that one custom tag cannot be substituted as the attribute of another custom tag.
Originally posted by Chris Pat:

How can I set the ActionForm bean value without access to an expression that will pull out the serverPort?

The best place to set the bean value is in an Action class that forwards to this JSP. If you set the value in the JSP and then have to redisplay the JSP because of a validation error, it will revert to the value you set rather than the value the user entered. However, if you insist on setting it in the JSP, you can do it like this:


Originally posted by Chris Pat:
Is the only way to populate the value with struts-el?

If your web application were a Servlet version 2.4 application you could use JSTL expressions anywhere in the JSP including in attributes of Struts tags, However, since you're using Tomcat 5.0, it doesn't support Servlet 2.4. In a Servlet 2.3 application, your only options are to use a scriptlet (e.g <%= somevalue%>) or to use the Struts-el tags.
Originally posted by Chris Pat:
Also where can I dn the struts-el jars?
There's only one struts-el jar file and you've already downloaded it when you downloaded Struts. Look in the "contrib" folder of the downloaded materials.
[ July 11, 2008: Message edited by: Merrill Higginson ]
Chris Pat
Ranch Hand

Joined: Aug 27, 2005
Posts: 156
Hi Merrill
Thank for your completeness and education.
 
 
subject: struts-jstl-struts