Solved

jsp display issue with struts framework

Posted on 2007-11-30
3
822 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
ID: 20390247
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
ID: 20410602
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
ID: 20442436

<%@ 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
countX 22 80
stringclean challenge 26 70
maven project clean install and build and adding as war web plugin 4 46
servlet requestdispatcher include and forward differences 1 22
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

939 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

11 Experts available now in Live!

Get 1:1 Help Now