Topic
  • 7 replies
  • Latest Post - ‏2013-06-11T16:44:25Z by rnassif
Chips
Chips
13 Posts

Pinned topic How to check Submit Action in Cognos Portlet using JSP

‏2013-06-03T08:24:38Z |

Dear all,

I am using JSP to build up a portlet for the Cognos Extended Application. My portlet is a form that user can input data and submit to insert data into database.

My problem is when i using under Cognos Portal, the portlet always store the POST Parameter. Every time i load the portal page, the jsp will detect the post value and insert into Database.

How can i check the portlet is refresh or submit by form? If anyone has any idea, please tell me, because, there is too little information in SDK. I really need some help.

Thanks and Thank a lot !!

  • rnassif
    rnassif
    5 Posts
    ACCEPTED ANSWER

    Re: How to check Submit Action in Cognos Portlet using JSP

    ‏2013-06-11T16:44:25Z  
    • Chips
    • ‏2013-06-11T01:47:22Z

    Dear Rnassif,

    Thanks for your reply!!!

    Actually, i have try both 

    session.setAttribute("valueAdded", "yes") ;

    request.getSession().setAttribute("valueAdded", "yes")

    I add this code just after insert the record, when i refresh the page, the value is "Yes", the checking is ok, the record will not insert again.

    But when i input a new value and click the insert button again (just after refresh the page), the session value still contain the "Yes", So the checking still happen, the record cannot be insert. That is the problem when i use session for my checking.

    Is it normal? Or just because i have missing something in my code?

     

    And, i have another question, should i use another jsp or servlet and let the submit action send to other jsp (Include the CreateURI as a hiddend value for redirect url ), and redirect back to the portlet page after insert the record?

    When i redirect back to portlet page, the login screen is show, is it normal? I just get a try, hope you can give me some advise.

    Thanks and Thanks a lot !!

     

    Instead of simply setting a value of "yes" in the session, maybe you should maintain the list of items that you already added in that session so you don't add them again.

    Also, what happens if a second user uses this application at the same time and tries to add a value that you already added ? I'm not sure what you are trying to do, but you might want to handle this scenario.

     

    As for the other question, you can use another jsp or servlet to handle the database insert, but you can't call it using the CreateURI and a form submit. Instead you can call it using XMLHttpRequest in javascript (as long as the host of the jsp is the same as the host of the page where you application is displayed).

  • rnassif
    rnassif
    5 Posts

    Re: How to check Submit Action in Cognos Portlet using JSP

    ‏2013-06-04T18:23:55Z  

    Is it possible to provide the jsp that you're using so we can have a better idea of what's happening ?

  • Chips
    Chips
    13 Posts

    Re: How to check Submit Action in Cognos Portlet using JSP

    ‏2013-06-05T05:07:29Z  
    • rnassif
    • ‏2013-06-04T18:23:55Z

    Is it possible to provide the jsp that you're using so we can have a better idea of what's happening ?

    Thanks for your reply, My jsp code is attached below

    The value in "test1" always has value. when i refresh the page the test1 also contain a value.

     

    <%@ taglib uri="/WEB-INF/tld/cps.tld" prefix="cps"%>
     
    <%@ page import ="java.lang.Double"%>
    ...
    <%@ page import ="com.cognos.developer.schemas.bibus._3.*"%>
    <cps:IBMCognosConnect id = "cognos"/>
     
    <% request.setCharacterEncoding("UTF-8"); %>
    <% response.setContentType("text/html; charset=utf-8"); %>
    <% response.setHeader("Pragma", "No-cache"); %>
    <% response.setHeader("Cache-Control", "no-cache"); %>
    <% response.setDateHeader("Expires", 1);%>
    <%
    /* 
    Only Collect form Data by Submit, No Refesh page!
    */
    if ("POST".equalsIgnoreCase(request.getMethod())) {  // 
     
    String test1   = request.getParameter( "test1" );
    if ( test1 == null ) {
    test1 = "";
    }

    try {

    Class.forName("XXXX");

    Connection  conn = DriverManager.getConnection( "XXX", "XXX", "XXX");

    Statement stmt = conn.createStatement ();
    double ex_rate = 1;

    stmt = conn.createStatement ();

    String query_insert = "insert into testing_tbl  values ( " +test1+" ) ";

    out.println (query_insert);

    stmt.execute(query_insert);
    conn.commit();
    stmt.close();
    conn.close();
    } catch (java.sql.SQLException e) {
    out.println("There was an error doing the query:"+e );
    }
    } // End of if ("POST".equalsIgnoreCase(request.getMethod())) { 
     
    %>
    <link rel="stylesheet" href="<%=url%>/css/jquery-ui.css" />
    <script src="<%=url%>/css/jquery-1.9.1.js"></script>
    <script src="<%=url%>/css/jquery-ui.js"></script>
    <link rel="stylesheet" href="<%=url%>/css/style.css" />
    <script>
    function checkInput()
    {
    var x=document.forms["form1"]["test1"].value;
    if (x==null || x=="" || x == 0 )
    {
     alert("Please input value!");
     return false;
    }
     
    document.forms["form1"].submit();
    }
     
    </script>
    <body>
    <table border=0>
    <tr>
    <td valign="top">
    <p><b>Test insert Record</b>
    <form action="<cps:CreateURI/>" method="post" name="form1">
    <table border=0>
    <tr>
    <td>test1 Value</td>
    <td><input size="25" name="test1" type="text" value=""></td>
    </tr>
    <tr>
    <td><input type="button" class="portlet-form-button" onclick="javascript:checkInput()" value="Insert"></td>
    <td></td>
    </tr>
    </table>
    </form>
     
    Updated on 2013-06-05T10:47:50Z at 2013-06-05T10:47:50Z by Chips
  • rnassif
    rnassif
    5 Posts

    Re: How to check Submit Action in Cognos Portlet using JSP

    ‏2013-06-05T14:07:33Z  
    • Chips
    • ‏2013-06-05T05:07:29Z

    Thanks for your reply, My jsp code is attached below

    The value in "test1" always has value. when i refresh the page the test1 also contain a value.

     

    <%@ taglib uri="/WEB-INF/tld/cps.tld" prefix="cps"%>
     
    <%@ page import ="java.lang.Double"%>
    ...
    <%@ page import ="com.cognos.developer.schemas.bibus._3.*"%>
    <cps:IBMCognosConnect id = "cognos"/>
     
    <% request.setCharacterEncoding("UTF-8"); %>
    <% response.setContentType("text/html; charset=utf-8"); %>
    <% response.setHeader("Pragma", "No-cache"); %>
    <% response.setHeader("Cache-Control", "no-cache"); %>
    <% response.setDateHeader("Expires", 1);%>
    <%
    /* 
    Only Collect form Data by Submit, No Refesh page!
    */
    if ("POST".equalsIgnoreCase(request.getMethod())) {  // 
     
    String test1   = request.getParameter( "test1" );
    if ( test1 == null ) {
    test1 = "";
    }

    try {

    Class.forName("XXXX");

    Connection  conn = DriverManager.getConnection( "XXX", "XXX", "XXX");

    Statement stmt = conn.createStatement ();
    double ex_rate = 1;

    stmt = conn.createStatement ();

    String query_insert = "insert into testing_tbl  values ( " +test1+" ) ";

    out.println (query_insert);

    stmt.execute(query_insert);
    conn.commit();
    stmt.close();
    conn.close();
    } catch (java.sql.SQLException e) {
    out.println("There was an error doing the query:"+e );
    }
    } // End of if ("POST".equalsIgnoreCase(request.getMethod())) { 
     
    %>
    <link rel="stylesheet" href="<%=url%>/css/jquery-ui.css" />
    <script src="<%=url%>/css/jquery-1.9.1.js"></script>
    <script src="<%=url%>/css/jquery-ui.js"></script>
    <link rel="stylesheet" href="<%=url%>/css/style.css" />
    <script>
    function checkInput()
    {
    var x=document.forms["form1"]["test1"].value;
    if (x==null || x=="" || x == 0 )
    {
     alert("Please input value!");
     return false;
    }
     
    document.forms["form1"].submit();
    }
     
    </script>
    <body>
    <table border=0>
    <tr>
    <td valign="top">
    <p><b>Test insert Record</b>
    <form action="<cps:CreateURI/>" method="post" name="form1">
    <table border=0>
    <tr>
    <td>test1 Value</td>
    <td><input size="25" name="test1" type="text" value=""></td>
    </tr>
    <tr>
    <td><input type="button" class="portlet-form-button" onclick="javascript:checkInput()" value="Insert"></td>
    <td></td>
    </tr>
    </table>
    </form>
     

    The <cps:CreateURI/> tag that you using is designed to maintain all the parameters in the application navigational state. It is done this way so that when the page is refreshed, or when you leave the page and come back to it, the application will know its last state and react to it.

    Unfortunately, there is no current syntax that will only submit the parameter and not maintain it for subsequent requests.

    In your case, you are trying to update some database based on the parameter input. The parameter will always be there and you can't tell if it was added or not. One way to solve your problem, is to maintain some value in your jsp servlet session that indicates that you already inserted the value so you don't insert it again when the page is refresh or when you leave the page and come back to it. It is not an ideal solution, but it might be good enough to solve your situation.

    I hope this helps.

  • Chips
    Chips
    13 Posts

    Re: How to check Submit Action in Cognos Portlet using JSP

    ‏2013-06-06T02:39:45Z  
    • rnassif
    • ‏2013-06-05T14:07:33Z

    The <cps:CreateURI/> tag that you using is designed to maintain all the parameters in the application navigational state. It is done this way so that when the page is refreshed, or when you leave the page and come back to it, the application will know its last state and react to it.

    Unfortunately, there is no current syntax that will only submit the parameter and not maintain it for subsequent requests.

    In your case, you are trying to update some database based on the parameter input. The parameter will always be there and you can't tell if it was added or not. One way to solve your problem, is to maintain some value in your jsp servlet session that indicates that you already inserted the value so you don't insert it again when the page is refresh or when you leave the page and come back to it. It is not an ideal solution, but it might be good enough to solve your situation.

    I hope this helps.

    Thanks for your reply, actually, i have try to use 

    session.setAttribute("valueAdded", "yes") ;

    may be i don't know how to use this function, so i cannot perform a checking. 

    Can you explain more detail in set the vale in session? Because, i really need to solve this problem. 

    I am really really Thank for your reply and help. 

    Thanks and Thanks a lot!!!!

  • rnassif
    rnassif
    5 Posts

    Re: How to check Submit Action in Cognos Portlet using JSP

    ‏2013-06-10T14:27:08Z  
    • Chips
    • ‏2013-06-06T02:39:45Z

    Thanks for your reply, actually, i have try to use 

    session.setAttribute("valueAdded", "yes") ;

    may be i don't know how to use this function, so i cannot perform a checking. 

    Can you explain more detail in set the vale in session? Because, i really need to solve this problem. 

    I am really really Thank for your reply and help. 

    Thanks and Thanks a lot!!!!

    Can you should a snippet of your code. I tried your sample with something like the following and it works fine:

    request.getSession().setAttribute("valueAdded", "yes")

     

     

     

  • Chips
    Chips
    13 Posts

    Re: How to check Submit Action in Cognos Portlet using JSP

    ‏2013-06-11T01:47:22Z  
    • rnassif
    • ‏2013-06-10T14:27:08Z

    Can you should a snippet of your code. I tried your sample with something like the following and it works fine:

    request.getSession().setAttribute("valueAdded", "yes")

     

     

     

    Dear Rnassif,

    Thanks for your reply!!!

    Actually, i have try both 

    session.setAttribute("valueAdded", "yes") ;

    request.getSession().setAttribute("valueAdded", "yes")

    I add this code just after insert the record, when i refresh the page, the value is "Yes", the checking is ok, the record will not insert again.

    But when i input a new value and click the insert button again (just after refresh the page), the session value still contain the "Yes", So the checking still happen, the record cannot be insert. That is the problem when i use session for my checking.

    Is it normal? Or just because i have missing something in my code?

     

    And, i have another question, should i use another jsp or servlet and let the submit action send to other jsp (Include the CreateURI as a hiddend value for redirect url ), and redirect back to the portlet page after insert the record?

    When i redirect back to portlet page, the login screen is show, is it normal? I just get a try, hope you can give me some advise.

    Thanks and Thanks a lot !!

     

    Updated on 2013-06-11T01:53:26Z at 2013-06-11T01:53:26Z by Chips
  • rnassif
    rnassif
    5 Posts

    Re: How to check Submit Action in Cognos Portlet using JSP

    ‏2013-06-11T16:44:25Z  
    • Chips
    • ‏2013-06-11T01:47:22Z

    Dear Rnassif,

    Thanks for your reply!!!

    Actually, i have try both 

    session.setAttribute("valueAdded", "yes") ;

    request.getSession().setAttribute("valueAdded", "yes")

    I add this code just after insert the record, when i refresh the page, the value is "Yes", the checking is ok, the record will not insert again.

    But when i input a new value and click the insert button again (just after refresh the page), the session value still contain the "Yes", So the checking still happen, the record cannot be insert. That is the problem when i use session for my checking.

    Is it normal? Or just because i have missing something in my code?

     

    And, i have another question, should i use another jsp or servlet and let the submit action send to other jsp (Include the CreateURI as a hiddend value for redirect url ), and redirect back to the portlet page after insert the record?

    When i redirect back to portlet page, the login screen is show, is it normal? I just get a try, hope you can give me some advise.

    Thanks and Thanks a lot !!

     

    Instead of simply setting a value of "yes" in the session, maybe you should maintain the list of items that you already added in that session so you don't add them again.

    Also, what happens if a second user uses this application at the same time and tries to add a value that you already added ? I'm not sure what you are trying to do, but you might want to handle this scenario.

     

    As for the other question, you can use another jsp or servlet to handle the database insert, but you can't call it using the CreateURI and a form submit. Instead you can call it using XMLHttpRequest in javascript (as long as the host of the jsp is the same as the host of the page where you application is displayed).