problem:
I needed to pass a hashmap into a custom tag. This hashmap was to be created on the jsp page using jstl, and then passed into the tag as an attribute.
For some reason i was not able to find the solution with just one google query.
solution:
1. first, to create a hashmap on the jsp using jstl and add some stuff to it:
2. next, add another attribute to your tag in the tld file:
3. finally, pass the hashmap into your tag .. <tag someName="${something}" /> and make sure that the setter in the tag takes in a Map
Showing posts with label jsp. Show all posts
Showing posts with label jsp. Show all posts
Wednesday, July 30, 2008
Friday, March 07, 2008
Path does not start with a "/" character
Problem:
I get this error when using the tiles plugin when building out some tiles:
java.lang.IllegalArgumentException: Path .some.tiles.path does not start with a "/" character
first, lets pretend that the tile in question looks like this:
<definition name=".some.tiles.path" extends=".some.other.tiles.path"> ..some stuff.. </definition>
Solution:
ive noticed that the reason for this error can be one of the following:
1. if you look at the tile that this tile extends, and what that tile extends, until you find the tile that extends nothing, that tile should have a definition like this:
<definition name=".some.base.tile" path="/a/real/path/to/some/jsp/somejsp.jsp"> ..some stuff.. </definition>
the key thing, is that the path of the parent tile starts with a "/" character
2. if #1 is not your problem, then you might have a duplicate definition of the tile name which the error talks about.
3. Another thing that can happen is that your tiles path that you are referencing in struts-config.xml does not exist at all, because maybe you misspelled it, in which case that same error is thrown.
I get this error when using the tiles plugin when building out some tiles:
java.lang.IllegalArgumentException: Path .some.tiles.path does not start with a "/" character
first, lets pretend that the tile in question looks like this:
<definition name=".some.tiles.path" extends=".some.other.tiles.path"> ..some stuff.. </definition>
Solution:
ive noticed that the reason for this error can be one of the following:
1. if you look at the tile that this tile extends, and what that tile extends, until you find the tile that extends nothing, that tile should have a definition like this:
<definition name=".some.base.tile" path="/a/real/path/to/some/jsp/somejsp.jsp"> ..some stuff.. </definition>
the key thing, is that the path of the parent tile starts with a "/" character
2. if #1 is not your problem, then you might have a duplicate definition of the tile name which the error talks about.
3. Another thing that can happen is that your tiles path that you are referencing in struts-config.xml does not exist at all, because maybe you misspelled it, in which case that same error is thrown.
Thursday, February 21, 2008
JSP syntax: empty checks, params, misc
This stuff is so elementary that i am always annoyed to forget it every time i dont use jsp for a few months.
1. Get params from the url request, ie http://dogself.com?param1=test&something=poop
<c:out value="param1 is: ${param.param1} something is:${param.something}"/>
also there is ${params} for getting lists, but i would need to read up on that
2. checking if a request attribute is null or empty:
<c:if test="${param.page != null && not empty param.page}">
<c:import url="${base_html_dir}${param.page}"></c:import>
</c:if>
3. setting variables:
<c:set var="thingToSet" value="${1+ 3}">
this by default has the scope of 'page', also can be 'session' defined by attribute 'scope'
ill add more as i go
1. Get params from the url request, ie http://dogself.com?param1=test&something=poop
<c:out value="param1 is: ${param.param1} something is:${param.something}"/>
also there is ${params} for getting lists, but i would need to read up on that
2. checking if a request attribute is null or empty:
<c:if test="${param.page != null && not empty param.page}">
<c:import url="${base_html_dir}${param.page}"></c:import>
</c:if>
3. setting variables:
<c:set var="thingToSet" value="${1+ 3}">
this by default has the scope of 'page', also can be 'session' defined by attribute 'scope'
ill add more as i go
Monday, March 26, 2007
Using EL in custom tags as attributes
Problem:
I was working on a custom tag and i needed to pass it a bean from a JSP page kind of like this:
<customtag var="${somebean.something.else}">
I realized that what i was getting inside my custom tag was a String, not my bean.
Solution:
You need to use the ExpressionEvaluator to evaluate the expression, and get the bean, here is the code i used in my SimpleTag: (i was getting a Date object by the way)
Edit Aug 7, 2008:
It has come to my attention that in jsp 2.0 the EL expressions are evaluated before being passed to the custom tags, so you dont need to do any of this crap anymore.
I was working on a custom tag and i needed to pass it a bean from a JSP page kind of like this:
<customtag var="${somebean.something.else}">
I realized that what i was getting inside my custom tag was a String, not my bean.
Solution:
You need to use the ExpressionEvaluator to evaluate the expression, and get the bean, here is the code i used in my SimpleTag: (i was getting a Date object by the way)
Edit Aug 7, 2008:
It has come to my attention that in jsp 2.0 the EL expressions are evaluated before being passed to the custom tags, so you dont need to do any of this crap anymore.
Friday, February 09, 2007
JSP: custom tag to modify its body
This is a skeleton of what is needed to build a custom jsp tag which does something to its body. For example a tag could change the urls of all the links found in its body.
make a file called CustomTag.tld and put it into WEB-INF:
use it like this on your JSP:
<%@ taglib uri="com.mycompany.CustomTag" prefix="x"%>
<x:ct>
here is some stuff inside the tag!
<c:out value="${someparam}"/>
</x:ct>
make a file called CustomTag.tld and put it into WEB-INF:
use it like this on your JSP:
<%@ taglib uri="com.mycompany.CustomTag" prefix="x"%>
<x:ct>
here is some stuff inside the tag!
<c:out value="${someparam}"/>
</x:ct>
How to make a redirect servlet
make a servlet which calls the following method on doPost() and on doGet()
Subscribe to:
Posts (Atom)