?
Solved

Am I doing this JSP custom tags right ?...

Posted on 2005-04-08
5
Medium Priority
?
529 Views
Last Modified: 2013-11-24
Hi, I am new to JSP Custom Tags and I'd like to know if I am using it correctly.  I'd like to converting code#1 into code#2 (code provided below for reference) using JSP custom tags, am I doing it correctly or is there a better way?  

Any suggestions or tips would be greatly appreciated!

Thanks, noijet
***** code#1 (Inside a jsp)*****
<%
    if(loginBean.isDualLogin()) {
      %>

     ...Some HTML code....

else{
      %>
      ...Some other HTML code....
      <%
      }
    %>

***** code#2 (Inside a jsp) *** Is this correct ? *****
<control:conditional condition="user.isAdmin">
      ...Some HTML code....
</control:conditional>
<control:conditional condition="<%=(!user.isAdmin)%>">              
      ...Some other HTML code....
</control:conditional>

***** Java tag handler *****  
  public int doStartTag() throws JspException {
    if(condition) {
      return EVAL_BODY_INCLUDE;
    }  
    return SKIP_BODY;
  }
0
Comment
Question by:noijet
  • 3
5 Comments
 
LVL 12

Accepted Solution

by:
jessegivy earned 112 total points
ID: 13740728
Hmmmm,  looks like your making it too complex.  Does the administrator want to be able to see the html that the non-administrators see?  Also I'm not sure that there is actually a need for a custom tag here because it could be accomplished with a simple if statement, let me know if I'm wrong.  I'm also not quite sure what the constants are:  EVAL_BODY_INCLUDE, and SKIP_BODY?  Are these entire web pages stored as constant strings???  If you're just trying tags out I'd say it's fine but probably not the best option for performance.  Also, remember to include the custom tag reference at the top of your page.  Wasn't sure if you just left it out in what you posted or if it's not in the actual page.  Is the page running, or are you getting errors?
0
 

Author Comment

by:noijet
ID: 13741050
Hi jessegivy, thanks for your post, I am new to JSP custom tags, so currently I am practicing with it.  This kind of long, thanks in advance for your patience.   Basically, from the start, we only had the if statement (code#1) --> then we used a conditional custom tag (code#2) to replace the 'if' statement --> Now, we want to add an else clause (code#1)--> This is why I am trying to use code#2, but I'm just wondering if thats the way it is usually done in JSP custom tag code.

I think:
EVAL_BODY_INCLUDE: Means to evaluate the body
SKIP_BODY: Means to 'done', skip body evaluation.

Thanks so much,
noijet.
0
 
LVL 7

Assisted Solution

by:searlas
searlas earned 112 total points
ID: 13744941
Yes, using tags for 'else' usually does look that bad.  An example from struts logic tags would be something like:

<logic:equal property="someProperty" value="somevalue">..something..</logic:equal>
<logic:notEqual property="someProperty" value="somevalue">..something else..</logic:notEqual>
0
 

Author Comment

by:noijet
ID: 13752847
Thank you searlas.  So if I had to include that else condition to that "if" custom tag already existing, I would do it the way I stated above(code#2)?

Thanks so much,
noijet
0
 

Author Comment

by:noijet
ID: 13755596
Thank you both for your excellent comments and code !

Thanks again,
noijet.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

862 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