[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 832
  • Last Modified:

jsp display issue with struts framework

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
toharikr
Asked:
toharikr
1 Solution
 
ManishLeadCommented:
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
 
veradistCommented:
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
 
summerianCommented:

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

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now