This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Struts and the fly likes How to compare request attribute in Jsp in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "How to compare request attribute in Jsp in struts2" Watch "How to compare request attribute in Jsp in struts2" New topic
Author

How to compare request attribute in Jsp in struts2

gyanendra ojha
Greenhorn

Joined: May 16, 2007
Posts: 11
hi All,
i want a compare a request attribute (say "actionName") that has been set in a Action class in a jsp with struts2 tag ( i.e </s:if> ) in a Struts2 application.
but, my code is not working . please, check where i am wrong and suggest me right way to do it.

i have also visited Struts2 documentation but was in vain.

My Action :---->

public class AboutProject extends ActionSupport {

public String execute() throws Exception {

String actionName=getActionName();
HttpServletRequest request =
ServletActionContext.getRequest();
request.setAttribute("actionName", "edit");
return "SUCCESS";
}
}



My JSP :--->

<s:if test="%{actionName}=='edit'">
<tr> <td> action is Edit </td></tr>
</s:if>
<s:else>
<tr> <td> action is Not Edit </td></tr>
</s:else>
Ian Robinson
Greenhorn

Joined: Jul 16, 2008
Posts: 1
<s:if test="%{actionName}=='edit'">

will look in the root of the value stack - basically, you action.
To reference the request you will need something like

<s:if test="%{#request.actionName}=='edit'">

If memory serves me right!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to compare request attribute in Jsp in struts2
 
Similar Threads
Problem of resubmisson in struts2
[Struts2] losing display only(prepopulated) values of the form if the validaiton fails
Struts2: Compare request parameter not working
Struts2 test condition in s:if not working
Struts2 variable inside javascript