Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add other option tag in struts2 ins <s:select></s:select>

 
Sai Prasad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have to add another value to the drop down list based on the user logged in ( admin ). Can anyone help me .


Thanks in advance!
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi,

User Struts 2 merge tag for this

<s:merge

For ref: http://www.roseindia.net/struts/struts2/struts2controltags/merge-tag.shtml

If you want add some value from list then you have to modify your list according to your requirement.

And then use merge.

>
 
Sai Prasad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I tried with merge option it is working fine for addition of two or more lists,but how to add just single value to the drop down list
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

Then declare another list which contains value that you required and then use merge tag.

In action you can declare list with the value you required.

 
Sai Prasad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i just wanted to add single value to drop down, not more than that.

My requirement is:


If the logged in user is administrator then a value in the drop down is to be displayed or else for normal user value not to be displayed
 
Nishan Patel
Ranch Hand
Posts: 689
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Then you have to put your code in to condition.

Just check session

<s:if test="#session.login != 'admin'">
<s:select ..... />
</s:if>

 
Sai Prasad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but i think you mis understood me question, I actually wanted to add single value to the existing list if the logged in user is admin
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can define a single value in an immediate list: { value } and use <s:merge...> to merge it into the regular list.

Another option is to perform the admin check in the Java code and prepare the list there--this also keeps the JSP much cleaner.
 
Sai Prasad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey David

Can you show me some sample relating to the same scenario... please! :banghead:
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Merge, btw, probably isn't what you want--you probably want append.

The append tag docs should be enough to get you going, in your case the second list might be an immediate list rather than an action property.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic