• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

cset doubt??

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

Can anyone explain me the use of cset with some examples and comparing it with jsp:setProperty?? Any help will be appreciated.

Thanks in advance!
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<c:set> and <c:remove>
The set and remove tags allow the setting/creation of attributes and their removable. This is particularly useful when using the EL as although it allows variables to be manipulated it does not directly support setting or deleting.
The following code shows a trivial example of using these tags.
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<html>
<head>
<title>The set and remove JSTL tags</title>
</head>
<body>
<c:set var="result" value="10"/>
<c:out value="${result}"/>
<c:remove var="result"/>
Now the variable has been removed
<c:out value="${result}"/>
</body>
</html>


The <c:set used with var is for attributes and used with target is for beans properties or map values
Set and remove with Maps and Beans
The <c: set tag can be used with Beans and maps using the target attribute instead of the var attribute. The next JSP page uses the following simple plain Java code bean.
/**
**@author Marcus Green 2006
* For use with JSTL <c:set tag
**/
package com.examulator;
public class DemoBean{
private String MyField;
public void setMyField(String s){
this.MyField = s;
}
public String getMyField(){
return this.MyField;
}
}
The JSP page is as follows
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<jsp:useBean id="address" class="java.util.HashMap" />
<jsp:useBean id="demo" class="com.examulator.DemoBean" />
<html>
<head>
<title set and remove JSTL tags with beans and maps</title>
</head>
<body>
<c:set target="${demo}" property="myField" value="guru" />
<c:set target="${address}" property="line1" value="10 Downing St" />
<c:set target="${address}" property="postcode">
SW1A2AJ
</c:set>

<c:out value="${address.line1}"/>
<c:out value="${address.postcode}"/>
<c:out value="${demo.myField}"/>
</body>
</html>
Note how the set tag is used in two versions, one where the content is assigned using the value attribute and the other (for the postcode) where it is assigned within the body of the tag. When this page is run it will output
10 Downing Street SW1A2AJ guru
The <c:remove tag does not work with Beans and Maps, there is no var attribute and you cannot use the target attribute instead. Thus the following will NOT work.
<c:remove target="${address}"/>
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marcus,

That you ver much for the detailed explanation. I'm getting to understand it. Thankgs again.
 
Marcus Green
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can see it in the no mangled smiley tags if you go direct to

http://www.examulator.com/moodle/mod/resource/view.php?id=441
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marcus,

Thanks once again for the link. Actually I extensively use your tutorials for SCWCD and they are really helpful.
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic