|
Context :
I'm trying to build a JSP page to dynamically insert a new Container in a ContainerList (importing content from external data). But it doesn"t work. IN attachment, my JSP page (a modification of the simple template from the corporate samples). What is bad in it ?? THank's a lot. |
<%@ include file="include/header.inc"%>
<%@ page import="org.jahia.registries.ServicesRegistry" %>
<!--
Defining a simple container list to validate document
importation from batch Java Scriptlet
-->
<content:declareContainerList name="siteFlashes" title="Les flashs du SITE">
<content:declareField name="title" title="Titre" type="SmallText"/>
<content:declareField name="content" title="Contenu" type="BigText"/>
<content:declareField name="image" title="Picto" type="File"/>
</content:declareContainerList>
<!-- End ContainerList declaration -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="159" valign="top"><%@ include file="include/left_menu.inc"%></td>
<% if (!thePrint && hasLeft != 0) { %><td class="verticaleline"><img
src="<jahia:contextURL/>/images/pix.gif" width="25" height="12" alt=""/></td><% } %>
<td width="100%" valign="top">
<h1><%@ include file="include/page_title.inc"%></h1>
<jsp:include page="include/main_content.jsp" flush="true">
<jsp:param name="id" value="main_1"/>
</jsp:include>
<jsp:include page="include/box.jsp" flush="true">
<jsp:param name="id" value="cg13Flashes"/>
<jsp:param name="displayDetails" value="true"/>
</jsp:include>
</td>
<td><img src="<jahia:contextURL/>/images/pix.gif" width="25" height="12"
alt=""/></td>
<td valign="top">
<jsp:include page="include/box.jsp" flush="true">
<jsp:param name="id" value="right"/>
<jsp:param name="width" value="160"/>
</jsp:include>
</td>
</tr>
<tr>
<td> </td>
<td colspan="2">
<%
// Creating all needed services
ServicesRegistry registry = ServicesRegistry.getInstance();
JahiaVersionService verService = registry.getJahiaVersionService();
JahiaContainersService contService = registry.getJahiaContainersService();
// Looking for my containerList...
JahiaContainerList aList = jData.containers().getAbsoluteContainerList(
"siteFlashes", jData.gui().getLevelID( 1 ) );
// Creating in new container for my container list
JahiaContainer newFlashCont = new JahiaContainer(
0, /* ID */
jData.params().getJahiaID(), /* JahiaID */
jData.params().getPageID(), /* PageID */
aList.getID(), /* ListID */
0, /* rank */
aList.getAclID(), /* AclID */
aList.getctndefid(), /* */
verService.getCurrentVersionID(), /* VersionID */
0 /* WorkflowState */
);
out.write("Container list ID : " + aList.getID() +"<br/>");
out.write("New flash : " + newFlashCont.toString() + "<br/>");
// Exploring Definition (test)
JahiaContainerDefinition cDef = aList.getDefinition();
Hashtable subDefs = cDef.getSubDefs();
out.write("SubDefs size : " + subDefs.size() + "<br/>");
Enumeration eSB = subDefs.keys();
while( eSB.hasMoreElements() )
{
Object aKey = eSB.nextElement();
out.write("DefKey : " + aKey.toString() );
Object value = subDefs.get( aKey );
out.write(" - value : " + value.toString() + "<br/>");
}
Enumeration enumDef = cDef.getStructure( null, jData.params().getPageID() );
while( enumDef.hasMoreElements() )
{
Object aDef = enumDef.nextElement();
out.write("Def: " + aDef.toString() + "<br/>");
}
// Try to update my new Container
JahiaField aField = null;
aField = newFlashCont.getField("title");
if (aField != null) { aField.setValue("Flash 1"); }
else { out.write("Unable to set TITLE field...<br/>"); }
aField = newFlashCont.getField("content");
if (aField != null) { aField.setValue("Premier Flash 1"); }
else { out.write("Unable to set CONTENT field...<br/>"); }
// Commented, otherwise NullPointerException ???
// registry.getJahiaContainersService().saveContainer(newFlashCont, 0,
jData.params());
%>
Les flashes infos : <ul>
<%
// Viewing my info flashes
Enumeration enumFlash = aList.getContainers();
while( enumFlash.hasMoreElements() )
{
JahiaContainer aFlash = (JahiaContainer) enumFlash.nextElement();
out.write("<li>");
out.write( aFlash.getField("title").getValue() );
out.write("</li>");
}
%>
</ul>
</td>
</tr>
</table>
<%@ include file="include/footer.inc"%>
