• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

struts-jstl-struts

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 c:out tags.
 
Chris Pat
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill
Thank for your completeness and education.
 
reply
    Bookmark Topic Watch Topic
  • New Topic