0

In the following code snippet there is the isRowInDueCauseTable method (which in another class works properly) returns a boolean value. But using it in a JSP file, it always gives back true, altough it should change the isRowInDB variable accordingly. But it's always true, so isRowExists method always gets true as parameter. It seems like it only runs for the first time, and never evaluates again

if ( sAction == "newRow" ) {
            <%
            tblMgrHome = (TableManagerHome)pageEnv.get("ejb/TableManager");
            tblMgr = tblMgrHome.create();
            boolean isRowInDB = tblMgr.isRowInDueCauseTable(
                request.getParameter("REASON"),
                request.getParameter("TASK"),
                request.getParameter("RESULT"),
                request.getParameter("RESULT_CAUSE")
                );
                %>
            console.log("HERE IS THE BOOLEAN: " + <%=isRowInDB%>);
            isRowExists(<%=isRowInDB%>);
            setMenuClick(false);
        }

And I'm sure that it can also give back false, because that part of the application work. What is wrong with it?

dmbdnr
  • 334
  • 3
  • 19
  • What's wrong with this? It seems to me that this code is evaluated when the page loads the first time, so it is called only the first time. If then your java code changes that value, it won't reflect to the page dynamically alone – quirimmo May 18 '17 at 13:09
  • I want this to be evaluated every time a button is clicked, that's when the javascript method which contains this snippet gets invoked – dmbdnr May 18 '17 at 13:12
  • It's a lot I don't use JSP but from my memory JSP is executed once the page loads, then it is not executed anymore. Try to do a simpler example and put just one counter incremented by Java inside that method. Then console log that value. Can you see the counter progresses? or do you see always the starting value? – quirimmo May 18 '17 at 13:18
  • it'll be the same value, checked already – dmbdnr May 18 '17 at 13:21
  • So my memories are fine. This is not how JSP works. You have to implement an AJAX call when you click on the button and get that value from the AJAX request. – quirimmo May 18 '17 at 13:24
  • and can you provide any example, how to do it? – dmbdnr May 18 '17 at 13:27
  • here you go: http://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax Please let me know if it works fine for you – quirimmo May 18 '17 at 13:28

1 Answers1

0

this is jsp code this will evaluate only one time while making the html to be displayed on the browser. Make an api for this isRowInDueCauseTable and use ajax to check it again and again from browser.