File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How to add other option tag in struts2 ins <s:select></s:select> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to add other option tag in struts2 ins <s:select></s:select>" Watch "How to add other option tag in struts2 ins <s:select></s:select>" New topic
Author

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

Sai Prasad
Ranch Hand

Joined: Feb 08, 2009
Posts: 30
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!

Take No Challenge Lightly....

Strive for Excellence..!!!
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 689



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.

>


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Sai Prasad
Ranch Hand

Joined: Feb 08, 2009
Posts: 30
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

Joined: Sep 07, 2008
Posts: 689


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

Joined: Feb 08, 2009
Posts: 30
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

Joined: Sep 07, 2008
Posts: 689



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

Joined: Feb 08, 2009
Posts: 30
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 08, 2009
Posts: 30
Hey David

Can you show me some sample relating to the same scenario... please! :banghead:
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add other option tag in struts2 ins <s:select></s:select>