001
014
015 package com.liferay.portlet.dynamicdatamapping.action;
016
017 import com.liferay.portal.kernel.servlet.ServletResponseUtil;
018 import com.liferay.portal.kernel.util.ContentTypes;
019 import com.liferay.portal.kernel.util.ParamUtil;
020 import com.liferay.portal.theme.ThemeDisplay;
021 import com.liferay.portal.util.PortalUtil;
022 import com.liferay.portal.util.WebKeys;
023 import com.liferay.portlet.dynamicdatamapping.util.DDMXSDUtil;
024
025 import javax.servlet.http.HttpServletRequest;
026 import javax.servlet.http.HttpServletResponse;
027 import javax.servlet.jsp.JspFactory;
028 import javax.servlet.jsp.PageContext;
029
030 import org.apache.struts.action.Action;
031 import org.apache.struts.action.ActionForm;
032 import org.apache.struts.action.ActionForward;
033 import org.apache.struts.action.ActionMapping;
034
035
038 public class RenderStructureFieldAction extends Action {
039
040 @Override
041 public ActionForward execute(
042 ActionMapping actionMapping, ActionForm actionForm,
043 HttpServletRequest request, HttpServletResponse response)
044 throws Exception {
045
046 try {
047 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
048 WebKeys.THEME_DISPLAY);
049
050 JspFactory jspFactory = JspFactory.getDefaultFactory();
051
052 PageContext pageContext = jspFactory.getPageContext(
053 getServlet(), request, response, null, true, 0, true);
054
055 long classNameId = ParamUtil.getLong(request, "classNameId");
056 long classPK = ParamUtil.getLong(request, "classPK");
057 String fieldName = ParamUtil.getString(request, "fieldName");
058 String namespace = ParamUtil.getString(request, "namespace");
059 String portletNamespace = ParamUtil.getString(
060 request, "portletNamespace");
061 boolean readOnly = ParamUtil.getBoolean(request, "readOnly");
062
063 request.setAttribute("aui:form:portletNamespace", portletNamespace);
064
065 String fieldHTML = DDMXSDUtil.getFieldHTMLByName(
066 pageContext, classNameId, classPK, fieldName, null,
067 portletNamespace, namespace, null, readOnly,
068 themeDisplay.getLocale());
069
070 response.setContentType(ContentTypes.TEXT_HTML);
071
072 ServletResponseUtil.write(response, fieldHTML);
073
074 return null;
075 }
076 catch (Exception e) {
077 PortalUtil.sendError(e, request, response);
078
079 return null;
080 }
081 }
082
083 }