This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes get action property Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "get action property" Watch "get action property" New topic
Author

get action property

misha nesterenko
Greenhorn

Joined: Feb 05, 2011
Posts: 28
Hello

I have login.jsp


checkLogin action is mapped to CheckLoginAction.java


how can I get isLoggedIn property in <s:property...> after executing action checkLogin in login.jsp?
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
have you tried:

<s:property value="isLoggedIn"/>

This works for me, however, instead of a getter method I would use a method named isIsLoggedIn (might want to change the variable name if you do that though). I would think the getter method would work but maybe struts2 can't convert the boolean to a string if you do that. If that doesn't work, can you indicate what is going wrong with it?
misha nesterenko
Greenhorn

Joined: Feb 05, 2011
Posts: 28
I have added getter method isIsLoggedIn, so CheckLoginAction.java now looks like:


and I get the property like:
<s:property value="isLoggedIn"/>

It shows just nothing
excerpt from top of login.jsp:


and how it is rendered to html:
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Ok, I played around with this a little. I think the problem is you are using Boolean, and I am using boolean. I guess the s:property can't handle that wrapper class around the boolean (although I admit that seems wierd since it does have a toString method). I recommend trying to use the native type boolean instead of Boolean and see if that fixes your problem.
misha nesterenko
Greenhorn

Joined: Feb 05, 2011
Posts: 28
no, nothing helped

I have changed type, name of the property and there is still no output

login.jsp


CheckLoginAction.java


output:
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
Strange, this code looks like it should access the values in your action class. Are you sure your action class is being called? Are you calling the JSP directly?
misha nesterenko
Greenhorn

Joined: Feb 05, 2011
Posts: 28
I directly call jsp file, action is definetly called (I added Syste.out.println("sdfsdfsdf") in the execute method and I can see in the tomcat console sdfsdfsdf printed when I call login.jsp)
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
try this in your jsp:

misha nesterenko
Greenhorn

Joined: Feb 05, 2011
Posts: 28
doesnt work
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
I'm at a loss. The next thing I would try would be to put an s:debug tag between the <s:action> and </s:action> tags to see what's on the stack. Maybe that will clear up why loggedIn isn't accessible.
misha nesterenko
Greenhorn

Joined: Feb 05, 2011
Posts: 28
nothing



what is attribute var in action tag for?
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Novice in struts2 but just want to check what is happening,
try simple String type instead of boolean and see if something is displayed or not.


Have Fun with Java
little,little.. little by little makes a lot..
misha nesterenko
Greenhorn

Joined: Feb 05, 2011
Posts: 28
and, one more question, we can access properties via their name only if they belong to a current action (which is stored in top of the ValueStack), so how can I tell where to look for this property?
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
hmm... looking at the api for the action tag, it looks like I misunderstood how it works. I think you'll want to set the executeResult attribute of it to true, then in your struts.xml file specify a JSP for it to use to generate its output, then in that JSP you should be able to access loggedIn with OGNL. I also thought you could use that tag to do what you are trying to do, but It looks like I'm mistaken.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get action property
 
Similar Threads
Struts 2 hidden values
Tags variable, with quotes?
Processing a Return or Enter Key
Struts 2 Question
Form processing using register.java but it doesn't show my hashmap errormessages