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

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;
  }
noijetAsked:
Who is Participating?
 
jessegivyDeveloperCommented:
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
 
noijetAuthor Commented:
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
 
searlasCommented:
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
 
noijetAuthor Commented:
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
 
noijetAuthor Commented:
Thank you both for your excellent comments and code !

Thanks again,
noijet.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.