Can I change the values of HttpServletRequest in ModuleTag ?

Hello,
I have a class that overrides ModuleTag.
I want to change some attributes of HttpServletRequest in the DoStartTag method.

Ok!?

Some more information is needed …

Michael

Software AG Germany, Darmstadt

I have a HModuleTag which extends ModuleTag and I use HModuleTag instead of ModuleTag in my application.
In this HModuleTag I have a such a variable
private PageContext myPC;

In doStartTagCore method of HModuleTag I make necessary operations and then
return super.doStartTagCore();

What I want to do is to do all necessary Businness Logic operations before calling super.doStartTagCore();

In doStartTagCore method of HModuleTag I have a line like this :
HttpServletRequest hsr = (HttpServletRequest) myPC.getRequest();

Here I can access to the parameters in the request but I can not change their values :frowning:
I hope this is clear enough.
Thanks
Server

It’s not possible to change values in HTTPServletRequest. Because the request was created and submitted by some client, changing the request would mean you want to client to send a different request.

Why do you want to change the request? To me, it feels more appropriate to modify the code that reads the request.

Michael

Software AG Germany, Darmstadt

Hello,
Let me explain what I want to do a little more in details.
Suppose I have an xapp:edit tag in my jsp file.
When user invokes this jsp this tag is converted to an tag in html.
The user enteres a value for this field and the value of this field is stored in a field in my businessdocument.
Suppose user enters xxx as value of the tag.
But I dont want xxx to be stored in the document. I take this xxx and convert it to yyy according to an algorithm and yyy is to be stored in the businessdocument.
Is it possible to implement such a thing ?
Thanks for your helps…
Server

Hello,

you can overwrite the default dehavior for storing the value of field: Map you own setValue method the field you want to control.

(1) xapplication.xml

<BR><element name="simple name of your field>"><BR>  <action name="setValue"<BR>           method="yourPackage.YourClass.yourMethod"><BR>    <arg>arg</arg><BR>  </action><BR></element><BR></pre><BR><BR>(2) YourClass<BR><pre class="ip-ubbcode-code-pre"><BR>public class YourClass {<BR>   public static void setValue(Element e, String newValue) {<BR>      if (newValue.equals("yyy") {<BR>        newValue = "xxx";<BR>      }<BR>      e.setText(newValue);<BR>   }<BR>}<BR>


Do you think, that will work?

Bye,
Christian.

Hello,
I have added the method to my class and it works fine :slight_smile:
But to detect which value I am going to set to the field I need to access the HttpSession or HttpRequest from this method.
Can you tell me how I can access to the HttpSession or HttpRequest from this method ?
Thanks for your interest
Server

Hello,

if you need the value of a request parameter you can use the VariablesHandler:

<BR><element name="..."><BR>  <action name="setValue" method="..."><BR>    <arg>arg</arg><BR>    <arg>variables</arg><BR>  </action><BR></element><BR></pre><BR><BR><pre class="ip-ubbcode-code-pre"><BR>import com.softwareag.xtools.xapplication.plugin.VaraiblesHandler;<BR><BR>public class YourClass {<BR>  public static void setValue(Element elem, String newValue, VariablesHandler var) {<BR>    String valueFromRequest = var.evaluatingReplace("name of the request parameter");<BR>    ...<BR>  }<BR>}<BR>




Bye,
Christian.

Hello,
I have added the var(VariablesHandler) attribute to my plugin method.
I can access the variableHandler but it does not return the correct value :frowning:

My code is as follows :

try {
newValue= var.evaluatingReplace("#currentHasta#/Hasta/Vaka/Kontrol/Tarih");
} catch (Exception ee) {ee.printStackTrace();}
System.out.println("newvalue = " + newValue);


In fact the variable I want to access is Tarih node of Kontrol. But when I examine the html output of the jsp page this fields name is #currentHasta#/Hasta/Vaka/Kontrol/Tarih
And the newValue becomes "#currentHasta#/Hasta/Vaka/Kontrol/Tarih"
not its value :frowning:

I hope it is clear.
Thanks for your interest…
Server

Hello,

for a better understanding what’s wrog, please, could you post

(a) the JSP page where you set the variable and
(b) the complete code of the plugin method?

Many thanks,
Christian.

Hi,

I have added these lines to xapplication.xml



arg
variables



Then I added this method to VariablesHandler :
public Iterator getSessionVariables() {
return sessionVariables.keySet().iterator();
}

then I added this setIslemTarih method to my Hitit class :

public static void setIslemTarih(Element el, String newValue,VariablesHandler var) {
if (CommonJava.strEqualNullOrEmpty(newValue)) {
try {
Iterator it = var.getSessionVariables();
System.out.println(“it…”);
while(it.hasNext()) {
System.out.println("…"+it.next().toString());
}

newValue= var.evaluatingReplace("#currentHasta#/Hasta/Vaka/Kontrol/Tarih");
} catch (Exception ee) {ee.printStackTrace();}
System.out.println("newvalue = " + newValue);
}
el.setText(newValue);
}

When I submit a page that contains the IslemTarih node this method is invoked .
But the iterator(it) is probably null since program does not enter into the loop.
And the new value of the IslemTarih becomes "#currentHasta#/Hasta/Vaka/Kontrol/Tarih"

Thanks Server
X-Application Version: 3.1.3, 3.1.2, 3.1.1
Tamino Version : 3.1.1
Platform : NT, Win2k, Solaris, …
WebContainer : Tomcat 3.3
JDK Version : 1.3.1

If the iterator is null, you’d get a NullPointerException (when calling is.hasNext()). Maybe there are no variables at all, and thus, hasNext() always returns false.

Michael

Software AG Germany, Darmstadt

I think, there is a mistake:

The VariablesHandler provides functionality to store strings (variable values) which assigned to other strings (variables).

It provides a evaluaiting replace method which filters a string for variable references of the form

${a variable name$}

and replaces this variable by the value of the variable.

If you evaluate the string

#currentHasta#/Hasta/Vaka/Kontrol/Tarih"

There is no variable reference to by replaced and
therefore the result of the method is

#currentHasta#/Hasta/Vaka/Kontrol/Tarih".


My propose (if I understand your scenario right):

Within the JSP:


<directelementaction type=“setValue” select="…/IslemTarih" …/>

Within the code:

String newValue = var.evaluatingReplace("${IslemTarih$}");

Bye,
Christian.

Hello,
I think the way you mentione would not work because the setvar tag will set the IslemTarih as the old value of Kontrol/Tarih not the value that has been entered into that field before the last request :frowning:
Isn’t there any way to access to the request variables?
(The input tags of html request)
Thanks
Server

Hello,

then overwrite the set method of …/Kontrol/Tarih: If the value is set transfer the value to IslemTarih.

code:

<BR>... (Element kontrolTarih, String newValue, BusinessDocument doc) {<BR>   kontrolTarih.setValue(newValue);<BR>   Element islemTarih = doc.selectElement("/.../Islem/Tarih");<BR>   islemTarih.setText(newValue);<BR>}<BR></pre><BR><BR>This means, if the value of Kontrol/Tarih is set the value of Islem/Tarih is set also.<BR><BR>If Islem/Tarih is not part of the document where Kontrol/Tarih belongs to, use the workspace instead of the BusinessDocument, e.g.<BR><BR><pre class="ip-ubbcode-code-pre"><BR>... (Element kontrolTarih, String newValue, BusinessDocumentWorkspace ws) {<BR>   kontrolTarih.setValue(newValue);<BR>   BusinessDocument doc = ws.lookup("name of the document islem tarih belogs to");<BR>   Element islemTarih = doc.selectElement("/.../Islem/Tarih");<BR>   islemTarih.setText(newValue);<BR>}<BR>



!! The mapping of the Plugin method has to be adapted if you want to implement one of these solutions, the arguments are

arg
document

or

arg
workspace

Bye,
Christian.

Hello,
The method you proposed would not help me because I will not set the value of IslemTarih always as Kontrol/Tarih.
In my scenario there will be one other Tarih node being updated with IslemTarih.
These pairs are possible to be together.

Kontrol/Tarih && IslemTarih
Muayene/Tarih && IslemTarih
Yatis/Tarih && IslemTarih
Yatis/Ameliyat/Tarih && IslemTarih

So I need to check which field is submitted together with IslemTarih and set the value of IslemTarih as this value.
I know this is an interesting situation and can seem meaningless to you but this is what my application requires.
Server

Hello,

if I understand your requirement right, then you want to update the node

…/IselmTarih

to the value of the current setting of another Tarih node. This node can be:

…/Kontrol/Tarih
…/Muayene/Tarih


If you register the plugin I proposed for a Tarih node

<BR><element name="Tarih"><BR>  <action type="setValue"<BR>          action="myPackage.MyClass.setTarih"><BR>     <arg>arg<arg><BR>  </action><BR></element><BR></pre><BR><BR>The code of the plugin<BR><BR><pre class="ip-ubbcode-code-pre"><BR>package myPackage;<BR><BR>public class MyClass {<BR>    public static void setTarih (Element tarih, String newValue, BusinessDocument doc) {   <BR>        tarih.setValue(newValue);<BR>        Element islemTarih = doc.selectElement("/.../Islem/Tarih");   <BR>        islemTarih.setText(newValue);<BR>    }<BR>}<BR></pre><BR><BR>would be invoked for every tarih node independent of the parent. Perhaps, it was a mistake: a plugin is bound to an element independent of the parent context. It could be 'Kontrol', but it could be also 'Yatis', 'Ameliyat' or 'Muayene'.<BR><BR>If you need additional information about the parent you can get it from the Tarih node, e.g.<BR><BR><pre class="ip-ubbcode-code-pre"><BR>    Element tarihParent = tarih.getParent();<BR>    if ("Kontrol".equals(tarihParent.getName()) {<BR>        ...<BR>    }<BR>



Do you think, this could solve your requirement?

Bye,
Christian.