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.JspWriter;
029 import javax.servlet.jsp.PageContext;
030
031 import org.apache.struts.action.Action;
032 import org.apache.struts.action.ActionForm;
033 import org.apache.struts.action.ActionForward;
034 import org.apache.struts.action.ActionMapping;
035
036
039 public class RenderStructureFieldAction extends Action {
040
041 @Override
042 public ActionForward execute(
043 ActionMapping mapping, ActionForm form, HttpServletRequest request,
044 HttpServletResponse response)
045 throws Exception {
046
047 try {
048 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
049 WebKeys.THEME_DISPLAY);
050
051 JspFactory jspFactory = JspFactory.getDefaultFactory();
052
053 PageContext pageContext = jspFactory.getPageContext(
054 getServlet(), request, response, null, true,
055 JspWriter.DEFAULT_BUFFER, true);
056
057 long classNameId = ParamUtil.getLong(request, "classNameId");
058 long classPK = ParamUtil.getLong(request, "classPK");
059 String fieldName = ParamUtil.getString(request, "fieldName");
060 String namespace = ParamUtil.getString(request, "namespace");
061 int repeatableIndex = ParamUtil.getInteger(
062 request, "repeatableIndex");
063 boolean readOnly = ParamUtil.getBoolean(request, "readOnly");
064
065 request.setAttribute("aui:form:namespace", namespace);
066
067 String fieldHTML = DDMXSDUtil.getFieldHTMLByName(
068 pageContext, classNameId, classPK, fieldName, repeatableIndex,
069 null, null, null, readOnly, themeDisplay.getLocale());
070
071 response.setContentType(ContentTypes.TEXT_HTML);
072
073 ServletResponseUtil.write(response, fieldHTML);
074
075 return null;
076 }
077 catch (Exception e) {
078 PortalUtil.sendError(e, request, response);
079
080 return null;
081 }
082 }
083
084 }