10 Replies Latest reply on Aug 13, 2010 12:18 AM by trong.tran

    How can I change the title of my portal page in the portlet?

    jhakyblue

      hi:

       

      I have a problem, I've implemented a portlet, I want to change the title of my portal page with a dynamic title generate in the portlet .I think i can do that in doHeaders of my jsp portlets but i don't have any idea how can i do. please help me.

        • 1. Re: How can I change the title of my portal page in the portlet?
          antoine_h

          first thing to say : this is a strange way to use the page.

          a page of a portal is supposed to be the same for all the users.

          so : if it is changed dinamicaly, and this is specific for each user, then, it won't be possible.

           

          may be using the dashboard : the user can build it's own page of dashboard... hence have it work "only for him".

          or you can have it built for him (by code).

          I have seen a project trying to use the dashboard like this... but it is a lot of work... and messy and a lot of complications.

           

          may be try another way to show the dynamical information you want to show ?

           

          like in some kind of "head part of the portlet content", which shall show these informations.

           

          or in the page, build it with two portlets : one for the general dynamic info, the second with your portlet.

          and have the portlets communicates, so the first one receive the info to show.

          this way is not very easy to do too (communication between portets...).

           

          globally, in a portal, each portlet is supposed to run and do it's job "autonomously", by itself.

           

          hope it helps,

          Antoine
          JBoss Portal and GateIn (JSR-286), JSF, Richfaces, J2EE, Drools, BRMS.
          http://www.sysemo.com/Sysemo-expertise-portails-jboss-portal.php

          • 2. Re: How can I change the title of my portal page in the portlet?
            jhakyblue

            Hi antoine

             

            First one thanks for your answer and the information. I want to explain you why i want to change the title depends of the information that the portal page shows because i wanna use SEO(Search engine optimization) for my portal page. If you know how to do this, you send me a message

             

            thanks

            Jhaky

            • 3. Re: How can I change the title of my portal page in the portlet?
              hoang_to

              If you look at the template UIPortalApplication.gtmpl, you could see that your portal page 's title is actually UIPage/Page 's title.

               

              Hence, the only way to obtain your objective is to reset title of UIPage 's object.

              • 4. Re: How can I change the title of my portal page in the portlet?
                trong.tran

                the "Setting Markup Head Elements" feature in JSR 286 would help you to add/set page headers and the title header is no exception. It means you could do something like following in your portlet's rendering

                 

                Java code :

                      Element element = response.createElement("title");
                      element.setTextContent("This is new title");
                      response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, element);
                
                1 of 1 people found this helpful
                • 5. Re: How can I change the title of my portal page in the portlet?
                  jhakyblue

                  Hi Trong

                  I put this java code into doHedears methods but doesn't work, Maybe I have to change or add something in the UIPortalApplication.gtmpl.

                  is that true?

                  • 6. Re: How can I change the title of my portal page in the portlet?
                    trong.tran

                    No, you do not need to change anything in the UIPortalApplication.gtmpl

                     

                    It works for me and you can refer to the attached sample portlet SettingMarkupHeadElementPortlet.java.

                     

                    Note : in GateIn 3.1, the Setting Markup Head Elements feature does not work in an ajax request and this problem will be fixed by https://jira.jboss.org/browse/GTNPORTAL-1256

                    1 of 1 people found this helpful
                    • 7. Re: How can I change the title of my portal page in the portlet?
                      jhakyblue

                      Hi Trong

                       

                      I execute your code in my portlet and it works , i can change the title in my portal page. now I need to use processAction in the edit mode but i can't do that because in your doEdit method the w.write function only use html or is there another way to insert java code in w.write?

                      then i tried that:

                      public void doEdit(RenderRequest request, RenderResponse response)
                          throws PortletException, IOException {
                      
                                  ArrayList<InicialBean> categorias = consultarCategorias();
                                  request.setAttribute("categorias", categorias);
                                  
                                  String idCategoria = getPreferencia("ID_CATEGORIA", request, response);
                                  request.setAttribute("pref_categoria", idCategoria);
                                  
                                  response.setContentType("text/html");
                                  PortletRequestDispatcher prd = getPortletContext()
                                          .getRequestDispatcher("/jsp/edit.jsp");
                                  prd.include(request, response);
                              }
                      
                      
                      

                       

                      and i call edit.jsp

                       

                      <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
                      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
                      <portlet:defineObjects /> 
                      <portlet:actionURL    var="myActionURL" />
                      <div>
                          <div align="center">
                              <form action="<%=myActionURL%>" method="POST">
                                  
                                  <table>    
                                      <tr>
                                          <td><div>Categoria: </div></td>
                                          <td><div>
                                                  <select id="cat" name="cat" value="${pref_categoria}">
                                                      <c:forEach var="cat" items="${categorias}">
                                                          <option value="${cat.id}">${cat.name}</option>
                                                      </c:forEach>
                                                  </select>
                                              </div>
                                          </td>
                                      </tr>
                                  
                                      <tr>
                                          <td colspan="2" align="center"><div><input type="submit" value="save" /></div></td>
                                      </tr>
                                  </table>
                              </form>
                          </div>
                      </div>
                      

                       

                      But i don't know why the portlet doesn't show the edit mode (edit.jsp).

                       

                      After I noticed this occurs when I import the servlet-api library (servlet-api.jar). I need this library because when I try to call the response.addProperty method, the next error appears: "The type javax.servlet.http.Cookie cannot be resolved. It is indirectly referenced from required .class files"

                       

                       

                      import org.w3c.dom.Element;
                      import javax.portlet.MimeResponse;
                      //...
                      public void doHeaders(RenderRequest request, RenderResponse response){
                           Element element = response.createElement("title");
                                  element.setTextContent(titulo);
                                  response.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, "any title");
                      }
                      

                       

                       

                      the log doesn't show me any warnings or errors.

                       

                      Thanks for your answer.

                      • 8. Re: How can I change the title of my portal page in the portlet?
                        trong.tran

                        Hi,

                        now I need to use processAction in the edit mode but i can't do that  because in your doEdit method the w.write function only use html or is  there another way to insert java code in w.write?

                        I'm not sure to understand what you mean. However, absolutely you are able to use the PortletRequestDispatcher.include() with a jsp file BUT just ensure the syntax of your jsp file is valid. Apparently the following code snippet seems not to be correct in JSP's syntax :


                                                    <select id="cat" name="cat" value="${pref_categoria}">
                                                        <c:forEach var="cat" items="${categorias}">
                                                            <option value="${cat.id}">${cat.name}</option>
                                                        </c:forEach>
                                                    </select>

                         

                        BTW, You may want to have a look in a simple JSP portlet http://anonsvn.jboss.org/repos/gatein/portal/tags/3.1.0-GA/examples/portlets/jsphellouser/

                        After I noticed this occurs when I import the servlet-api library  (servlet-api.jar). I need this library because when I try to call the  response.addProperty method, the next error appears: "The type  javax.servlet.http.Cookie cannot be resolved. It is indirectly  referenced from required .class files"

                        Yes, it should be imported indeed

                        • 9. Re: How can I change the title of my portal page in the portlet?
                          jhakyblue

                          Hi

                          I use JSTL and EL in jsp syntax for generation  of code . But I did a test and I wrote only html code in my jsp file but the edit mode didn't show it:

                           

                          edit.jsp:

                          <H1>Hello edit mode</H1>
                          <p>I should see this message</p>
                          

                           

                          this code doesn't appear in edit mode. only appear when i remove the servlet-api.jar, but if i do that i can not use response.addProperty method.

                          For view mode and help mode is the same problem, only show the message when I put w.write into doEdit with the message like this :

                           

                           

                          public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException {
                                  
                              response.setContentType("text/html");
                              PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/jsp/edit.jsp");
                              prd.include(request, response);
                          
                              PrintWriter w = response.getWriter();
                              w.write("<div class=\"portlet-section-header\">Hello doView method</div>");
                          }
                          

                           

                          thanks for your help

                          • 10. Re: How can I change the title of my portal page in the portlet?
                            trong.tran

                            Hi,

                            this code doesn't appear in edit mode. only appear when i remove the  servlet-api.jar, but if i do that i can not use response.addProperty  method.

                            Notice that you should only use servlet-api.jar for building (compiling) time but do not inlude it in the portlet war package. If you are using maven to build up your project, the servlet-api dependency could be in provided scope like following :

                             

                                  <dependency>
                                     <groupId>javax.servlet</groupId>
                                     <artifactId>servlet-api</artifactId>
                                     <scope>provided</scope>
                                  </dependency>
                            
                            
                            

                             

                            In addition, the old version of the servlet api could be a problem in the case too.