<%@page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<jsp:useBean id="userName" class="java.lang.String" scope="request"></jsp:useBean>
<portlet:defineObjects />
日本語テスト
<br/>
Hello <%=userName%>.
edit.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <%@page contentType="text/html; charset=UTF-8" %> <jsp:useBean id="addNameUrl" class="java.lang.String" scope="request"></jsp:useBean> <jsp:useBean id="userName" class="java.lang.String" scope="request"></jsp:useBean> <portlet:defineObjects/> <form id="<portlet:namespace></portlet:namespace>/helloForm" action="<%=addNameUrl%>" method="post"> <table> <tr> <td>Name:</td> <td> <input type="text" name="username" value="<%=userName%>"/> </td> </tr> </table> <input type="submit" id="nameButton" title="Add NameT" value = "Add NameV" /> </form> 日本語ページテスト
HelloYouPortlet.java
package com.mytest; import java.io.IOException; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.GenericPortlet; import javax.portlet.PortletException; import javax.portlet.PortletMode; import javax.portlet.PortletPreferences; import javax.portlet.PortletRequestDispatcher; import javax.portlet.PortletURL; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class HelloYouPortlet extends GenericPortlet { private static Log _log = LogFactory.getLog(HelloYouPortlet.class); protected String editJSP; protected String viewJSP; @Override public void init() throws PortletException { // TODO Auto-generated method stub super.init(); editJSP = getInitParameter("edit-jsp"); viewJSP = getInitParameter("view-jsp"); } @Override public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException { GetContent1(request); response.setContentType("text/html"); PortletURL addName = response.createActionURL(); addName.setParameter("addName", "addname"); request.setAttribute("addNameUrl", addName.toString()); include(editJSP, request, response); } @Override public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { GetContent1(request); include(viewJSP, request, response); } private void GetContent1(RenderRequest request) { PortletPreferences prefs = request.getPreferences(); String username = prefs.getValue("name", "no"); if (username.equalsIgnoreCase("no")) { username = ""; } request.setAttribute("userName", username); } protected void include(String path, RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException { PortletRequestDispatcher portletRequestDispatcher = getPortletContext().getRequestDispatcher(path); if (portletRequestDispatcher == null) { _log.error(path + " is not a valid include."); } else { portletRequestDispatcher.include(renderRequest, renderResponse); } } @Override public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { String addName = request.getParameter("addName"); if (addName != null) { PortletPreferences prefs = request.getPreferences(); prefs.setValue("name", request.getParameter("username")); prefs.store(); response.setPortletMode(PortletMode.VIEW); } } }
0 件のコメント:
コメントを投稿