Author: julien(a)jboss.com
Date: 2007-03-10 14:16:04 -0500 (Sat, 10 Mar 2007)
New Revision: 6623
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java
trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
Log:
improved the JSF portlet component to add the capability to add javascript handling before
a portlet URL is submitted to the server which allows to add additional parameters in the
portlet URL
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-10
00:20:00 UTC (rev 6622)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-10
19:16:04 UTC (rev 6623)
@@ -38,6 +38,7 @@
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
+import javax.faces.event.AbortProcessingException;
import javax.faces.model.SelectItem;
import org.jboss.logging.Logger;
@@ -49,6 +50,7 @@
import org.jboss.portal.core.model.portal.PortalObjectContainer;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.admin.ui.actions.WindowComparator;
@@ -602,6 +604,34 @@
}
}
+ public List getRegionItems()
+ {
+ try
+ {
+ Map windows = getWindows((Page)getSelectedObject());
+
+ //
+ ArrayList regions = new ArrayList(windows.keySet());
+ Collections.sort(regions);
+ for (int i = 0; i < regions.size();i++)
+ {
+ String regionName = (String)regions.get(i);
+ SelectItem regionItem = new SelectItem(regionName, regionName);
+ regions.set(i, regionItem);
+ }
+
+ //
+ return regions;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ //
+ return Collections.EMPTY_LIST;
+ }
+ }
+
public Map getWindowItemsMap() throws Exception
{
Map windowMap = getWindows((Page)getSelectedObject());
@@ -644,15 +674,41 @@
if (uris != null && uris.length > 0)
{
String uri = uris[0];
-
PortalObject po = getSelectedObject();
switch(po.getType())
{
case PortalObject.TYPE_WINDOW:
+ {
Window window = (Window)po;
window.getContent().setURI(uri);
break;
+ }
case PortalObject.TYPE_PAGE:
+ {
+ // Validate window name
+ String windowName =
((String[])actionParams.get("windowName"))[0];
+ if (windowName.trim().length() == 0)
+ {
+ FacesContext faces = FacesContext.getCurrentInstance();
+ FacesMessage message = new
FacesMessage(FacesMessage.SEVERITY_ERROR, "No window name!", null);
+ faces.addMessage("layoutForm:windowName", message);
+ throw new AbortProcessingException();
+ }
+
+ // Check for duplicate window name
+ Page page = (Page)getSelectedObject();
+ if (page.getWindow(windowName) != null)
+ {
+ FacesContext faces = FacesContext.getCurrentInstance();
+ FacesMessage message = new
FacesMessage(FacesMessage.SEVERITY_ERROR, "Duplicate window name found on this
page!", null);
+ faces.addMessage("layoutForm:windowName", message);
+ throw new AbortProcessingException();
+ }
+
+ // Get the target region
+ String targetRegion =
((String[])actionParams.get("targetRegion"))[0];
+
+ //
selectedContentURI = uri;
selectedContentParameters.clear();
for (Iterator i = actionParams.entrySet().iterator();i.hasNext();)
@@ -666,9 +722,54 @@
selectedContentParameters.put(paramName, paramValue);
}
}
+
+ try
+ {
+ Window window = page.createWindow(windowName,
selectedContentType, uri);
+ Content content = window.getContent();
+ for (Iterator i =
selectedContentParameters.entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ String paramName = (String)entry.getKey();
+ String paramValue = (String)entry.getValue();
+ content.setParameter(paramName, paramValue);
+ }
+
+ //
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION,
targetRegion);
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER,
"" + Integer.MAX_VALUE);
+
+ // Get the windows belonging to the selected region sorted by
order
+ List windows = new ArrayList();
+ for (Iterator i =
page.getChildren(PortalObject.WINDOW_MASK).iterator();i.hasNext();)
+ {
+ Window tmp = (Window)i.next();
+ if
(targetRegion.equals(tmp.getProperty(ThemeConstants.PORTAL_PROP_REGION)))
+ {
+ windows.add(tmp);
+ }
+ }
+
+ // Sort windows
+ Collections.sort(windows, new WindowComparator());
+
+ // Add the created one
+ windows.add(window);
+
+ // Update the order states
+ for (int i = 0;i < windows.size();i++)
+ {
+ Window tmp = (Window)windows.get(i);
+ tmp.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER,
"" + i);
+ }
+ }
+ catch (DuplicatePortalObjectException unexpected)
+ {
+ unexpected.printStackTrace();
+ }
break;
+ }
}
-
}
}
}
Modified: trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java 2007-03-10
00:20:00 UTC (rev 6622)
+++ trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java 2007-03-10
19:16:04 UTC (rev 6623)
@@ -26,7 +26,6 @@
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.PortletParameters;
-import org.jboss.portal.portlet.PortletParametersStateString;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.portlet.invocation.ActionInvocation;
Modified: trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java 2007-03-10
00:20:00 UTC (rev 6622)
+++ trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java 2007-03-10
19:16:04 UTC (rev 6623)
@@ -87,6 +87,9 @@
/** The initial mode value if not null, otherwise VIEW is used. */
private String initialMode;
+ /** . */
+ private String onClick;
+
/** The internal nav state. */
private PortletParameters internalNavState;
@@ -211,6 +214,16 @@
this.initialMode = initialMode;
}
+ public String getOnClick()
+ {
+ return onClick;
+ }
+
+ public void setOnClick(String onClick)
+ {
+ this.onClick = onClick;
+ }
+
WindowState getInternalWindowState()
{
if (internalWindowState == null)
@@ -340,7 +353,7 @@
}
//
- Object values[] = new Object[10];
+ Object values[] = new Object[11];
values[0] = super.saveState(faces);
values[1] = instanceId;
values[2] = opaqueValue;
@@ -351,6 +364,7 @@
values[7] = initialMode;
values[8] = internalNavState;
values[9] = internalMode;
+ values[10] = onClick;
return values;
}
@@ -370,6 +384,7 @@
initialMode = (String)values[7];
internalNavState = (PortletParameters)values[8];
internalMode = (Mode)values[9];
+ onClick = (String)values[10];
}
public void decode(FacesContext faces)
@@ -472,8 +487,82 @@
FragmentResponse fragment = (FragmentResponse)pir;
ResponseWriter writer = faces.getResponseWriter();
writer.startElement("div", this);
+ writer.writeAttribute("id", "bilto", null);
writer.write(fragment.getContent());
writer.endElement("div");
+
+ //
+ if (onClick != null)
+ {
+ writer.startElement("script", this);
+ writer.write(
+
+ "var isIE = /msie/i.test(navigator.userAgent);\n" +
+
+ "function attachEvent(elm, eventName, eventHandler) {\n"
+
+ " if (isIE) {\n" +
+ " elm.attachEvent(\"on\" + eventName,
eventHandler);\n" +
+ " } else {\n" +
+ " elm.addEventListener(eventName, eventHandler,
false);\n" +
+ " }\n" +
+ "}\n" +
+
+ "function getEventTarget(event) {\n" +
+ " var targetElement = isIE ? event.srcElement :
event.target;\n" +
+ " while (targetElement.nodeType == 3 &&
targetElement.parentNode != null) {\n" +
+ " targetElement = targetElement.parentNode;\n" +
+ " }\n" +
+ " return targetElement;\n" +
+ "}\n" +
+
+ "\n" +
+
+ "function PortletURL(url) {\n" +
+ " this.params = new Array();\n" +
+ " this.url = url;\n" +
+ " this.setParameter = function(name, value) {;\n" +
+ " this.params[name] = value;\n" +
+ " return this;\n" +
+ " }\n" +
+ " this.toString = function() {;\n" +
+ " var tmp = this.url;\n" +
+ " for (var i in this.params) {\n" +
+ " tmp = tmp + ('&' + i + '=' +
this.params[i]);\n" +
+ " };\n" +
+ " return tmp;\n" +
+ " }\n" +
+ "}\n" +
+
+ "function fx(event) {\n" +
+ " var target = getEventTarget(event);\n" +
+ " if (target.nodeName == 'INPUT' &&
target.type == 'submit') {\n" +
+ " var current = target.parentNode;\n" +
+ " while (current.nodeName != 'FORM' &&
current.nodeName != 'BODY') {\n" +
+ " current = current.parentNode;\n" +
+ " }\n" +
+ " if (current.nodeName == 'FORM') {\n" +
+ " var action = current.action;\n" +
+ " var portletURL = new PortletURL(action);\n" +
+ " (function(url){" + onClick +
"})(portletURL);\n" +
+ " current.action = portletURL.toString();\n" +
+ " } else {\n" +
+ " // Really can't do nothing for now\n" +
+ " }\n" +
+ " }\n" +
+ " else if (target.nodeName == 'A') {\n" +
+ " var href = target.href;\n" +
+ " var portletURL = new PortletURL(href);\n" +
+ " (function(url){" + onClick +
"})(portletURL);\n" +
+ " target.href = portletURL.toString();\n" +
+ " }\n" +
+ " \n" +
+ "}\n" +
+
+ "var elt = document.getElementById('bilto');\n" +
+ "attachEvent(elt, 'click', fx);\n"
+ );
+ writer.endElement("script");
+ }
writer.flush();
}
}
Modified:
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
===================================================================
---
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-10
00:20:00 UTC (rev 6622)
+++
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-10
19:16:04 UTC (rev 6623)
@@ -51,9 +51,6 @@
<div>
<h:commandButton value="->"
id="l_#{regionName}" actionListener="#{assignWindowsAction.execute}"
styleClass="portlet-form-button"/>
</div>
- <div>
- <h:commandButton value="<-"
id="r_#{regionName}" actionListener="#{assignWindowsAction.execute}"
styleClass="portlet-form-button"/>
- </div>
</td>
</tr>
</tbody>
@@ -73,6 +70,17 @@
</tr>
<tr>
<td class="label">
+ <span class="portlet-form-field-label">Target
Region:</span>
+ </td>
+ <td class="widget">
+ <h:selectOneMenu id="targetRegion"
styleClass="portlet-form-input-field">
+ <f:selectItems
value="#{portalobjectmgr.regionItems}"/>
+ </h:selectOneMenu>
+ <h:message for="targetRegion"
errorClass="portlet-msg-error"/>
+ </td>
+ </tr>
+ <tr>
+ <td class="label">
<span class="portlet-form-field-label">Content
type:</span>
</td>
<td class="widget">
@@ -99,7 +107,8 @@
supportedModes="edit"
supportedWindowStates="normal"
initialMode="edit"
- initialWindowState="normal"/>
+ initialWindowState="normal"
+ onClick="url.setParameter('windowName',
document.getElementById('layoutForm:windowName').value).setParameter('targetRegion',
document.getElementById('layoutForm:targetRegion').value);"/>
</div>
</ui:define>