【问题标题】:Spring portlet ajax call, No parameter foundSpring portlet ajax调用,未找到参数
【发布时间】:2014-05-05 05:28:08
【问题描述】:

我正在尝试使用 LR 6.2 GA1 构建示例 spring portlet。 以下是同一https://docs.google.com/file/d/0By1kU5o_jlrublhUNXIxQ24wODQ/edit的来源

在 ajax 上没有获取参数。参数始终保持空白。

@Controller(value = "ProjectSearch")
@RequestMapping("VIEW")
public class ProjectSearch {
    Log log_ = LogFactoryUtil.getLog(ProjectSearch.class);

@RenderMapping
public String handleRenderRequest(final RenderRequest request,
        final RenderResponse response, Model model) {
    System.out.println("ProjectSearch.handleRenderRequest()");
    return "search_form";
}

@ResourceMapping("getProjectNameSuggestion")
public void getNameSuggestion(ResourceRequest request,
        ResourceResponse response) throws IOException {
    Map<String, String[]> map = request.getParameterMap();
    for (Map.Entry<String, String[]> element : map.entrySet()) {
        log_.info(element.getKey());
    }
    String entityName = ParamUtil.getString(request, "query");
    log_.info("Entity name==>" + entityName);

}

}
@RenderMapping
    public String handleRenderRequest(final RenderRequest request,
            final RenderResponse response, Model model) {
        System.out.println("ProjectSearch.handleRenderRequest()");
        return "search_form";
    }

@ResourceMapping("getProjectNameSuggestion")
public void getNameSuggestion(ResourceRequest request,
        ResourceResponse response) throws IOException {
    Map<String, String[]> map = request.getParameterMap();
    for (Map.Entry<String, String[]> element : map.entrySet()) {
        log_.info(element.getKey());
    }
    String entityName = ParamUtil.getString(request, "query");
    log_.info("Entity name==>" + entityName);

}

}

输出-->05:23:24,148 INFO [http-bio-8080-exec-119][ProjectSearch:41] Entity name==&gt;

谁能告诉我我做错了什么??

【问题讨论】:

    标签: ajax liferay-6 spring-portlet-mvc


    【解决方案1】:

    解决方案:

    在 liferay-portlet.xml 中配置要求名称间隔参数为 false

    现在需要将 name 间隔参数设置为 false,然后仅将表单数据映射到 Action Request 和 Render Request 中。并且表单数据也将绑定到模型对象或命令对象。

    以下是我们需要在liferay-portlet.xml文件中进行的配置

    <requires-namespaced-parameters>false</requires-namespaced-parameters>
    

    Liferay 中所需的名称空间参数行为

    Liferay 6.2 我们必须为输入元素的每个名称附加 portlet 命名空间,即表单输入元素或请求参数名称,否则 portlet 操作类将忽略没有 portlet 命名空间的参数。

    场景

    jsp页面

    在下面的表单中,我们没有将 portlet 名称空间附加到表单输入元素名称中。

    <portlet:actionURL var="addEmployeeActionURL" name="addEmployee">
    <portlet:param name="<%=ActionRequest.ACTION_NAME%>" value="addEmployee"/>
    </portlet:actionURL>
    
    <form action="<%=addEmployeeActionURL%>" name="emplyeeForm"  method="POST">
    Employee Name<br/>
    <input  type="text" name="employeeName" id="employeeName"/><br/>
    Employee Address<br/>
    <input type="text" name="employeeAddress" id="employeeName"/><br/>
    <input type="submit" name="addEmployee" id="addEmployee" value="Add Employee"/>
    </form>
    
    Portlet Class Action Method
    
    public class EmplyeePortletAction extends MVCPortlet {
    public void addEmployee(ActionRequest actionRequest,
    ActionResponse actionResponse) throws IOException, PortletException {
    
    String employeeName=ParamUtil.getString(actionRequest,"employeeName");
    String employeeAddress=ParamUtil.getString(actionRequest,"employeeAddress");
    
           }
    }
    

    在上述情况下,在 portlet 类操作中无法访问employeeName 和employeeAddress 表单输入数据。表单元素名称未附加portlet 名称空间,此类场景portlet 类忽略那些请求参数或表单输入

    解决方案:1

    需要将标签附加到每个输入元素名称。

    jsp页面

    <portlet:actionURL var="addEmployeeActionURL" name="addEmployee">
    <portlet:param name="<%=ActionRequest.ACTION_NAME%>" value="addEmployee"/>
    <portlet:param name="requestParam" value=" requestParamValue"/>
    </portlet:actionURL>
    
    <form action="<%=addEmployeeActionURL%>" name="emplyeeForm"  method="POST">
    Employee Name<br/>
    <input  type="text" name="<portlet:namespace/>employeeName" id="<portlet:namespace/>employeeName"/><br/>
    Employee Address<br/>
    <input type="text" name="<portlet:namespace/>employeeAddress" id="<portlet:namespace/>employeeName"/><br/>
    <input type="submit" name="addEmployee" id="addEmployee" value="Add Employee"/>
    </form>
    

    Portlet 类操作方法

    public class EmplyeePortletAction extends MVCPortlet {
    public void addEmployee(ActionRequest actionRequest,
    ActionResponse actionResponse) throws IOException, PortletException {
    
    String employeeName=ParamUtil.getString(actionRequest,"employeeName");
    String employeeAddress=ParamUtil.getString(actionRequest,"employeeAddress");
    String requestParamValue=ParamUtil.getString(actionRequest,"requestParam");
    
           }
    }
    

    解决方案:2 我们可以将 liferay-portlet.xml 文件中的标签值设为 false

    <requires-namespaced-parameters>false</requires-namespaced-parameters>
    

    解决方案:3

    我们可以使用合金标签库表单标签。当我们使用 AUI 标记时,它会将 portlet 名称空间附加到每个输入元素名称。

    jsp页面

    <%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
    
    <aui:input type="text" name="employeeAddress" id="employeeName"/><br/>
    <aui:input type="submit" name="addEmployee" id="addEmployee" value="Add Employee"/
    
    
    
    
    <input type="text" name="<portlet:namespace/>employeeAddress" id="<portlet:namespace/>employeeName"/>
    

    和一样

    <aui:input type="text" name="employeeAddress" id="employeeName"/>
    

    http://www.liferaysavvy.com/2013/12/liferay-spring-portlet.html http://www.liferaysavvy.com/2014/04/liferay-mvc-portlet-development.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      相关资源
      最近更新 更多