JSP <-> Taglib

Status
Nicht offen für weitere Antworten.

pmy180494

Neues Mitglied
Ich möchte in eine JavaServerPage einen Taglib einbauen.

Folgendes habe ich vorbereitet :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<taglib
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd"
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">

	<tlib-version>1.0</tlib-version>
	<tag>
		<name>info</name>
		<tagclass>de.hes.web.taglib.InfoTag</tagclass>
		<bodycontent>empty</bodycontent>
		<attribute>
			<name>id</name>
			<required>true</required>
		</attribute>
	</tag>
</taglib>

und :

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

	<servlet-mapping>
		<servlet-name>HeaderInfo</servlet-name>
		<url-pattern>/HeaderInfo.html</url-pattern>
	</servlet-mapping>


	<jsp-config>
		<taglib>
			<taglib-uri>http://.../tools/taglib/hesTagLib</taglib-uri>
			<taglib-location>
				/WEB-INF/tags/hesTagLib.tld
			</taglib-location>
		</taglib>
	</jsp-config>

</web-app>

und zum aufrufen :

Code:
<hes:info id="96" />

Funktioniert einwandfrei.

Wenn ich jetzt folgendes zum aufrufen schreibe :

Code:
<hes:info id="<%=feld.getId()%>" />

kommt folgende Fehlermeldung :

According to TLD or attribute directive in tag file, attribute id does not accept any expressions


Auch folgendes geht nicht :

Code:
<hes:info id="${feld.getId()}" />

oder

<hes:info id="#{feld.getId()}" />

Warum geht das nicht?
Der Wert von feld.getId() wird woanders im Programm verwendet
und funktioniert auch.

Ich finde leider nirgentwo eine Beschreibung dafür.
Soll heißen, das ich schon danach gesucht habe.
 

HLX

Top Contributor
pmy180494 hat gesagt.:
Code:
<hes:info id="<%=feld.getId()%>" />

kommt folgende Fehlermeldung :

According to TLD or attribute directive in tag file, attribute id does not accept any expressions

Du möchtest an dieser Stelle dem Attribut 'id' eine Expression zuweisen. Das musst du jedoch in der TLD-Datei explizit für das Attribut erlauben:
Code:
...
    <attribute> 
         <name>id</name> 
         <required>true</required>
         <rtexprvalue>true</rtexprvalue>
    </attribute>
...
 
G

Guest

Gast
Danke für den Tip.
Zumindest kommt jetzt eine andere Fehlermeldung :
  • The function getId must be used with a prefix when a default namespace is not specified
 
Status
Nicht offen für weitere Antworten.

Ähnliche Java Themen


Oben