|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Nov 2004
Messaggi: 409
|
[JAVA]: portlet
Ciao,
ho creato una portlet con una preferenza dichiarata all'interno del file portlet.xml e l'ho deployato senza problemi all'interno di JBoss Portlet Container. Il file xml per questa portlet è il seguente: Codice:
<portlet> <description>PreferencesPortlet</description> <portlet-name>PreferencesPortlet</portlet-name> <display-name>PreferencesPortlet</display-name> <portlet-class>it.portlet.PreferencesPortlet</portlet-class> <expiration-cache>0</expiration-cache> <supports> <mime-type>text/html</mime-type> <portlet-mode>VIEW</portlet-mode> <portlet-mode>EDIT</portlet-mode> </supports> <portlet-preferences> <preference> <name>userName</name> <value>Mark</value> <read-only>false</read-only> </preference> <preferences-validator>it.validator.UserNameValidator</preferences-validator> </portlet-preferences> <portlet-info> <title>Portlet Preferences</title> <short-title>PreferencesPortlet</short-title> </portlet-info> </portlet> Per quale motivo non riesco a impostare il valore della preferenza a runtime? Di seguito ci sono gli altri sorgenti: Codice:
public class PreferencesPortlet extends GenericPortlet {
public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("*************************************************** doView");
response.setContentType("text/html");
String userName =(String)request.getPreferences().getValue("userName",null);
if (userName != null)
response.getWriter().println("Hello " + userName);
else
response.getWriter().println("Vai nell'edit mode per modificare l'username");
}
public void processAction( ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException, IOException {
System.out.println("*************************************************** processAction");
String userName = actionRequest.getParameter ("userName");
System.out.println("*************************************************** username="+userName);
PortletPreferences pref = actionRequest.getPreferences();
pref.setValue("userName",userName);
try{
pref.store();
System.out.println("*************************************************** store");
}catch (Exception e) {
e.printStackTrace();
}
actionResponse.setPortletMode(PortletMode.VIEW);
}
@Override
protected void doEdit(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
System.out.println("*************************************************** doEdit");
response.setContentType("text/html");
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/edit_userName.jsp");
dispatcher.include(request, response);
}
}
Codice:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<portlet:defineObjects/>
<h3>Edit User Name</h3>
<form method="post" action="<portlet:actionURL/>">
Username: <input type="text" name="userName" >
<input type="submit"> <input type="reset">
</form>
</body>
</html>
ciao e grazie in anticipo
__________________
HU Queen Member |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2004
Messaggi: 409
|
up
__________________
HU Queen Member |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 16:46.



















