0

I am having a problem in passing Struts2 property tag as parameter in java function in the jsp. I am calling a java function like this from jsp,

<s:if test="%{DoSomething()}">

DoSomething() function is in the Action class, and is being called for each record in the iterator.

The problem is that I want to pass this property <s:property value="userId"/> in the function DoSomething as java string as follow.

<s:if test="%{DoSomething("<s:property value="userId">/)}">

Can anyone please guide me that how can I do that. I goggled it but did not find anything.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • Basically I just want to pass "s:property" tag as a parameter in java function like this /)}"> – Idrees Hamayun Oct 24 '14 at 19:12
  • 1
    Show your `DoSomething` method. What type is your `userId`? – Aleksandr M Oct 24 '14 at 21:17
  • public boolean DoSomething(string User){ if(User!= null){ return true;} } //it's a simple function. I even removed all the logic, but still I am getting NULL – Idrees Hamayun Oct 24 '14 at 21:53
  • 1
    1. Mention people with `@` (e.g. @IdreesHamayun) in that way they get notification. 2. Edit your post instead posting code in comments. 3. You haven't answered about type of your `userId` property. – Aleksandr M Oct 24 '14 at 22:37
  • But `DoSomething()` *is not a function*, it's a method of some object in Java terms, it could be an action bean. – Roman C Oct 25 '14 at 07:42

3 Answers3

0
<s:if test="%{DoSomething(userId)}">
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • It does not work. I am getting null in the action class when I pass "userId", but when I write '< s:property value="userId">' in the jsp, it displays the value of UserId perfectly. – Idrees Hamayun Oct 24 '14 at 19:22
  • @IdreesHamayun Then you need to provide more information, at worst you'd need `%{DoSomething(#userId)}`, but it also depends on what `DoSomething` is, which you don't state. – Dave Newton Oct 24 '14 at 19:30
  • DoSomething is a simple boolean function that returns true or false based on the userId passed. – Idrees Hamayun Oct 24 '14 at 19:41
  • and we are calling this function in a loop' " ". Now the function DoSomething() is being called perfectly for each record in the entities. Problem comes when I try to pass s:property value as a parameter. If I pass a simple java string as a parameter it works perfectly – Idrees Hamayun Oct 24 '14 at 19:44
0

Most likely you wouldn't need to pass in a parameter like this. You are trying to call a method DoSomething from your action class. You want to pass in a parameter to this method in your action class. The userId must be existing already in you action class otherwise you couldn't be able to get it through the s:property tag. You can just use this userId variable in your DoSomething method of your action class.

-1

you cannot used Struts2 tag to another Struts2 tag, you can use expression language, first use <s:set name="userId" value="userId" /> then use ${userId}

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Pankaj Mandale
  • 596
  • 7
  • 15