?
Solved

jsp display issue with struts framework

Posted on 2007-11-30
3
Medium Priority
?
828 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.
Suggested Courses

777 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