| Author |
Using EL to generate attribute/value pairs inside of an XHTML element
|
John Semler
Greenhorn
Joined: Dec 11, 2010
Posts: 13
|
|
I'm trying to remove all scriptlets from my JSP file. Since I'm working on getting my SCWCD certification, I thought I would ask the question here.
The following JSP code works:
But Eclipse gives me the following warnings:
Description Resource Path Location Type
Undefined attribute name (:). ephemeris.jsp /servlet/WebContent line 244 JSP Problem
Undefined attribute name (:). ephemeris.jsp /servlet/WebContent line 246 JSP Problem
Undefined attribute name (:). ephemeris.jsp /servlet/WebContent line 248 JSP Problem
Undefined attribute name (DE200). ephemeris.jsp /servlet/WebContent line 244 JSP Problem
Undefined attribute name (DE405). ephemeris.jsp /servlet/WebContent line 246 JSP Problem
Undefined attribute name (DE406). ephemeris.jsp /servlet/WebContent line 248 JSP Problem
Undefined attribute name (ephemeris.catalog). ephemeris.jsp /servlet/WebContent line 244 JSP Problem
Undefined attribute name (ephemeris.catalog). ephemeris.jsp /servlet/WebContent line 246 JSP Problem
Undefined attribute name (ephemeris.catalog). ephemeris.jsp /servlet/WebContent line 248 JSP Problem
Here's the result of the HTML rendering ("view source" on web browser). This is the correct result after selecting "DE405".
Is there something wrong with the way I use the expression?
|
 |
John Semler
Greenhorn
Joined: Dec 11, 2010
Posts: 13
|
|
I coded up a tag so I can avoid getting the warning messages.
This is what I coded in my JSP ("ephemeris.jsp"):
This is what gets rendered to output after selecting "DE405" ("View Source" from browser client):
*****************************************************************************************
How did I implement my tag?
Here's my Java code that writes the replacement XHTML code ("Radio.java"):
Here's my tag library descriptor ("RadioTag.tld"):
*****************************************************************************************
If anybody can come up with an explanation as to what was wrong with the orignal coding, I'd still be interested in knowing.
Just saw the Dynamic Attrribute tutorial for tag programming, Java Ranch is a great resource!
|
 |
Frits Walraven
Rancher
Joined: Apr 07, 2010
Posts: 1039
|
|
Hi John,
If have looked at your code twice and I couldn't find a reason why Eclipse was giving warnings.
Your solution by using dynamic attributes is a good one.
Just for our viewers, this could be the solution:
taglib:
TagHandler:
jsp:
rendered into:
CATALOG: DE200<br></br>
<input name= "Catalog" onclick= "this.form.submit()" class= "radio" type= "radio" value="DE200" checked="checked" ></input>
DE200<br>
<input name= "Catalog" onclick= "this.form.submit()" class= "radio" type= "radio" value="DE405" ></input>
DE405<br>
<input name= "Catalog" onclick= "this.form.submit()" class= "radio" type= "radio" value="DE406" ></input>
DE406<br>
Regards,
Frits
|
 |
John Semler
Greenhorn
Joined: Dec 11, 2010
Posts: 13
|
|
Thanks!
I've converted over to the Dynamic Attributes method. I now have 3 tags defined to take care of the similiar situations involving checkboxes and select options. I put the definitions all in one file.
EphemerisTags.tld:
Checkbox.java:
Option.java:
Radio.java:
Here are my code fragments that shows how I use my tags to simplify my programming of checkboxes, radio, and select options (I maintain a name list of checked items for my check box group in the EL expresion "ephemeris.reductions"):
ephemeris.jsp:
With Month drop down box set to "December", Reduction checkboxes all checked, and Catalog DE200 radio button selected, it renders as:
|
 |
 |
|
|
subject: Using EL to generate attribute/value pairs inside of an XHTML element
|
|
|