เมื่อสร้าง custom tag ควรกำหนดพร็อพเพอร์ตี้ต่อไปนี้สำหรับแต่ละ attribute ในไฟล์ TLD (Tag Library Descriptor)
| ลำดับ | พร็อพเพอร์ตี้ | วัตถุประสงค์ |
|---|---|---|
| 1 | name | ชื่อของ attribute (ต้องไม่ซ้ำใน tag เดียวกัน) |
| 2 | required | true/false - บังคับหรือไม่บังคับ |
| 3 | rtexprvalue | true/false - รองรับ runtime expression (เช่น ${...}) ได้หรือไม่ |
| 4 | type | คลาส Java ของ attribute (ค่าเริ่มต้น String) |
| 5 | description | คำอธิบายเพื่อเอกสาร |
| 6 | fragment | true/false - ค่าควรถือเป็น JspFragment หรือไม่ |
ตัวอย่างใน TLD
<attribute>
<name>attribute_name</name>
<required>false</required>
<type>java.util.Date</type>
<fragment>false</fragment>
</attribute>
ตัวอย่าง 2 attributes
<attribute>
<name>attribute_name1</name>
<required>false</required>
<type>java.lang.Boolean</type>
<fragment>false</fragment>
</attribute>
<attribute>
<name>attribute_name2</name>
<required>true</required>
<type>java.util.Date</type>
</attribute>
คำแนะนำ
- ตั้งค่า
required="true"สำหรับ attribute ที่จำเป็น - ใช้
rtexprvalue="true"เพื่อรองรับ EL expressions - ระบุ
typeให้ชัดเจนเพื่อ type safety - ใช้
fragment="true"สำหรับ attribute ที่รับ body content แบบ dynamic