1. Custom Label class:
javax.servlet.jsp.tagext.bodytagsupport--Import this Package
public class Subnodestag extends Bodytagsupport {
/**
*
*/
Private static final long serialversionuid = 1396571704883585147L;
Private Bbsmessage bbsmessage;
Private String Proposalid;
private int level = 0;
private static final String Date_format = "Yyyy/mm/dd HH:mm:ss";
/**
* @param bbsmessage
* The Bbsmessage to set
*/
public void Setbbsmessage (final bbsmessage bbsmessage) {
This.bbsmessage = Bbsmessage;
}
/**
* @param proposalid
* The Proposalid to set
*/
public void Setproposalid (final String proposalid) {
This.proposalid = Proposalid;
}
/**
* {@inheritDoc}
*/
@Override
public int Doendtag () throws Jspexception {
This.getsubnodes (Bbsmessage, proposalid);
return eval_page;
}
/**
* Get the child node for each layer of message
* @param bbsmessage Bbsmessage
* @param proposalid String
*/
private void Getsubnodes (final bbsmessage bbsmessage, final String proposalid) {
To get the first-level child node.
list<bbsmessage> subnodes = Bbsmessage.getsubnodes ();
level++;
if (subnodes.size () > 0) {
Traversing child nodes
for (Bbsmessage m:subnodes) {
try {
Pagecontext.getout (). Print ("<tr><td>");
for (int i = 0; I < level; i++) {
Pagecontext.getout (). Print ("");
}
Pagecontext.getout (). Print ("<a href=/" bulletinboard.do?proposalid=);
Pagecontext.getout (). print (Proposalid);
Pagecontext.getout (). Print ("&messageid=");
Pagecontext.getout (). Print (M.getmessageid ());
Pagecontext.getout (). Print ("/>");
Pagecontext.getout (). Print (Tagutils.converthtml (M.gettitle ()));
Pagecontext.getout (). Print ("</a>");
Pagecontext.getout (). Print ("亅");
Pagecontext.getout (). Print (Tagutils.converthtml (M.getdisplayusername ()));
Pagecontext.getout (). Print ("亅");
Pagecontext.getout (). Print (New SimpleDateFormat (Date_format). FORMAT (M.getcreateddatetime ());
Pagecontext.getout (). Print ("</td></tr>");
This.getsubnodes (M, proposalid);
level--;
catch (IOException IoE) {
Ioe.printstacktrace ();
}
}
}
}
}
This completes the definition of a custom label
2. Configuration:
In the. tld file, configure the following:
<tag>
<description>
Display the subnodes.
</description>
<name>subNodes</name>
<tag-class>xxx.products.sms.sourcing.web.tag.SubNodesTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>BbsMessageModel</description>
<name>bbsMessage</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>ProposalId</description>
<name>proposalId</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
attribute indicates the parameters required for the label to be used.
3. Complete initialization of the bbsmessage (take to all child nodes):
Private list<bbsmessage> Getsubnodes (String Parentmessageid) throws Dataconnectexception, Datapropertyexception, DataAccessException {
Remove the first layer of child nodes in the DB layer
list<bbsmessage> subnodes = Bbsmessagedao.getbbsmessagebyparentmessageid (Parentmessageid);
if (subnodes.size () > 0) {
traversing the child nodes;
Bbsmessage.setsubnodes (Getsubnodes (Bbsmessage.getmessageid ()));
}
}
return subnodes;
}
4. Refer to the JSP page:
<table>
<c:if test= "${not Empty Bbsmessage.subnodes}" >
<nbs:subnodes bbsmessage= "${bbsmessage}"
Proposalid= "${proposalid}" ></nbs:subNodes>
</c:if>
</table>
This enables you to implement a tree-like message body in a page, similar to the capabilities of Windows Explorer, and to enable the display of messages.