Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed with struts2

 
Rao Papa
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have this piece of code in my jsp file
<s:hidden name="lastIndex" value="'<%=j%>'" />

but I get an exception related to tld not supporting an expression.
I would like to know if anyone has faced a similar issue. I would like to know the equivalent of the <%=variableName%> in struts 2.

Thanks
Papa Rao
 
Quince bise
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
try to use jsp expression language for this.

Basic Syntax is: ${variablename} <-- means to search the PageContext, HttpServletRequest, HttpSession and ServletContext and output the object with that attribute name.

equivalent form: pageContext.findAttribute("variablename") or
<jsp:useBean id="variablename" class="sompackage" scope="session,request,application">
<%=variablename%>

I hope it could help you.
 
Rao Papa
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thank you for responding back i tried using $ but i still face this error

I tried this ::
<s:url id="next" action="Next">
<s aram name="lastIndex" value="%{${pageIndex}}"/>
</s:url>

using it still gives me this error which is the same as what i got when i used <%= =%>

According to TLD or attribute directive in tag file, attribute value does not accept any expressions
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
 
Quince bise
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi! please do it this way: remove "%" and the other "{}"

value="${pageIndex}"

and make sure that pageIndex is stored as pageContext or request or session.

example:
<% request.setAttribute("pageIndex", urvalue)%> or from your action class
 
Rao Papa
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thank you for responding back i tried using $ but i still face this error

I tried this ::
<s:url id="next" action="Next">
<s aram name="lastIndex" value="%{${pageIndex}}"/>
</s:url>

using it still gives me this error which is the same as what i got when i used <%= =%>

According to TLD or attribute directive in tag file, attribute value does not accept any expressions
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
 
Rao Papa
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Quincy,

Thanks for the reply. I tried it but i still get the same exception. Any other ideas on how I can tackle this issue..

Regards,
Papa Rao
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Struts <s:hidden> tag is tied to the value referenced by the name attribute. If you want to put some value into the tag, change the value of the property referenced by the name. Example: Suppose I have the following tag

If I want the value of this tag to be "someValue", I must manipulate the value of the foo property, either in the action class that forwards to the JSP as in:

or, in the JSP itself as in:

[ April 01, 2008: Message edited by: Merrill Higginson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic