Logic:Iterate Taglib question

S

spivee

Okay, I'm missing something here... I've looked at a lot of examples
online, but haven't been able to find out what I'm doing wrong here.

I'm trying to take a Vector of HashMap objects and use logic:iterate to
print them to a web page. This is what I have...

Alerts.class..

public class Alerts {
public HashMap alert;

public Alerts() {
alert = null;
}

public Vector <HashMap> getOpenAlerts() {
Vector <HashMap> alerts = new Vector <HashMap> ();
try {
/**
* Populate Hashmap and vector here. I've confirmed
* this is working. Basically, I've created a String,
* String HashMap and added four values to it; id,
* type, value, and message. Then I add that HashMap
* object to the Vector.
*/
}
catch (Exception ex) {}
return alerts;
}

public void setAlert(HashMap <String, String> alert) {
this.alert = alert;
}
public HashMap getAlert() {
return alert;
}

}

My jsp...

<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ page language="java" import="java.util.*" %>
<%@ page language="java" import="com.my.package.Alerts" %>

<%
Alerts openAlerts = new Alerts();
Vector alerts = openAlerts.getOpenAlerts();
session.setAttribute("alerts", alerts);
%>

<logic:iterate name="alerts" property="alert" id="alertobj"
type="com.eds.webhosting.registrar.Alerts" scope="session">
<bean:write name="alertobj" property="id" />-
<bean:write name="alertobj" property="type" />-
<bean:write name="alertobj" property="value" />-
<bean:write name="alertobj" property="message" /><br>
</logic:iterate>


The Error I get is... "[ServletException
in:/WEB-INF/pages/forms/manageAlerts.jsp] No getter method for property
alert of bean alerts"

I just haven't been able go get my head around these things. Any ideas?
 
B

Babu Kalakrishnan

Okay, I'm missing something here... I've looked at a lot of examples
online, but haven't been able to find out what I'm doing wrong here.

I'm trying to take a Vector of HashMap objects and use logic:iterate to
print them to a web page. This is what I have...
<logic:iterate name="alerts" property="alert" id="alertobj"
type="com.eds.webhosting.registrar.Alerts" scope="session">
<bean:write name="alertobj" property="id" />-
<bean:write name="alertobj" property="type" />-
<bean:write name="alertobj" property="value" />-
<bean:write name="alertobj" property="message" /><br>
</logic:iterate>


The Error I get is... "[ServletException
in:/WEB-INF/pages/forms/manageAlerts.jsp] No getter method for property
alert of bean alerts"

You want to access values that are in a Map, but trying to access them
as if they are "properties" of the object. The above construct would
work only if you had accessors with method names as getId(), getType(),
getValue() etc in the Map object.

To do this right - read the section named "Mapped properties" in the
following document.

http://struts.apache.org/faqs/indexedprops.html

BK
 
S

Spivee

Thanks, that helped me figure out what I was doing wrong. I was trying
to iterate on the vector. What I did was build an object that
contained the vector (was actually already built) and put that object
in the session, then I was able to iterate correctly...

Basically,

public class Alert() {
private HashMap alert;
.... build the hashmap....

public class Alerts() {
private Vector <Alert> alerts;
.... populate the vector ....


<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ page language="java" import="com.my.package.Alerts" %>

<%
Alerts alerts = new Alerts();
session.setAttribute("alerts", alerts);
%>

<logic:iterate name="alerts" property="alerts" >
<bean:write....
</logic:iterat>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,230
Latest member
LifeBoostCBD

Latest Threads

Top