Use of request variables in query

Hi,

I need to be able to perform a query where a paramter for the query is a request variable to the jsp page.

The following is what I have been trying but it does not work. I’m guessing its because the JSP scope comes after the XApplication scope.

...
<xapp:module>

<form method="POST" action="view.jsp" name="form_view">
   <xapp:form document="CapabilityDocument">
   
      <input type="hidden" name="cap_id" value="<%= request.getParameter("cap_id")%>"/>

      <xapp:setvar name="whereFilterID" scope="session" value="${cap_id$}" default=" " />
	
      <xapp:setvar name="cap_query_by_id" >
          for $x in input()/Capability where $x/@id = "${whereFilterID$" return $x 
      </xapp:setvar>
                  
      <xapp:directcommand type="read" collection="${NMPCollection$}" document="CapabilityDocument" arg="${cap_query_by_id$}"/>

      
      <xapp:browse document="CapabilityDocument" pagesize="1" >

        ....

      </xapp:browse>

   </xapp:form>

</form>

</xapp:module>
...



any help will be greatly appriciated.

Thank you.

–joey

X-Application Version: 4.1.1
Tamino Version : 4.1.1
Platform : Win2k
WebContainer : Tomcat 4.1.24
JDK Version : 1.4.1

Hello Joey,

please have a look at the topic Using a Javabean value in a directelementaction for a similar problem.

Regards, Harald

Thanks for the tip Harald.

After reading the post you directed me to I realize its not possible to set attrubte values with <% %> JSP tags.

so the following is what I ended up trying.

  
......
<body>
<%
SessionContext sessionContext = ServletSessionContext.getSessionContext(pageContext);

String id = request.getParameter("cap_id");
String query = "for $x in input()/Capability where $x/@id = \"" + id + "\" return $x";

sessionContext.getVariablesHandler().setVariable("cap_query_by_id", query, "session");

out.println("ID : " + id);
out.println("<br/>");
out.println("query = " + sessionContext.getVariablesHandler().getVariable("cap_query_by_id")); 
%>

<xapp:module>

     <form method="POST" action="view_test.jsp" name="form_view">
        <xapp:form>
	   <xapp:directcommand type="read" collection="${NMPCollection$}" document="CapabilityDocument" arg="${cap_query_by_id$}"/>

           <xapp:browse document="CapabilityDocument" pagesize="1" >
               <xapp:display select="./name" />

               ......

           </xapp:browse>
        </xapp:form>

      </form>
   </xapp:module>

</body>
......




The query variable seems to be set because I print it out and it’s there. And it looks like the query is actualy being performed, BUT the contents of the returned element within the xapp:browse/ tag are not displayed. If I pass an invalid ID to this page I get a StoredException : element not found in database. So its something with the tag I’m guessing.

Any ideas what could be causing this behaviour ?
Thanks…

-joey

X-Application Version: 4.1.1
Tamino Version : 4.1.1
Platform : Win2k
WebContainer : Tomcat 4.1.24
JDK Version : 1.4.1

Hello,

you are using a ‘read’ command. This command requests a single document from the Tamino Server and stores this document within the workspace. The name of the document is ‘CapabilityDocument’.

You can access the document by defining a document context via the xapp:form tag. Therefore, could you replace the browse tag by

<xapp:form document="CapabilityDocument>
 ...
</xapp:form>



The browse tag is used to iterate a document set stemming from ‘query’ or ‘xquery’ commands / actions.

Bye,
Christian.

Thanks Christian.

I see what the problem was. I reaplced the browse tag with a form tag and a document=“CapabilityDocument” attribtue and that fixed the problem. Now the query is performed and the result is display properly.

Thanks again!!

–joeycz

X-Application Version: 4.1.1
Tamino Version : 4.1.1
Platform : Win2k
WebContainer : Tomcat 4.1.24
JDK Version : 1.4.1

Hello,

nice to hear that your problem could be solved.

Just another tip to solve your former problem:

You want to use a request parameter within a query. Request parameter are transferred per default to the variables handler.

So, you could check this for your parameter ‘cap_id’. If you add a tag

<xapp:getvar name="cap_id" /> 
</pre><BR><BR>on the page, the value of the request parameter should be displayed.<BR><BR>Therefore, you could also define your query referrencing this variable.<BR><BR><pre class="ip-ubbcode-code-pre">
<xapp:setvar name="cap_query_by_id" 
  value="for $x in input()/Capability where $x/@id = ${cap_id$} return $x" />
</pre><BR><BR>And then, you could use your directcommand<BR><BR><pre class="ip-ubbcode-code-pre">
<xapp:directcommand type="read"
                     collection="${NMPCollection$}" 
                         document="CapabilityDocument" 
                    arg="${cap_query_by_id$}" />



If this proposal works, you can skip the Java code of your JSP.

Excuse me when sending this proposal so late.

Bye,
Christian.

Christain, thank you for your reply.

awsome… i didnt know that the variables handler has access to request parameters… very cool…

this method is much more elegant then the JSP code approach. Although i did make one minor correction to the query veriable. quotes are requierd arround cap_id.

	<xapp:getvar name="cap_id" /> 
	<xapp:setvar name="cap_query_by_id">
		for $x in input()/Capability where $x/@id = "${cap_id$}" return $x 
	</xapp:setvar>




Thanks very much… this is realy helpful

btw… is this document anywhere in the XApplication documentation ? It would be very usefull to maybe add such a thing to the documentation of the next release of XApplication.

–joeycz

Hello,

there is a chapter ‘Defining and Processing XQueries’. It contains examples how define a query based on input fields. Input fields of a HTML form are request parameters that are send when HTML form is submitted.

However, we don’t have a section within the documentation where the mechanism of the request handling is explained. Could be a task for a next version :slight_smile:

Thanks.

Bye,
Christian.