3 Replies Latest reply on May 4, 2009 10:36 AM by peterj

    How to get started?? Which jars for needed for simple portle

    nadley

      Hello everyone,

      I need to develop a JBoss Portlet for university and by now I'm nearly going crazy!!!

      My installation: Portal 2.6.8, I downloaded the the JBoss bundle ("jboss-portal-2.6.8.GA-bundled.zip"). Eclipse Ganymede with JBoss Tools installed.

      The portlet I want to run contains a jsp files and the error message I receive is the following:

      ...
      Cause: javax.portlet.PortletException: org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 18 in the jsp file: /WEB-INF/jsp/SuperBrain.jsp portletSession cannot be resolved
      ...
      


      I included all necessary jars and libs in build path, so that Eclipse can resolve everything.

      Do I need additional jars in WEB-INF? If yes, which?? As soon as I tried to include jars like "portal-api.jar" my portlet did not display at all.

      What do I have to do???

      Thanks!

        • 1. Re: How to get started?? Which jars for needed for simple po
          peterj

          Sounds like your JSP is attempting to make use of a variable name portletSession, but such a variable was never declared. Could you post the JSP? When posting the JSP, enclose it in 'code' tags. To do this, select the JSP text and click the Code button above the forum's editor window, And use the Preview button to check the formatting before submitting.

          • 2. Re: How to get started?? Which jars for needed for simple po
            nadley

            Well, you're right - I never declared that variable because I thought it should be available for every portlet. Isn't it possible to include a certain jar so that I can access "portletSession"? I've seen "portletSession" in various sample codes...

            Here is my JSP:

            <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
            
            <portlet:defineObjects/>
            
            <div align="center">
            <%!
             java.util.Random random = new java.util.Random();
             int toGuess;
             int guessedNumber;
             long start;
             long end;
             long minuten;
             long sekunden;
            %>
            <%
             String value = renderRequest.getParameter("guessedNumber");
            
             java.util.List <String> list = (java.util.List <String>)portletSession.getAttribute("bereitsGeraten");
             if (portletSession.getAttribute("toGuess")!=null){
             toGuess = (Integer) portletSession.getAttribute("toGuess");
             }else {
             toGuess = random.nextInt(1000);
             }
             if (value != null){
             if (value.equals("neustart")){
             list = new java.util.ArrayList <String> ();
             guessedNumber = -1;
             toGuess = random.nextInt(1000);
             }
             else {
             if (list == null){
             list = new java.util.ArrayList<String>();
             }
             list.add(value);
             try {
             guessedNumber = Integer.parseInt(value);
             }catch (Exception e){
             out.print("Fehler beim Lesen der eingegebenen Zahl!");
             }
             }
             }
            
             portletSession.setAttribute("bereitsGeraten",list);
             portletSession.setAttribute("toGuess",toGuess);
            %>
            <form action="<portlet:actionURL><portlet:param name="page" value="mainview"/></portlet:actionURL>" method="POST">
            
            <% if (guessedNumber == toGuess){
             end = new java.util.Date().getTime();
             minuten = (end-start)/(60*1000);
             sekunden = ((end-start)%(60*1000))/ 1000;
            %>
             Super! Das war die gesuchte Zahl!!! <br>
             Sie haben das Ergebnis in <%=minuten%> Minuten und <%=sekunden%>
             Sekunden beim <%= list.size()%>. Versuch gefunden! <br>
             <input type=hidden name=guessedNumber value="neustart">
             <input type=submit value=Neustart>
            <% }else {
             if ((value == null)||(value.equals("neustart"))) {
             start = new java.util.Date().getTime();%>
             Hallo! <br> Bitte eine Zahl zwischen 0 und 1000 erraten!
            <% } else if (guessedNumber > toGuess) { %>
             Die zu erratende Zahl ist kleiner! Noch ein Versuch:
             <% } else if (guessedNumber < toGuess) { %>
             Die zu erratende Zahl ist größer! Noch ein Versuch:
             <% } %>
             <br>
             <input type="text" name="guessedNumber">
             <input type="submit" value="raten">
             <br><br>
             Bereits geratene Zahlen: <%=list %>
             <%} %>
            
            </form>
            </div>
            


            It's a little game to guess a random number and it worked fine as a jsp-only application.

            • 3. Re: How to get started?? Which jars for needed for simple po
              peterj

              You get portletRequest and porltetResponse for free because they are the parameters for the method that will contain the JSP code. For the session, you will have to do:

              PortletSession portletSession = portletRequest.getPorltetSession();