Solved

jsp display issue with struts framework

Posted on 2007-11-30
3
823 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumHeights  challenge 17 71
array6 challenfge 6 102
How  Can  I  resolve   this  Error "java.sql.SQLException: Invalid column index" 4 39
by zero exception 10 41
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…
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.

803 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