Solved

jsp display issue with struts framework

Posted on 2007-11-30
3
820 Views
Last Modified: 2013-11-24
I am working on struts. I have total three requirements.

1. Depending the user who logged in ( will be getting from session scope) i need to make "save" button invisible.

For ex:
I am getting the userid from session scope varibale called ID_BEAN. and i have the following code
in my jsp
<html:submit styleClass="navigationButton"
                             property="screenAction"
                                 value="Save">
I need to make this button invisble when ID_BEAN is "USER" and visible when ID_BEAN is "ADMIN".

2.  In the same jsp i have lot of fields for editing. I need to make entire screen disabled (only "view" mode) if the ID_BEAN is "USER' and edit access to "ADMIN" user.

3. i have a checkbox option in the jsp. I need to enable the checkbox only when ID_BEAN is "ADMIN" and disable it when  ID_BEAN is "USER"

can anyone please provide the sample code for the above three requirements.


Thanks.
0
Comment
Question by:toharikr
3 Comments
 
LVL 11

Expert Comment

by:Manish
Comment Utility
For 1. You can control this through code. if else
  2. there is disabled property for all input types like text.
  3. For this also i think disabled will work.
http://www.w3schools.com/tags/tag_input.asp check for attributes.
0
 
LVL 1

Accepted Solution

by:
veradist earned 500 total points
Comment Utility
you can do it by ckecking the sesion value in your jsp page

just enclose your struts tags with session conditions
like ,
to display submit button when only IDBEAN is ADMIN do as below

if(session.getAttribute("IDBEAN")=="ADMIN"){
         <html:submit styleClass="navigationButton"
                             property="screenAction"
                                 value="Save">
}


repeat the same trick for your remaining two problems also...
it will work....
0
 
LVL 5

Expert Comment

by:summerian
Comment Utility

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

1. Showing button when user is admin

<c:if test="${sessionScope.ID_BEAN == 'ADMIN'}">

    <html:submit styleClass="navigationButton"

                             property="screenAction"

                                 value="Save">

</c:if>

  

2. showing input when user is admin and something else when he is not

<c:choose>

  <c:when test="${sessionScope.ID_BEAN == 'ADMIN'}">

    <!-- ADMIN -->

    <input ...>

  </c:when>

  <c:otherwise>

    <!-- non ADMIN -->

    <!-- print smth -->

  </c:otherwise>

</c:choose>
 

3. checked checkbox when user is admin

    <input type="checkbox" <c:if test="${sessionScope.ID_BEAN == 'ADMIN'}">checked</c:if>>

Open in new window

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now