• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Standard Tags, Design Pattern Qs

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have some doubts on design patterns and JSP standard tags. I got curious about some standard tags after going through the JSTL spec. Please do reply to following doubts

Design Pattern:
1. Is Intercepting filter a Presentation tier or Business Tier Pattern ?
2. How is struts related to MVC and front controller pattern ?

Standard Tags (please refer to JSTL spec ):
1. How can i iterate over key and value sets returned through keySet() and entrySet() methods of following map in a <c:forEach > tag :

<%
java.util.Map capitalMap=new java.util.HashMap();
capitalMap.put("Punjab","Chandigarh");
capitalMap.put("Haryana","Chandigarh");
capitalMap.put("Orissa","Bhubneshwar");
capitalMap.put("Bihar","Patna");
capitalMap.put("Maharastra","Mumbai");
capitalMap.put("Tamil Nadu","Chennai");
request.setAttribute("MyStateMap",capitalMap);
%>

2. What is the use of var attribute in <c:if> tag ? Please give a simple example?

3. In the JSTL spec., var attribute of <c:forEach > tag has been mentioned as optional in both the syntaxes. So how can i access value of current item in a List without specifying var attribute ?

Regards,
[ December 01, 2005: Message edited by: lalit upadheyay ]
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Design Pattern:
1. Is Intercepting filter a Presentation tier or Business Tier Pattern ?
* If you learn what those three terms mean, it will be very obvious.
2. How is struts related to MVC and front controller pattern ?
* Struts is a framework that boasts both but I don't think it's important for the test.

Standard Tags (please refer to JSTL spec ):
1. How can i iterate over key and value sets returned through keySet() and entrySet() methods of following map in a <c:forEach > tag :
<%
java.util.Map capitalMap=new java.util.HashMap();
capitalMap.put("Punjab","Chandigarh");
capitalMap.put("Haryana","Chandigarh");
capitalMap.put("Orissa","Bhubneshwar");
capitalMap.put("Bihar","Patna");
capitalMap.put("Maharastra","Mumbai");
capitalMap.put("Tamil Nadu","Chennai");
request.setAttribute("MyStateMap",capitalMap);
%>
*I believe you can specify .key and .value on your iterated items.

2. What is the use of var attribute in <c:if> tag ? Please give a simple example?
* var here will be a Boolean that represents the evaluation of the test attribute

3. In the JSTL spec., var attribute of <c:forEach > tag has been mentioned as optional in both the syntaxes. So how can i access value of current item in a List without specifying var attribute ?
* I don't think you can. You should only leave out var if you don't need access to the objects:
<c:forEach start="1" end="10">
I'm displaying this 10 times.
</c:forEach>
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About the Standard Tags:

1.
<c:forEach items="${MyStateMap}" var="statemap">
<c ut value="${statemap.key},${statemap.value}"/>
</c:forEach>

2. <c:if> is mainly used to output something in certain condition

<c:if test="${isSunny}">
What a beautiful day !
</c:if>


3. Var is optional because you can use forEach as a simple loop.
If you want to iterate through a List, you'll have to use var.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Design Pattern:
1. Is Intercepting filter a Presentation tier or Business Tier Pattern ?
2. How is struts related to MVC and front controller pattern ?

----------------------------------------------------------------
answer

intercepting filter ---------- presentation tier
struts related to front controller
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Almost all the questions are answered, just wanted to add one more thing on importance of 'var' attrib in <c:if>.
If you see there is another attrib 'scope', if these two attributes are combined, you can access the result of this particular expr as any other scoped attribute that has a Boolean type.
 
lalit upadheyay
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Thanks for your reply but regarding Q 1 on Standard tags , i want output like

keyset:
===========
Punjab
Haryana
Orissa
Bihar
Maharastra
Tamil Nadu

entryset:
===========
Chandigarh
Chandigarh
Bhubneshwar
Patna
Mumbai
Chennai

I want the output in two separate loops (non nested) , one following the other using EL's or stands tags.

Sorry for being unable to put my question earlier exactly.

Thanks and Regards
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose that what you call entries mean values of the map.
The you should do the same loop twice :



[ December 06, 2005: Message edited by: Satou kurinosuke ]

[ December 06, 2005: Message edited by: Satou kurinosuke ]
[ December 06, 2005: Message edited by: Satou kurinosuke ]
 
Hold that thought. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic