如何使用requestScope将值从jsp传递到portlet

时间:2015-04-14 03:45:51

标签: jstl liferay

我正在尝试将我的jsp中的一些值发送到portlet类。我正在使用jstl来实现这一点,我的要求是使用requestScope来传递portlet中的值。我在使用requestScope时已经看到了在portlet中创建URL它工作正常,但是如果值传递它不起作用,我发布我的代码到目前为止我做了

<fmt:setBundle basename="Language-ext"/>
<form action="<c:out value='${requestScope.registerUserActionUrl}'/>" method="POST">
<table width="200px">
 <tr>
  <td colspan="2">
    <font color="#FF0000"><c:out 
       value="${requestScope.errorMsg}"/></font>
</td>
</tr>
<tr>
  <td><fmt:message key="label.firstName"/></td>
    <td><input type="text" name="firstName" value="${requestScope.User.firstName}"></input></td>
 </tr>
 <tr>
<td>&nbsp;</td>
</tr>
 <tr>
<td><fmt:message key="label.lastName"/></td>
<td><input type="text" name="lastName" value="${requestScope.User.lastName}"></input></td>
 </tr>
 <tr>
<td>&nbsp;</td>
 </tr>
 <tr>
<td><font color="#FF0000"><b>*</b></font>&nbsp;<fmt:message key="label.email"/></td>
<td><input type="text" name="email" value="${requestScope.User.email}"></input>     </td>
</tr>
 <tr>
<td>&nbsp;</td>
</tr>
<tr align="center">
 <td colspan="2">
    <input type="submit"/>
    &nbsp;
  <a href="<c:out value='${requestScope.resetRenderUrl}'/>">
    <b><fmt:message key="label.reset"/></b>
  </a>
</td>
</tr>

这是我的bean类

public class User implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = -5729328658617182010L;
private String firstName;
private String lastName;
private String email;

public User(String firstName,String lastName,String email){

    super();
    this.firstName = firstName;
    this.lastName = lastName;
    this.email = email;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

这是我正在捕捉价值的portlet

@ProcessAction(name = "registerUserAction")
public void registerUser(ActionRequest request, ActionResponse response)
        throws PortletException, IOException {
    String email = request.getParameter("email");
    System.out.println("Email :"+email +","+request.getParameter("firstName"));
    // --set the information entered by the user on the registration

但我的电子邮件和firstName都是空的。有人请帮忙

1 个答案:

答案 0 :(得分:1)

与Liferay 6.2相关的答案

默认情况下,Liferay 6.2要求给定portlet的请求参数以portlet名称空间为前缀。在纯HTML中,您需要使用<portlet:namespace/>标记明确指定每个请求参数/表单字段的命名空间:

<input type="text" name="<portlet:namespace/>firstName" value="${requestScope.User.firstName}">

不要忘记所需的TLD导入:

<%@taglib prefix="portlet" uri="http://java.sun.com/portlet" %>

只有命名空间参数对portlet可见(通过标准portlet API)。