簡體   English   中英

如何從一個JSP的下拉列表中獲取選定值到Liferay Portlet參考中的Java控制器類

[英]How to get selected value from drop down list in one jsp to java controller class in liferay portlet references

我使用Liferay作為平台。我創建了帶有2個值的下拉列表(true / false(默認情況下為“ false”),單擊更新按鈕后,應該在首選項字段(即下拉列表)中對其進行更新。 。 我正在使用下面的代碼,但其值為空。 我無法讀取/獲取從EditPreferences.jsp到EditController.java的選定下拉值。 如果有可能將值從Editpreferences.jsp呈現到EditConytroller類,那么對我來說應該沒問題。 謝謝您的任何建議。

這是我在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");

}

選擇標記缺少名稱屬性。 指定的id不會影響參數綁定。 此外,該名稱必須以portlet名稱空間為前綴。

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

下次您可能不想使用人工呈現完整的HTML,而是想使用aui或liferay-ui標簽庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM