Dashboard > Community Wiki > ... > Developing with Magnolia > How to access paragraph data
How to access paragraph data Log In View a printable version of the current page.

Added by GrĂ©gory Joseph , last edited by Boris Kraft on Jun 23, 2008  (view change)
Labels: 

How to access paragraph data

To access paragraph data of an image paragraph you can use this method in your jsp:

For image paragraphs:

<%@ page import=" com.obinary.cms.Aggregator,
com.obinary.cms.core.HierarchyManager,
com.obinary.cms.core.Content"%>
<%!
public String getImageValue(HttpServletRequest request, String name, String defaultValue) {
  String returnValue = defaultValue;
  try {
    HierarchyManager hierarchyManager= HierarchyManager)request.getAttribute(Aggregator.HIERARCHY_MANAGER);
    String URI = (String) request.getAttribute(Aggregator.HANDLE);
    Content imageProperties = hierarchyManager.getPage(URI+"_properties");
    Content theParagraph = imageProperties.getParent();
    String text = theParagraph.getNodeData(name).getString();
    if (text != null && text.length() > 0) {
      returnValue = text;
    }
  } catch (Exception e) {
    // just don't ignore this, really.
  }
  return returnValue;
}
%>

For other paragraphs:

<%@ page import="com.obinary.cms.util.Resource,
com.obinary.cms.core.NodeData,
com.obinary.cms.core.Content"%>
<%!
public String getValue(HttpServletRequest request, String name, String defaultValue) {
  String returnValue = defaultValue;
  try {
    Content contentNode = (Content) Resource.getLocalContentNode(request);
    if (contentNode == null) {
      contentNode = (Content) Resource.getGlobalContentNode(request);
    }
    NodeData nodeData = contentNode.getNodeData(name);
    String text = nodeData.getString();

    if (text != null && text.length() > 0) {
      returnValue = text;
    }
  } catch (Exception e) {
    // just don't ignore this, really.
  }
  return returnValue;
}
%>

In its previous incarnation on JspWiki, this page was last edited on Feb 9, 2007 10:12:27 AM by 212.163.159.14
Other known authors include :

  • 61.145.233.118
Powered by a free Atlassian Confluence Open Source Project License granted to Magnolia International. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators