| | |
How to pass a server side value to an attribute of a custom jsp tag
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2007
Posts: 3
Reputation:
Solved Threads: 0
Hi All:
I needed to passed an integer value from the following code:
<%=ic.getTotalNumOfRecords()%>
to an attribute of a custom tag
<inquiry:tableClaimHistory numberOfRecords="5" dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
The function getTotalNumOfRecords returns an int.
The attribute numberOfRecords expects an string.
Here are the different ways I tried in a jsp page but I get also the following errors:
1.)
Error Message:
claimHistoryView.jsp:190:3: Unterminated tag.
<inquiry:tableClaimHistory numberOfRecords=<%=ic.getTotalNumOfRecords()%> dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
2.)
Error Message:
claimHistoryView.jsp:190:4: The required attribute "numberOfRecords" is missing.
<inquiry:tableClaimHistory numberOfRecords="<%=ic.getTotalNumOfRecords()%>" dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
3.)
Error Message:
java.lang.NumberFormatException: For input string: "<%ic.getTotalNumOfRecords();%>"
4.)
error message:
java.lang.NumberFormatException: For input string: "<%numberOfRecords2;%>"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
at java.lang.Double.valueOf(Double.java:447)
at java.lang.Double.(Double.java:539)
at com.DisplayTableClaimHistoryTag.displayTable(DisplayTableClaimHistoryTag.java:63)
5.)
error message:
claimHistoryView.jsp:194:3: Unterminated tag.
<inquiry:tableClaimHistory numberOfRecords=<%numberOfRecords2;%> dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
In the custom tag java code called "DisplayTableClaimHistoryTag"
I tried to used the following code:
The problem is that in order to get session I needed HttpSession object. I don't know how to passed HttpSession "session" object
to a custom tag. Is there a way to do this?
Any hint would be greated appreciated.
Yours,
Frustrated
I needed to passed an integer value from the following code:
<%=ic.getTotalNumOfRecords()%>
to an attribute of a custom tag
<inquiry:tableClaimHistory numberOfRecords="5" dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
The function getTotalNumOfRecords returns an int.
The attribute numberOfRecords expects an string.
Here are the different ways I tried in a jsp page but I get also the following errors:
1.)
•
•
•
•
<%@ include file="../common/page_imports.jsp" %>
<inquiry:tableClaimHistory numberOfRecords=<%=ic.getTotalNumOfRecords()%> dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
claimHistoryView.jsp:190:3: Unterminated tag.
<inquiry:tableClaimHistory numberOfRecords=<%=ic.getTotalNumOfRecords()%> dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
2.)
•
•
•
•
<%@ include file="../common/page_imports.jsp" %>
<inquiry:tableClaimHistory numberOfRecords="<%=ic.getTotalNumOfRecords()%>" dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
claimHistoryView.jsp:190:4: The required attribute "numberOfRecords" is missing.
<inquiry:tableClaimHistory numberOfRecords="<%=ic.getTotalNumOfRecords()%>" dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
3.)
•
•
•
•
<%@ include file="../common/page_imports.jsp" %>
<inquiry:tableClaimHistory numberOfRecords="<%ic.getTotalNumOfRecords();%>" dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
java.lang.NumberFormatException: For input string: "<%ic.getTotalNumOfRecords();%>"
4.)
•
•
•
•
<%@ include file="../common/page_imports.jsp" %>
<%
int records1 = ic.getTotalNumOfRecords();
Integer records2 = new Integer(records1);
String numberOfRecords2 = records2.toString();
%>
<inquiry:tableClaimHistory numberOfRecords="<%numberOfRecords2;%>" dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
java.lang.NumberFormatException: For input string: "<%numberOfRecords2;%>"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
at java.lang.Double.valueOf(Double.java:447)
at java.lang.Double.(Double.java:539)
at com.DisplayTableClaimHistoryTag.displayTable(DisplayTableClaimHistoryTag.java:63)
5.)
•
•
•
•
<%
int records1 = ic.getTotalNumOfRecords();
Integer records2 = new Integer(records1);
String numberOfRecords2 = records2.toString();
%>
<inquiry:tableClaimHistory numberOfRecords=<%numberOfRecords2;%> dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
claimHistoryView.jsp:194:3: Unterminated tag.
<inquiry:tableClaimHistory numberOfRecords=<%numberOfRecords2;%> dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
In the custom tag java code called "DisplayTableClaimHistoryTag"
I tried to used the following code:
•
•
•
•
InquiryContext ic = InquiryContext.getContext(session);
to a custom tag. Is there a way to do this?
•
•
•
•
public class DisplayTableClaimHistoryTag extends InquiryTag
{
String numberOfRecords;
public void setNumberOfRecords(String numberOfRecords)
{
this.numberOfRecords = numberOfRecords;
}
public String getNumberOfRecords()
{
return numberOfRecords;
}
public int doStartTag()throws JspException
{
InquiryContext context = (InquiryContext)pageContext.getSession().getAttribute(Constrain.CONTEXT);
if(context==null)
throw new JspException(TAG_EXCEPTION+ "InquriyContext is null.");
String hasData = (String)context.getAttribute(Constrain.CONTROL_HAS_DATA);
if(hasData==null)
throw new JspException(TAG_EXCEPTION + "The hasData property can not be null.");
boolean hd = Boolean.valueOf(hasData).booleanValue();
Debug.println("hasData="+hd);
Debug.println("hasDataString="+hasData);
if(hd)
displayTable();
else
disPlayError();
return SKIP_BODY;
}
private void displayTable() throws JspException
{
String outString ="";
Debug.println("dispalyTable() ********* dataAction="+ dataAction);
JspWriter out = pageContext.getOut();
/*
* Minimum height height= 103,70
* 21.7 per row
* First row==103+21.5=124.5
* Second row ==103+21.5*2=146
* Third row ==103+21.5*3=167.5
*/
Double numberOfRecordsBigDouble = new Double(numberOfRecords);
double numberOfRecordsDouble = 70 + 21.8*numberOfRecordsBigDouble.intValue();
if(order==null || order.equals("0"))
// outString = "<iframe src=\"" + "/inquiry/" + dataAction + "?order=0"+ "\"" + " name=\"dataFrame\" id=\"dataFrame\" height=\""+numberOfRecordsDouble+"\"" +" width=\"100%\" scrolling=\"NO\" frameborder=\"0\"></iframe>";
// outString = "<iframe src=\"" + "/inquiry/" + dataAction + "?order=0"+ "\"" + " name=\"dataFrame\" id=\"dataFrame\" style=\"height:"+numberOfRecordsDouble+"px; width:100%\" scrolling=\"NO\" frameborder=\"0\"></iframe>";
// outString = "<iframe src=\"" + "http://www.google.ca"+ "\"" + " name=\"dataFrame\" id=\"dataFrame\" style=\"height:"+numberOfRecordsDouble+"px; width:100%\" scrolling=\"NO\" frameborder=\"0\"></iframe>";
outString = "<iframe src=\"" + "/inquiry/" + dataAction + "?order=0"+ "\"" + " name=\"dataFrame\" id=\"dataFrame\" style=\"height:"+numberOfRecordsDouble+"px; width:100%\" scrolling=\"NO\" frameborder=\"0\"></iframe>";
else
{
String orderStr = "?order=" + order;
outString = "<iframe src=\"" + "/inquiry/" + dataAction + orderStr + "\"" + " name=\"dataFrame\" id=\"dataFrame\" height=\""+numberOfRecordsDouble+"\"" +" width=\"100%\" scrolling=\"NO\" frameborder=\"0\"></iframe>";
//outString = "<iframe src=\"" + "/inquiry/" + dataAction + orderStr + "\"" + " name=\"dataFrame\" id=\"dataFrame\" height=\"161\" width=\"100%\" scrolling=\"NO\" frameborder=\"0\"></iframe>";
}
Debug.println("dispalyTable() ********* outString = "+ outString);
try {
out.println(outString);
} catch (IOException e) {
this.log.error(TAG_EXCEPTION + e.toString(), e);
throw new JspException(e);
}
}
Yours,
Frustrated
java Syntax (Toggle Plain Text)
<% int records1 = ic.getTotalNumOfRecords(); Integer records2 = new Integer(records1); String numberOfRecords2 = records2.toString(); %> <inquiry:tableClaimHistory numberOfRecords="<%= numberOfRecords2 %>" dataAction="claimHistoryViewData.do" emptyKey="error.noData"/>
Though this approach is not recommended and you are better off using JSTL to reduce the clutter and better separation of presentation and business logic.
Last edited by ~s.o.s~; Jun 12th, 2007 at 2:38 pm.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- Client Side < -- > Server Side (ASP)
- Server side sends HTML over HTTP to browser (HTML and CSS)
- Server side FileBrowser (JSP)
- HTML and Server Side Includes (HTML and CSS)
- Custom Web Server Control That Validate Itself (ASP.NET)
- javascript variable in jsp session (JSP)
Other Threads in the JSP Forum
- Previous Thread: <html:button>
- Next Thread: mysql data
| Thread Tools | Search this Thread |
Tag cloud for JSP
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient project read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






