Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How do I access the variable of iterator in struts2

 
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a requirement where I am migrating struts 1 to struts2

Now in the JSP that is already written in struts1, there are scriptlets being used which are accessing the variable defined in <logic:iterator as follows >




I have minimized the code above to the least, so that it is easy to explain the requirement. Though the scriptlet has much bigger code inside it (in actual)

Now the requirement here is to migrate it to struts 2

In struts 2, I do it something as follows



Here I am not able to access the task variable inside scriptlet as I was able to access in struts1.

It is giving compilation error.

I cannot use the struts 2 tags, because such kind of scriptlets are many in the JSP, and I want to go with the least changes so that I dont need to change the complete JSP (whcih ofcourse is error-prone)
 
Bartender
Posts: 9623
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "var" attribute is the name of the iterator on the Value Stack (see here).  The tag is not creating a variable with that name.
 
Yogesh Gandhi
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote:The "var" attribute is the name of the iterator on the Value Stack (see here).  The tag is not creating a variable with that name.



Thanks for your response. But I need that as a variable as well (as it was being used in struts1). So that I can go ahead with minimal changes in the JSP.

Are you saying that its not possible?
 
Joe Ess
Bartender
Posts: 9623
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm saying the variable will be in the Value Stack.  It's an integral part of Struts 2.  see here
My personal opinion is that scriptlets are awful and one should avoid them at all costs.  It would also be wise to sit down and learn how to use Struts 2 effectively.  By taking the half-and-half route, you are missing out on the benefits of using Struts 2 while also causing more problems for yourself by trying to write code to get around the framework.
 
Yogesh Gandhi
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Joe Ess wrote:I'm saying the variable will be in the Value Stack.  It's an integral part of Struts 2.  see here
My personal opinion is that scriptlets are awful and one should avoid them at all costs.  It would also be wise to sit down and learn how to use Struts 2 effectively.  By taking the half-and-half route, you are missing out on the benefits of using Struts 2 while also causing more problems for yourself by trying to write code to get around the framework.



I understand what you are saying, but the problem I have in hand is, that code is an already running application, which has tons of JSPs and it is already using scriptlets and variables as shown in my first post.

Now I do not want to mess up the things any further. At present the job I have in hand is, to make it compatible with Struts2.
 
Yogesh Gandhi
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found out a work around to access the variable in the scriptlet. Though not as elegant way of doing it, but still it solves the problem



In this above example, the reqirement was to access the abc variable in the scriptlet


And then get that from request.getAttribute("abc")




 
You get good luck from rubbing the belly of a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic