1
votes

I am using Liferay as platform.I have created drop down list with 2 values (true/false ("false" is selected by default)) once I click on update button , it should be updated in preferences field (i.e drop down list). I am using below code but its giving null value. I am not able to read/get selected drop down value from EditPreferences.jsp to EditController.java. If its possible to render value from Editpreferences.jsp to EditConytroller Class then That should be fine for me. thank you for any kind of suggestion.

This is my code in EditPreferences.jsp

<portlet:defineObjects />
<script type="text/javascript" src="js/jquery.js"></script>
<%@page import="javax.portlet.PortletPreferences" %>
<%
    PortletPreferences pref = renderRequest.getPreferences();

    String IsCollege = pref.getValue("IsCollege","");
    Locale locale = renderRequest.getLocale();
    ResourceBundle bundle = portletConfig.getResourceBundle(locale);
    String updated = (String) request.getAttribute ("preferences-updated");
    if (updated != null && updated.equals ("true")) {

%>

  <div class="portlet-msg-info">
    <liferay-ui:message key="preferences-update-successful" />
  </div>
 <% 
 } 
 %>

  <portlet:actionURL var="actionOneMethodURL">

     <portlet:param name="action" value="actionOne"></portlet:param>

 </portlet:actionURL>

<form  method="POST" action="${actionOneMethodURL}" >
 <tr>
    <td>
        IsCollege:
    </td>

      <td>
        <select id="IsCollege">
            <option value="false" selected="selected">False</option>
            <option value="true">True</option>
       </select>
     </td>
    </tr>
    <tr>
        <td colspan=2>
        <input type="submit" id="updateBtn" value="Update">
        </td>
    </tr>
 </form>

EditController.java

 @ActionMapping(params = "action=actionOne")
  public void setPublisherPref(ActionRequest request, ActionResponse response)
        throws Exception {
    PortletPreferences pref = request.getPreferences();

   String IsCollege = ParamUtil.getString(request, "IsCollege", "");
   pref.setValue("IsCollege", IsCollege);
   pref.store();

    request.setAttribute("preferences-updated", "true");

}
1
You have not provided 'name' attribute to select tag, that why you are not getting selected value in controller. e.g. <select name="IsCollege">Pankaj Kathiriya
Don't forget portlet namespace, e.g. <select name="<portlet:namespace/>IsCollege">.Tomas Pinos
@PankajKathiriya and Tomas.. Thanks to both.. It worked now..user3534759
Please, can anyone answer where it is supposed to be answered? ThanksPrakash K
The answer provided. Thanks.Tomas Pinos

1 Answers

1
votes

The select tag is missing name attribute. The id, which is specified, doesn't affect parameter binding. Moreover, the name must be prefixed with portlet namespace.

<select name="<portlet:namespace/>IsCollege">

Instead of rendering the complete HTML manually, next time you may want to use aui or liferay-ui taglibs.