-
1. Re: getPreferences with JSF portlet
franco12 Oct 16, 2006 8:33 AM (in response to franco12)I forgot to say
thanks ^^
regards -
2. Re: getPreferences with JSF portlet
franco12 Oct 16, 2006 8:44 AM (in response to franco12)The problem is that the program won't pass through 'doView'
MDP_contribution_consultation.javaimport javax.portlet.PortletPreferences; import javax.portlet.PortletSecurityException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.PortletException; import java.io.IOException; public class MDP_contribution_consultation { String consulter="ok"; String supprimer; private String init="false"; protected void doView(RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException { response.setContentType("text/html"); // StringBuffer html = new StringBuffer(); // PrintWriter writer = response.getWriter(); PortletPreferences prefs = request.getPreferences(); String parameter = prefs.getValue("suppression_pref",init); if (parameter.equals("true")) { this.supprimer="ok"; // html.append("<-- Contribution --><br/>"); // html.append("<img src='/WEB-INF/images/logo.gif'/>"); } else { this.supprimer="pas ok"; // html.append("<-- Consultation --><br/>"); } // response.getWriter().write(html.toString()); // writer.close(); } public String getConsulter() { return consulter; } public void setConsulter(String consulter) { this.consulter = consulter; } public String getSupprimer() { return supprimer; } public void setSupprimer(String supprimer) { this.supprimer = supprimer; } }
view.jsp<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <f:view> <div align="center"> <h:panelGrid columns="3"> <h:outputText value="NOM FICHE"/> <h:outputText value="CONSULTER"/> <h:outputText value="SUPPRIMER"/> <h:outputText value="fiche 1"/> <h:outputText value="#{MDP_contribution_consultation.consulter}"/> <h:outputText value="#{MDP_contribution_consultation.supprimer}"/> <h:outputText value="fiche 2"/> <h:outputText value="#{MDP_contribution_consultation.consulter}"/> <h:outputText value="#{MDP_contribution_consultation.supprimer}"/> <h:outputText value="fiche 3"/> <h:outputText value="#{MDP_contribution_consultation.consulter}"/> <h:outputText value="#{MDP_contribution_consultation.supprimer}"/> </h:panelGrid> <br/> </div> </f:view>
sorry for the multiple posts
regards -
3. Re: getPreferences with JSF portlet
theute Oct 16, 2006 9:13 AM (in response to franco12)It doesn't look like a portlet to me, you are not extending GenericPortlet or anything else.
-
4. Re: getPreferences with JSF portlet
franco12 Oct 16, 2006 9:23 AM (in response to franco12)"thomas.heute@jboss.com" wrote:
It doesn't look like a portlet to me, you are not extending GenericPortlet or anything else.
sorry I'm a noob,
what have I to do except adding "extends GenericPortlet" ?
Because now, I've having this errorObject not found mdpApp.MDP_contribution_consultation
thanks -
5. Re: getPreferences with JSF portlet
theute Oct 16, 2006 9:27 AM (in response to franco12)It looks like you didn't specify your XML descriptors correctly.
You should start from the HelloWorld portlet and extend it step by step:
http://labs.jboss.com/portal/portletswap/portlets_tutorial.html -
6. Re: getPreferences with JSF portlet
franco12 Oct 16, 2006 9:42 AM (in response to franco12)"thomas.heute@jboss.com" wrote:
It looks like you didn't specify your XML descriptors correctly.
You should start from the HelloWorld portlet and extend it step by step:
http://labs.jboss.com/portal/portletswap/portlets_tutorial.html
hu sorry,
I had to refresh anoter time
it's working without error
but the program won't pass through doView
i'd like to set supprimer="ok" if my parameter suppression_pref="true"
or supprimer="pas ok" if suppression_pref="false"
and then I display supprimer in my JSP<h:outputText value="#{MDP_contribution_consultation.supprimer}"/>
thanks for your quick replies -
7. Re: getPreferences with JSF portlet
theute Oct 16, 2006 10:15 AM (in response to franco12)Oups sorry i replied too quickly i missed that you were working on a JSF portlet.
On a JSF portlet you don't need to extend GenericPortlet and render() won't be called.
You need to pass a JSF page as parameter in portlet.xml in getSupprimer() you should access the preferences like this:public String getSupprimer() { PortletPreferences prefs = request.getPreferences(); String parameter = prefs.getValue("suppression_pref",init); if (parameter.equals("true)) { return "ok"; } else { return "pas ok"; } }
-
8. Re: getPreferences with JSF portlet
franco12 Oct 16, 2006 10:57 AM (in response to franco12)ok thanks for your help Thomas :)
I removed "extends GenericPortlet" and the doView method
and I updated getSupprimer() like thisimport javax.portlet.PortletPreferences; import javax.portlet.PortletSecurityException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.PortletException; import java.io.IOException; public class MDP_contribution_consultation { String consulter="ok"; String supprimer; private String init="false"; public String getConsulter() { return consulter; } public void setConsulter(String consulter) { this.consulter = consulter; } public String getSupprimer(RenderRequest request, RenderResponse response) throws PortletException, PortletSecurityException, IOException { PortletPreferences prefs = request.getPreferences(); String parameter = prefs.getValue("edit",init); if (parameter.equals("true")) { return "ok"; } else { return "pas ok"; } } public void setSupprimer(String supprimer) { this.supprimer = supprimer; } }
now I'm having this error
An error occured while rendering window 'default.MaPage.contrib' org.apache.jasper.JasperException: Bean: MDP_contribution_consultation, property: supprimer
my portlet.xml has a jsp page as an init parameter, like this<portlet-app version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet" xmlns="http://java.sun.com/xml/ns/portlet"> <portlet> <portlet-name>MDP_contribution_consultation</portlet-name> <portlet-class>org.apache.myfaces.portlet.MyFacesGenericPortlet</portlet-class> <portlet-info> <title>MDP_contribution_consultation</title> </portlet-info> <init-param> <name>default-view</name> <value>/WEB-INF/jsp/view.jsp</value> </init-param> <init-param> <name>suppression_init</name> <value>false</value> </init-param> <portlet-preferences> <preference> <name>edit</name> <value>true</value> </preference> </portlet-preferences> <supports> <mime-type>text/html</mime-type> <portlet-mode>VIEW</portlet-mode> </supports> </portlet> </portlet-app>
regards -
9. Re: getPreferences with JSF portlet
theute Oct 16, 2006 11:06 AM (in response to franco12)getSupprimer should have no parameter.
You can get the request from FacesContext.getExternalContext.getRequest(); -
10. Re: getPreferences with JSF portlet
franco12 Oct 16, 2006 11:25 AM (in response to franco12)did you mean
PortletPreferences prefs = FacesContextWrapper.getExternalContext.getRequest().getPreferences();
or
PortletPreferences prefs = FacesContextFactoryImpl.getExternalContext.getRequest().getPreferences();
FacesContext cannot be resolved
FacesContextWrapper or FacesContextFactoryImpl can't be resolved ("It is indirectly referenced from required .class files") -
11. Re: getPreferences with JSF portlet
theute Oct 16, 2006 11:36 AM (in response to franco12)I need to wake up...
I meant:
FacesContext.getCurrentInstance().getExternalContext().getRequest()
Then you can cast it to a PortletRequest.
FacesContext is part of the JSF public API.
http://java.sun.com/javaee/javaserverfaces/1.0/docs/api/javax/faces/context/FacesContext.html -
12. Re: getPreferences with JSF portlet
franco12 Oct 16, 2006 1:58 PM (in response to franco12)sorry I don't get it :-s
FacesContext doesn't work alone
eclipse suggests me FacesContextWrapper or FacesContextFactoryImpl but not FacesContext alone -
13. Re: getPreferences with JSF portlet
theute Oct 16, 2006 3:54 PM (in response to franco12)Add the JSF API to Eclipse classpath then...
-
14. Re: getPreferences with JSF portlet
franco12 Oct 16, 2006 5:03 PM (in response to franco12)ok :)
first of all I'd like to say thank you for bearing with the n00b I am
ok now eclipse is ok with FacesContext
but now i'm facing to the 'cast' problem
by "casting to a PortletRequest", did you mean :
PortletRequest prefs = FacesContext.getCurrentInstance().getExternalContext().getRequest();
?
thanks