Solved

JAVA STRUTS JSP

Posted on 2004-10-14
66
1,906 Views
Last Modified: 2013-11-23
Hi All,

Would appreciate help with my this project pls..

I am not too old to this company, but I am very new to this project. I know some of Java & jsp, and don't know anything about struts and weblogic.

This project was developed by my company and sold to other company. But my company supports it. unfortunately all guys who wrote this code have left. Now this urgent issue came up to support and modify code on this project and some requirements are so that if we don't support, we will loose this whole product. Unfortunately my company cannot hire anybody so soon, it will take them few weeks to hire due to budget approvals etc. and economic reasons. So I am trying to save this project for a company thus few guys can be hired also once we can support this product and situation is stable..

Hope you guys can help me saving this project..


This is written in JAVA-JSP-STRUTS ON WEBLOGIC 6.1/8.1 ON UNIX..

This is the first requirement --

There are tabs on the page -- Dealings/Trds etc..

Once we click on Trd's..  (it calls http://ifxap1.nj.ssmb.com:8005/isoft/iSoft/ViewTrades.do?action=recon)

I know ViewTrades.do is not actually a file -- it is some mapping to jsp in struts..

This page brings a form to fill with some parameters


in this form, there  are several fields to fill but one I need to work on is as below:


There is a select box, text box, submit button and reset button:


TEXTBOX:

<html:text  property="gpNum" styleClass="inputtextmedium" tabindex="1"/>

SELECT BOX:

          <html:select property="reconSource" value="Dollar" size="3" styleClass="inputtextmedium" tabindex="4">
                <html:option value="Dollar"></html:option>
                <html:option value="Non-Dollar"></html:option>
                <html:option value="Australia"></html:option>
              </html:select>



action of the form is as below:
<html:form method="get" action="/TradeReconSearch" onSubmit="tradeReconSearchValidate(this);">

and reset of button:

<html:reset styleClass="submitsmall" property="Button" value="Reset" tabindex="14"/>


Now when client selects option (say Australia), and in textbox say value = 115,

and click on submit, it comes with response page -- as well as above form on the top (in case client wants to submit it again).

Requirement 1:

The form which comes back has value in the textbox (115) which client typed initially, but doesn't have option selected .. (it resets it back to default option).. requirement is to make is somehow so that it comes in response page with seleclted option as (AUSTRALIA) as client submitted.

Requirement 2:

say response page came back with
results
and form again with textbox populated..

RESET BUTTON should reset everything to default values.. (Initially before submitting, default value of textbox was empty)

But on response page, default value of textbox has been changed to whatever client put on first page (115).

If I click on reset button on response page, it will always reset to 115 (and not to empty). I want to reset this to empty (without reloading the page - since it will delay the process since action is going to servlet etc.. i want to do this client-side and fast)..


any help pls...


Thanks,

Regards

0
Comment
Question by:shivani
  • 29
  • 20
  • 12
  • +1
66 Comments
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12310089
Requirement 1:
To make the selection box display the selected value after a submit, take away the   value="Dollar"   property from your <html:select ...> tag.  Also, make sure that the ActionForm is not resetting the value of the variable   reconSource .
0
 
LVL 4

Accepted Solution

by:
Rick_Townsend earned 80 total points
ID: 12310150
Requirement 2:
You cannot have the Reset button set the values to blank if you want the previously entered values to show up, without either
a) processing a request on the server to reset the values of your bean, or
b) using JavaScript to clear all the fields.

Option a) is the Struts way, but does take more time because of network lag and processing time.  Also, you will lose the values previously submitted, because you will remove them from your bean (I don't know if that is important, but I thought I'd mention it.)

Option b) will be faster, but means you have to use a JavaScript function to clear all the values.  You would do something like this:
<html:button styleClass="submitsmall" property="Button" value="Reset" tabindex="14" onClick="clearAllFields()"/>

where clearAllFields() is your JavaScript function.
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12310481
Im fairly new at Struts but maybe I can help.

Requirement 1: Inside the action class of the submit button, get the value from the ActionForm
and set it as an Attribute on the request object, when the jsp loads, download it from the
request, and set the ActionForm field to it..

Requirement 2 recommendation:
Maybe if you activated the reset method on the Formbean as the action of the reset button
you see, Struts loads the form as a bean inside the scope (usually session)

Personally, I like Rick's Javascript clear idea better =D

About Recommendation 1....
First check which form are you using in your action...(struts-config.xml)
for example:
<action path="/GoToEdit"
            type="com.softtek.actions.ActualEditProyectL"
            name="ProductForm"/>    

This action (the one the button submits to) fills the ProductForm (a JB instance)
declared here:
<form-bean name="ProductForm"  type="com.softtek.forms.ProductForm"/>
Now, type, is the class ProductForm instatiates from.
This is where all form data from the jsp page is stored after submitting it to the action.

Inside the action, i uploaded the desired String data to an attribute
request.setAttribute("cate","This is the data I want by default in the textbox");

Now, in your JSP page...after returning from the action..
Import the class:
<%@ page language="java" import="com.softtek.forms.ProductForm" %>
in a JSP section:
<%
ProductForm f = (ProductForm)session.getAttribute("ProductForm");
 Striing categoria = request.getAttribute("cate").toString();
 f.setDefaultedTextBox(categoria);
%>

In the example above, defaultedTextbox is the name of my Textbox.

I hope this works for you, like I said im fairly new at this (2 weeks).

Good luck!


0
 

Author Comment

by:shivani
ID: 12310981
Rick and Celdric,

Thanks for your comments.

I will try the approaches from Requirement 1. Though I have not completely understood what I am doing here (since as I told you, I have never touched struts before), looks like atleast I will able to somehow make this working, and then I can try to understand how is this struts working here as well..


Requirement 2:

Well, Rick clearAllFields(), will not work here, because all the fields in the form are not empty. Some of the fields have default value in it, and we want to keep it like that.. when user Clicks on "RESET" button, default values (some of them are empty, some have some value), should be populated.

Any ideas on how can I accomplish this easily..??
0
 

Author Comment

by:shivani
ID: 12311111
Rick,

Your idea of Requirement 1 is working great looks like. I am testing it right now. Only thing is, Now I have lost the default value as "DOLLAR" from the page. Now it comes with empty select (no value selected). I wanted this to be defaulted to DOLLAR. Any ideas?


Thanks to both of you in advance for help..

0
 

Author Comment

by:shivani
ID: 12312106
Hello

Any help on my way here pls
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12312113
You can pre-populate your form bean (ActionForm class) with the default values.  The usual method is to put them in the reset() method (if you plan to re-use the form bean), or in the constructor (if you create a new form bean for each request.)  You can then put those defaults in your JavaScript method.  i.e.: Instead of clearing the fields, set them to their defaults.
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12312156
Instead of using methods in the ActionForm, you could also just call the JavaScript reset method when a user first enters your site, so that the defaults are loaded.  How easy that is to implement will depend on what pages are loaded in what order.
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12312173
Well, If you tried the method I recommended, instead of setting the inputs with a "default"
String, you could set them to empty "" Strings, but I think you should try Ricks method first :D
The method im talking about is too hard-coded and bulky and its server-side. (I think)


0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12312252
Celdric: Your solution will work.  Your method for Requirement #1 is basically re-implementing the functionality of the Struts selection tag.  It's usually easier to avoid that kind of hard-coding unless required (as you again stated above).  I re-iterated your suggestion to use the reset() method of the ActionForm, since that is the simplest solution.

shivani:
Pros and cons of using a JavaScript method v.s. the reset method of your ActionForm

JavaScript:
Pros: Faster, client-side (so less work for your server), possibly easier to program and maintain depending on your experience
Cons: To have it set your defaults, will have to be customized with the actual names of each field that needs a default value.  To have it simply clear every field, you could write a generic script that clears all the fields in a given form...

ActionForm's reset() method:
Pros: Simpler solution (can define the defaults directly on each field), defaults can be applied on initial creation and on reset, requires no JavaScript at all
Cons: Slower for resetting, since it requires a call to the server
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12312269
I won't be checking my email for 3 or 4 hours, so please don't feel that I'm abandoning you guys.  I'll check this thread again after we land.
0
 

Author Comment

by:shivani
ID: 12312325
Rick,

I am sorry could not understand your ActionForm method..

Sorry I have never done struts but I am trying to understand this all as you experts are suggesting solution..

I thought by reading some info that

I will get the information of ActionForm (name of it) in struts-config.xml file...

Firstly I could not located struts-config.xml file in this whole project..

But I do see a XML file --

trade-struts-config.xml file  looks like they are using this file..

I saw this
<form-bean name="tradeSearchForm" type="org.apache.struts.validator.DynaValidatorForm">

is there a ActionForm here? Any ideas how to get to this?


Your second idea (JAVASCRIPT RESET METHOD) -- I am sorry could not understand.. can you provide me with same code or direct me to place where I can understand this idea more?
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12312339
Whoa, Dynamic Forms, I think you CAN set the default values from there, let me look it up.

 Im going on a netless vacation this weekend and wont be seeing the forum till monday.

Here is a great link that explains most JavaScript functions and things that i find useful
If you need a good reference, Im sure Rick has better, but this can help you while
he comes back :)

http://www.devguru.com/Technologies/ecmascript/quickref/js_functions.html

Be back with some info on the DynaForms
0
 

Author Comment

by:shivani
ID: 12312373
Celdric,

To Implement your solution, I think I need to know more about STRUTS and how they are being used in my appl.

Can you help me understanding this since I am sure u r an expert already
0
 

Author Comment

by:shivani
ID: 12312388
Comeon,
everybody is leaving from this Q
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12312419
Lol, Im no expert, but I think we can pull this off with DynaForms, at least the reset button.

Check this out:
<form-bean name="dynaCustomerForm"
           type="org.apache.struts.action.DynaActionForm">
  <form-property name="lastName" type="java.lang.String"/>
  <form-property name="firstName" type="java.lang.String"/>
  <form-property type="java.lang.String" name="street"/>
  <form-property name="city" type="java.lang.String"/>
  <form-property name="state" type="java.lang.String"/>
  <form-property name="postalCode" type="java.lang.String"/>
</form-bean>

If your struts config has that setup, you could put the default value from there
like: <form-property name="lastName" type="java.lang.String" value=""/>

Now, this will make the form be unpopulated by default, and when it loads you can
use javascript to populated like Rick says.

You can put the Reset Button do an action that uses the unpopulated  form..
I personally havent used DynaForms, but tell me if it works.
0
 

Author Comment

by:shivani
ID: 12312429
Comeon,
everybody is leaving from this Q :)))

Ok Ok kidding..

I am sorry, but my deadline to accomplish this is this weekend, so kind of in a difficult situation right now..

I will try to convince them if they can wait until Monday since I know lot of things have to be understood here due to my limited knowledge, but well, company's project in stake, so it will not be easy for me to make top guys understand this, anyways, best we can do is try..

well, your javascript link, I am looking at it and trying to find a reset function rick mentioned, if u know it from top of your head, let me know where to look for it.

Thanks
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12312533
Well, not a JS expert myself, Im fresh out of college and started learning Java
in August (was a .net junky in college), anyway. Im going to explain some basic Struts
Concepts, like really fast.

Now, Struts is mainly made of 3 things, the Controller, The Model and the View.
In out case, the controller is the Action Class
the model is the JavaBean (or ActionForm) where data is stored
and the view is the JSP page.

The thing in common between the 3 is the servlet container, and this uses scopes, that
are like places where we store objects and Data.

Now, when you are in a form and click submit, the ActionForm fills itself from the jsp,
struts tags (how it does this, i dont know exactly), inside the Action, you recieve
ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response

the mapping is to find to which page the action will redirect the user (a forward)
the actionform is the data that was captured from the STRUTS HTML tags
the request is the object where all this will be stored
and the reponse...well..I dont know what that IS =#)

anyway, inside the action, before the forward, you can "attach" objects (like a String)
to the request, so when the next page (or action) gets it, it can access the data.

So, in your case, to populate the form with the values your user input, you ned to attach
that data somewhere, like i told Rick, my method is bulky, ugly and you should avoid it
if possible, you can attach the data to the request object using the setAttribute method
and unload it in the JSP using the request.getAttribute method inside a JSP section and
putting it in a JSP page variable..phew..well..Ill stop here...any questions?
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12312587
Oh yeah, when i started learning sTruts, I found this example very helpful.

http://javaboutique.internet.com/tutorials/Struts/
http://javaboutique.internet.com/tutorials/Struts2/
http://struts.apache.org/userGuide/struts-html.html

and the e-book Mastering Jakarta Struts is also good to understand how
struts-config.xml works.

Good luck


0
 

Author Comment

by:shivani
ID: 12312620
Well,

I see in trades-struts-config.xml

    <form-bean name="tradeSearchForm" type="org.apache.struts.validator.DynaValidatorForm">
      <form-property name="ccMnc" type="java.lang.String"/>
      <form-property name="dealMnc" type="java.lang.String"/>
      <form-property name="acctNum" type="java.lang.String"/>
      <form-property name="branchFc" type="java.lang.String"/>
      <form-property name="symbol" type="java.lang.String"/>
      <form-property name="tradeDateFrom" type="java.lang.String"/>
      <form-property name="tradeDateTo" type="java.lang.String"/>
      <form-property name="entryDateFrom" type="java.lang.String"/>
      <form-property name="entryDateTo" type="java.lang.String"/>
      <form-property name="stlmDateFrom" type="java.lang.String"/>
      <form-property name="stlmDateTo" type="java.lang.String"/>
      <form-property name="moveDateFrom" type="java.lang.String"/>
      <form-property name="moveDateTo" type="java.lang.String"/>
      <form-property name="ltEqQty" type="java.lang.String"/>
      <form-property name="gtEqQty" type="java.lang.String"/>
      <form-property name="tradeStatus" type="java.lang.String"/>
      <form-property name="firstTradeId" type="java.lang.String"/>
      <form-property name="lastTradeId" type="java.lang.String"/>
      <form-property name="prevTradeId" type="java.lang.String"/>
      <form-property name="prevCounter" type="java.lang.String"/>
      <form-property name="action" type="java.lang.String"/>
      <form-property name="gpNum" type="java.lang.String"/>
      <form-property name="imsNum" type="java.lang.String"/>
      <form-property name="reconSource" type="java.lang.String"/>
      <form-property name="methodName" type="java.lang.String"/>
    </form-bean>


Here I don't see any default value to be set -- But on the page -- I have some fields with default values -- like for example:

Trade Date has default value as 20041013  where is this coming from ???  It is not in JSP also..

any ideas?

I am not sure if I understand your comment correctly..

<form-property name="tradeDateFrom" type="java.lang.String" value=229292929 />

what do you mean  

>>Now, this will make the form be unpopulated by default, and when it loads you can
use javascript to populated like Rick says.


Why would it be unpopulated? when I load the page, will not it get it from this struts-config.xml file to 229292929 ??>?

sorry, I am new to this all... be patient

 
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12312678
Well, maybe the Trade Date is filled from somewhere else like inside the action
do a search on your project for tradeDateFrom and TradeDateFrom and check out
where it gets filled. it may use a method like setTradeDateFrom(Date);
or something.

Now about this:
<form-property name="tradeDateFrom" type="java.lang.String" value=229292929 />
the value should be inside ""

now, the name is the name of the form property, the type, well.. String/int/whatever
and the value, the default value, if it doesnt get changed anywhere between the
Instantiation of the form and the display (JSP)

I hope Rick comes back soon, he could help out more :)

Bytes!
0
 

Author Comment

by:shivani
ID: 12312713
Thanks for all the info buddy.. which college u got out from? where u from?

Understood most of stuff you explained..!!


Ok firstly, in my case, which is the ACTIONFORM? Do we have a ACTION form?

Or is it that if we are using DynaValidatorForm, we don't need a ACTIONFORM.. I am trying to understand where is this value 20041013 on my page for a field coming from
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12312812
Tec de Monterrey in mexico :D

Well, I havent checked out DynaForms, because its a little bit of advanced Struts but
I think what it does it makes a dynamic form from the properties you set in the
Struts config file and makes it the Actionform you get in the Action class.

In your case, your Form extends an ActionForm and it adds a validator
(hence the DynaValidator), what is does, it makes a JavaBean(I hope you know JB, if not
I can explain) with all the properties defined in the struts-config.

So your bean will hold space for all the following properties:
     <form-property name="moveDateTo" type="java.lang.String"/>
this translates to a:
String moveDateTo;

public void setMoveDateTo(String moveDateTo)
{
   this.moveDateTo = moveDateTo;
}

public String getMoveDateTo()
{
     return this.moveDateTo;
}

because is a dynamic form, this "class" makes itself at runtime.. its a bit complicated, I guess.
The actionForm will be this dynamic form that makes itself from the stuff you
set in struts-config

Hope it helps.
0
 

Author Comment

by:shivani
ID: 12312906
>> Well, maybe the Trade Date is filled from somewhere else like inside the action

Well, I got it from your suggestion where they are setting 20041013, not sure how this is happening though..

When I go the URL for the first time,

below if the URL:

ViewTrades.do?action=recon

Now  according to trades-struts-config.xml file,


<action path="/ViewTrades"
            type="com.citi.soft.struts.action.trade.ViewTradesAction"
          name="tradeSearchForm"
          validate="false"
          scope="request">
            <forward name="viewtrades" path="/jsp/viewtrades.jsp"/>
            <forward name="viewrecontrades" path="/jsp/tradesrecon.jsp"/>
      </action>
          

So is it that as soon as we hit ViewTrades.do?action=recon, it goes to ViewTradesAction??

In ViewTradesAction class, I found, (some relevant code only here)

DynaActionForm tradeSearchForm = (DynaActionForm) form;
tradeSearchForm.set("tradeDateFrom", String.valueOf(prevBusinessDate));
            tradeSearchForm.set("tradeDateTo", String.valueOf(currentDt));

            if (forwardPage != null && forwardPage.equals("recon")) {
                  return mapping.findForward("viewrecontrades");
            } else {
                  return mapping.findForward("viewtrades");
            }


So here they set it..

So may be I can set the default value of my select box also at this location, and atleast REQUIREMENT 1 should be okay.. right??


Lets finish Req 1 and we will think of REQ 2..

Am i on right track?
0
 
LVL 1

Assisted Solution

by:Celdric
Celdric earned 120 total points
ID: 12313049
Yeah, if they do that like that, its logical you can do it the same way wtg! :D

Well, its almost quitting time, and I hope Rick comes back and helps you out. :)

Im gonna check this thread Monday, but myabe I can check it tomorrow.

I wish you lots of luck!

Before I go, quick explanation about the action tag of struts:
<action path="/ViewTrades"
          type="com.citi.soft.struts.action.trade.ViewTradesAction"
         name="tradeSearchForm"
         validate="false"
         scope="request">
          <forward name="viewtrades" path="/jsp/viewtrades.jsp"/>
          <forward name="viewrecontrades" path="/jsp/tradesrecon.jsp"/>
     </action>

Well, the path is the url you use to access the action, in this case: ViewTrades.do
the .do part its implicit

the type, is the class it instantiates the action from.

it doesnt validate..I guess not sure about this one.
scope, it means the Action will put its ActionForm (the DynaForm) inside the request object.
The forwards are to determine where to go after the actionn returns depending on
the String it returns..

Hope it helped!
0
 

Author Comment

by:shivani
ID: 12313643
Thanks alot Celdric.

This is helping me alot..

Rick and Celdric,

To accomplish requirement 1:

I finally changed the
ViewTradesAction

to add
tradeSearchForm.set("reconSource", "DOLLAR");

But this doesn't seem to be working.. My select box doesn't show "DOLLAR" as default value..

Just to do an experiment,

I also did the same thing for textbox:


tradeSearchForm.set("gpNum", "00055");

and it seems to be working well..

anything special I need to do for select box?

I also have a list box on my page.. so I guess we will have same problem with list box also..

any help pls
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12315929
Well, shivani, I am not an expert in Struts....just average :D but I will try my best to help you.

Are you sure that it is DOLLAR and not Dollar? I see from your first page that it is Dollar instead of DOLLAR in your select box.

Good luck
0
 
LVL 16

Assisted Solution

by:suprapto45
suprapto45 earned 50 total points
ID: 12316021
Hi,

So, try tradeSearchForm.set("reconSource", "Dollar");. Remember that Java is case sensitive :D.

For the second requirements,
To clear the textfields, you should use either use Javascript (as what those gentleman said) or change the reset button to normal button and associate some codes with that particular button to clear the value in the form. You can use like....tradeSearchForm.set("gpNum", ""); and so on.

Does it make sense....Sorry English is my second language

0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12316033
Shivani,

If you need the JavaScript, please do not hesitate to contact me...I can provide one very good sample for you. I am using JavaScript too sometimes for clearing textfield (for validation).

Good luck
0
 

Author Comment

by:shivani
ID: 12320065
Supra,

Looks like you were right. I messed up in between DOLLAR and Dollar..

It seems to be working fine now..

Only problem I am having with respect to REQ 1 for now is with MULTPLE SELECT BOX:

  <html:select multiple="true" property="tradeStatus" size="3" styleClass="inputtextmedium" tabindex="17">
            <html:option value="All"></html:option>
                <html:option value="Trade"></html:option>
                <html:option value="Adjustment"></html:option>
                <html:option value="Exception"></html:option>
                <html:option value="User Cancel"></html:option>
                <html:option value="True Cancel"></html:option>
              </html:select>


If user selects "Trade" and "Adjustment" and submits it, result screen comes up with only "Trade" as selected option and forgets about "Adjustment" . Any ideas how this can be fixed..??

With respect to REQ 2:

Well, I might be confused here.. sorry about it.. but I don't want to "CLEAR" fields..  

I want to "RESET" them..

So for example --- if Dollar is default option.. and if user selects "AUSTRALIA" and submits the form, result page comes with "Australia" as selected option  Right?  So if user clicks on reset button on this result page -- the value should go back to Dollar - since Dollar was the default value....  can javascript do this?? I don't want to hard-code too much here.. and I don't want to get it slow by sending it to server also .. any ideas?
0
 

Author Comment

by:shivani
ID: 12320073
BTW,

You english is good -- I was able to understand everything you said.. what country r u from?>
0
 

Author Comment

by:shivani
ID: 12320473
Hello
Any help here pls...

Rick? Supra? Celdric? Anybody else?
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12321409
Your variable for the multiple selection box needs to be an array.  If you've recently converted this field from a single selection to a multiple selection, you need to convert the variable and getter and setter.

The variable should be defined like this:
private String[] tradeStatus;

The getter and setter should get and set the array:
public String[] getTradeStatus(){
   return tradeStatus;
}
public void setTradeStatus(String[] tradeStatus){
   this.tradeStatus = tradeStatus;
}
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:shivani
ID: 12322398
Do You mean

In this line of trade-struts-config.xml
<form-property name="tradeStatus" type="java.lang.String"/>

I should have

<form-property name="tradeStatus" type="java.lang.String[]"/>

instead???


Since here we are using DYNAFORM, so there is no methods like as below:::

private String[] tradeStatus;
public String[] getTradeStatus(){
   return tradeStatus;
}
public void setTradeStatus(String[] tradeStatus){
   this.tradeStatus = tradeStatus;
}

I am sorry if I have misunderstood this
0
 

Author Comment

by:shivani
ID: 12322487
Also, How can I initialise the value to "ALL" in this case??
0
 

Author Comment

by:shivani
ID: 12322635
Ignore my last 2 comments..

Looks like it is working well..

<form-property name="tradeStatus" type="java.lang.String[]" initial="All"/>



I really appreciate your help..

with this my Req 1 is done..

I appreciate all the help you all have provided..

Now lets move to Req 2 (Reset button - TO Reset the form to initial values)...

Please remember - I am using DYNAFORM  and I don't think here they are subclassing it..

because
in
ViewTradesAction

they are doing
DynaActionForm tradeSearchForm = (DynaActionForm) form;

and setting initial values
as

tradeSearchForm.set("tradeDateFrom", String.valueOf(prevBusinessDate));

Any ideas please..


0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12323117
Oh, yeah, sorry, forgot you're using a DynaValidatorForm, and not an ActionForm.
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12323185
Well, if we're dropping the JS method, you could set up a Reset action in the ViewTradesAction action handler, that would simply set all the defaults.  (It would probably call whatever method you already have for setting the initial values.)
0
 

Author Comment

by:shivani
ID: 12323256
Well, Rick,

I have not dropped JS method.. I just don't know how to do it in JS.. Can you give me some sample code pls.. (Please note that I don't want to clear the fields -- I need to set it to initial value)


Also, there is no method to initialize the values in ViewTradesAction.

below is code for ViewTradesAction:

   public ActionForward execute(
            ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response)
        throws IOException, ServletException {

            DynaActionForm tradeSearchForm = (DynaActionForm) form;

            tradeSearchForm.initialize(mapping);

            SimpleDateFormat dtFormat = new SimpleDateFormat("yyyyMMdd");

            String forwardPage = (String) tradeSearchForm.get("action");

            String currentDt = dtFormat.format(new Date());

            long prevBusinessDate;

            try {
                  prevBusinessDate =
                              BusinessDate.getInstance().getPreviousBusinessDate(
                                                      BusinessDate.US, currentDt);
            } catch(Exception ex) {
                  ex.printStackTrace();
                  if (forwardPage != null && forwardPage.equals("recon")) {
                        return mapping.findForward("viewrecontrades");
                  } else {
                        return mapping.findForward("viewtrades");
                  }
            }

            tradeSearchForm.set("tradeDateFrom", String.valueOf(prevBusinessDate));
            tradeSearchForm.set("tradeDateTo", String.valueOf(currentDt));
            tradeSearchForm.set("reconSource", "Dollar");
            //tradeSearchForm.set("gpNum", "00055");
            //tradeSearchForm.set("tradeStatus", "All");
        System.out.println("in ViewTradesAction");

            if (forwardPage != null && forwardPage.equals("recon")) {
                  return mapping.findForward("viewrecontrades");
            } else {
                  return mapping.findForward("viewtrades");
            }
      }

so few things are set in here using tradeSearchForm and now I am setting one value in XML file
<form-property name="tradeStatus" type="java.lang.String[]" initial="All"/>

so if we have to take this approach, can u tell me how to do it with sample code pls.. (Please I am sorry.. I am new to struts and all here)...

I would prefer JS approach here just becoz' it is fast, but ofcourse I have to clean and good with code to accomplish this else they will reject the solution thus my company will lose project.. so I have to be careful what I am providing them..


Thanks for all ur help
0
 

Author Comment

by:shivani
ID: 12323864
Hello

Any help pls
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12326288
Hi,

Sorry shivani, I am busy with my work so I have limited time in EE. However, I am trying my best to help you. Thank you for your compliment regarding my English. I am from Jakarta, Indonesia. David is my real name, suprapto is just my alias in Expert Exchange (EE) :).

Congrats to your first req :). Glad to help.

Regarding your second req.....

I have analyzed one thing. First the user chooses the "Dollar"....(the address maybe http://localhost/first.do - initial page where jsp loaded) and the response page (after you click submit button) will come out with the select box that chooses the "Dollar" (the address maybe http://localhost/response.jsp) . Well, to reset it, we can actually not to "reset" it but to use "tricky" way. When the user clicks the reset button, you could actually set your jsp back to the initial address which is "http://localhost/first.do" where all the value are blank and default. I do not know whether this way is appropriate for you or not but if I were you, I will use this way. So like directing the user back to the initial page.

To accomplish as what I said, you cannot use Reset button. You should use normal button. So change
<html:reset styleClass="submitsmall" property="Button" value="Reset" tabindex="14"/>
into
<input type="button" class="submitsmall" value="Reset" onclick="javascript:direct()"/>

it is extremely okay to  have "input type button" instead of "html:submit" in your JSP as Struts can be mixed with normal HTML. This is where the flexibility comes up. I am not sure on how to put tabindex in "input type button".

Then in your response.jsp where the reset button was located, add these codes before your inside your <head></head> and before your <body> and <html:form>

<head>
<!-- blah here -->
<script language="javascript">
function direct()
{
    location.href = "./first.do"
}
</script>
<!-- blah here -->
</head>

<body>


I hope that helps you. Please contact EE again if you still have problem
0
 

Author Comment

by:shivani
ID: 12332497
Supra,

Thanks for your input on this.

But unfortunately I don't think redirecting back to initial page would be a acceptable solution here.

They stressed on requirement that "Reset" button means to reset it back to initial (default values).. not redirecting, nor reloading, not clearing the values to empty..

REMEMBER IN THIS CASE --

ON response page -- we have this form , but we also have RESULTS of previous request.. I don't want to lose the the results of the previous request on this page.

It is like -- on response page --

we have on ths top a "+" sign which is user clicks -- it displays the form again..

On bottom -- we have results of the previous request..

They can resubmit the request from the top form which would reload the page again .. with results from new request.. i don't think this top and bottom are frames .. but i will check..

But anyway, i don't want to lose results at the bottom anyway while somebody clicks on reset button.. hope u understand..


So we have to somehow find a solution fot resetting it to default values...

Anybody -- Can js help in doing this? Any sample scripts would be helpful..

If js is not a solution, How should I code for reset button so that when somebody clicks on 'RESET' button, a method is called which can reset the values to default..

But without losing results from previous request??

0
 
LVL 1

Expert Comment

by:Celdric
ID: 12333222
Well, sorry for the late answer, couldnt get online before today, and I dont have much time,
have to pack up so I can get back home to get some sleep and go to work tomorrow...anyway

Now that the reset button is the only requirement left, I have an idea.
But first Ill explain how the forms get populated from within struts.
As you know, when you input an URL, the server looks to web.xml which in turn points
to Struts-confiug.xml, here struts looks up (or if it isnt created yet, it instantiates) 2 things:
A form, and an Action, using the Struts tags, struts fills the Form (in our case the DynaForm)
from the HTML tags in the previous jsp page. Then it calls the execute method of an Action
and gives it the form as a parameter.. so the form(which is a bean) is already filled when
the action gets there. Now..

We need to store the "default" data somewhere, right before Struts overwrites the
new data with the submit button, so when we click the reset button
the "default" values are emptied into the field, so we need the following steps:

1)In the action, right after setting the form default values, fill another Javabean (or a another data structure) with these default values. Just make another instatiation.
2)Attach this new bean it to the session object. (not request)
3)When the JSP form loads, it will be loaded with the default values of the first bean
   (not the one attached to the session)
4)When pressing the reset button, create an extra action, this action will fill itself with the
   modified data (dont worry, we will ignore this)
5)Now, when, inside this new action, we recieve the DynaForm instead of casting it
  DynaActionForm tradeSearchForm = (DynaActionForm) form;
  We will NOT put that line in this new action, we do not want the data the user input, we
  will fill this new form not from the previous form (from the JSP page) but from the
  data we stored in the session object so we:
  DynaActionForm tradeSearchForm = (DynaActionForm)session.getAttribute("storedbean);
 
  This will now fill the new page with the default values in the session bean and not from
  the form the user input before pressing reset, now we do a forward to the page and viola!

  Now, I dont remember the exact syntax for this solution (Im not at work) but I can help
  you create this new action tomorrow when I get back to work, so tell me if youd like
  to pursue this.

  Oh yeah, after using this stored bean, we need to remove it from session, but I dont remember
  thr syntax, ok.. good luck, see ya tomorrow!
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12333284
Oh yeah, I guess this could work too..hell, it may be a better solution

In the JSP page, use a onload javascript function that will store ALL default data.
You can store this data inside a String Array by iterating through the html inputs of the forms.

Inside  this function attach it to the request object, when the new action is called from
the reset button, get the info from the String Array in request and ignore the Dynaform
and cast it like the above example. This should work.

Remember when you set an attribute inside the request object, this attribute can be any
object, including String arrays.

In the javascript function...
String[] inputs = new String[8];
request.setAttribute("defaultdata",inputs);

In the action..
DynaActionForm tradeSearchForm = (DynaActionForm)request.getAttribute("defaultdata");

Thats it, that should do it!

Now, the only problem I can forsee, is that the default data is loaded after the page loads..
so the onload javascript wont  work, but this is unlikely on the other hand, I dont know
much javascript *shrug*

Good luck! Until tomorrow!
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12333300
Argh, I almost forgot, this
DynaActionForm tradeSearchForm = (DynaActionForm)request.getAttribute("defaultdata");
wont work, because default data isnt a form, but a String array, youll need a method
do it the normal way, but instead of doing this:

  tradeSearchForm.set("tradeDateFrom", String.valueOf(prevBusinessDate));
          tradeSearchForm.set("tradeDateTo", String.valueOf(currentDt));
          tradeSearchForm.set("reconSource", "Dollar");

use the data you have in the string array to fill the defaults.

Now, if this are the standard always default data just ignore everything and just call
the action with the reset button. Now, if your problem is that because there are two
buttons inside the form you dont know how to redirect the data...well, use a javascript
function to hardcode the action='<%=forward%>' from the <html:form>
when you click the reset or the submit button.. using onclick javascript functions
if this is your problem, ill elaborate tomorrow.

Ok, shutting up now.

Bye.
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12335142
Oi...im sorry about all the comments, but thinking it more throughly, you can do the
reset button with Javascript, do the onload bit, store the data, and then on the onclick
method of the reset button, set the form values (I dont know if the page has to reload tho)
This way you wont have to attach object anywhere, just get the info from the form, store
it while the user makes his input, if he clicks the reset button, do the method that sets the
inputs to the default values stored at form load.

Just a thought.

Bye.
0
 

Author Comment

by:shivani
ID: 12337461
Celdric,

Thanks for all your comments..

What I understand from above is as below, Let me know if I have misunderstood this,

you are saying to write a javascript function which sets the array of default values onLoad of a form.. When user clicks on RESET button, just use this function to get default values and use this to reset the form..

Firstly to build this string[] javascript array -- How to do it? This would bascially mean again hard-coding the default values in JS.. I ofcourse cannot use DYNAFORM default values to populate this js array because DYNAFORM will keep changing its values after user clicks on SUBMIT.. well!! I don't want to hard-code the value at 2 places now -- in Action form ( where I added the line for Dollar) and now in JS also, because, firstly, if default changes, we will have to maintain at 2 places -- and second, some default values are calculated based on some JDBC values, which I cannot do via JS..


Have I misunderstood your solution, so it there a some other good way to do it?

Regards
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12337854
How about using JSP?
Im not 100% sure, but i thinkyou can use a struts tag to call JSP functions, this way
you could make 2 functions:
1) To store the data from the input values from default (on load)
2)A method to load the data you got from on Load to the parameters.

Remember that the form is an object (check the JavaScript link I gave you)
So, when it loads its already populated from the DynaForm, you just make an iteration and
scan all inputs of the form withing the document (I believe its document[0].form[0])
and store it within your String Array.

When the reset button is clicked, you iterate again the whole form, but this time instead of
getting the values, you replace em..

This whole solution depends on 1 thing:
The values from the input field must be already populated when the onload method is called.

If I were you I would try it with JS first then JSP.

Good luck, Ill check on you on lunch hour (5 hours from now)


0
 

Author Comment

by:shivani
ID: 12338249
I will try JS first before JSP,

But Celdric,

I have 1 confusion..

say for 1st time, user clicks on tab, and page is loaded with value of

RECON SOURCE field = 'DOLLAR'.

and so our JS script has document.form(recon_soucee).value='Dollar' Right?
(ignore the syntax for now)

now on reset..

we will do

document.form(recon_source).value=Dollar

Right??

and I got it, it will reset the value..

Now after user clicks on TAB, and page is loaded for 1st time and Recon_Souce='Dollar'..

and now if user picks Australia and clicks on Submit. and page is loaded with form and results, now our js script is again invoked (onLoad), but this time, since form (DYNAFORM) has pre-selected value = 'Australia', so our JS script will think that this is a default value (since our array will again be filled in)..

and thus it will have wrong logic right??

How to maintain the JS Script array for the whole application?

hmm, or should I think of using a STRING[] JSP array with scope=application may be??

I don't know how to do it.. but is it on correct direction??

Let me know if I am misunderstanding something here

regards


0
 
LVL 1

Expert Comment

by:Celdric
ID: 12338392
I still dont get how the form and the buttons are supposed to work..maybe you can explain
to me a little more about the functionality of it all, I might be able to give you better ideas :)

On this:
>and now if user picks Australia and clicks on Submit. and page is loaded with form and results, >now our js script is again invoked (onLoad), but this time, since form (DYNAFORM) has pre->selected value = 'Australia', so our JS script will think that this is a default value (since our >array will again be filled in)..

Yep, youre correct, so from this I infer that the funtionality of the reset button is to load
the first state of the form and not the previous one?

You could always do a boolean, that switches the first time the user logs in, this way the
"default" values wont ever be replaced. *shrug*

Lets keep it going, I want to see this through ;)
[Ill keep MSN open to see if you reply]

Bytes!
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12338403
Write a static getInitialValues() function in your one of your classes.  The class must be accessible to the JSP (through an import) and to your Action class that is currently setting the defaults.

In that class, the getInitialValues() function, do something like this:

public static HashTable getInitialValues() {
   HashTable initMap = new HashTable();
   
   //set the defaults
   initMap.add("reconSource", "Dollar");
   //... add any other defaults
}


From your Action class, do this:
(Note that I called the class SomeClass.  Replace that with the name of the class that you put the method in.)

//...
HashTable initMap = SomeClass.getInitialValues();

this.reconSource = initMap.get("reconSource");
//... repeat for any other defaults


In your JSP, add the following to your JavaScript function

<% HashTable initMap = SomeClass.getInitialValues(); %>

function loadDefaults(){
   document.form(recon_source).value="<%=initMap.get("reconSource")%>";
   '... repeat for any other defaults

}
0
 

Author Comment

by:shivani
ID: 12339892
Hey all,

I am working on above both suggestions,

but just curios since somebody gave me this suggestion here but don't know how to implement it..

like struts renders html initially as

<input type=text name="test" value="111"></input>

(say for example "111" is default value from dynaform set as
tradeSearchForm.set("test", "111");


and once we submit the form, it becomes

<input type=text name="test" value="888"></input>


So our reset gets messed up, since it doesn't have information about "111" anymore..

is there a way something as below

<input type=text name=test value="111">888</input

so that default value doesn't change but display value is 888 (or object curr value is 888).

I mean is this something feasible..

guy told me that this is something feasible, but didn't know how to implement it..

if this is possible, this would bebest solution..

let me know pls,

if not feasible, I will have to get this JS way first, since this is fast -- (client side), I will need some help with this soon, since need some suggestion on this ..
0
 

Author Comment

by:shivani
ID: 12340216
CELDRIC Any ideas on above recommendation?

Rick?

Anybody?
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12340254
As far as I know, that isn't possible.  The "value" attribute of an input tag is intended to be the actual value, not just the initial value.

Sorry.
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12340272
Whoa, sorry about that ;) I think Struts is very strict about how it "translates"
its tags to normal HTML, I dont think its feasible... (I hope someone who knows more
about this contradicts me) but I dont know that much to do your solution using Struts tags.

Im on a blank there...so, can you explain the whole JSP layout for me, because
im still not clear about the buttons' functionality.

0
 

Author Comment

by:shivani
ID: 12340538
well,

I don't know much about JSP layout as well since I have never worked on struts and know only a bit about JAVA/JSP, so I will explain you watever I see it here, and may be you can interpret it and explain me in better way.. I will explain you as soon as I reach back the office (in few mins), since I have to browse to pages to really put JSP layout here ..

well, since both of you have said almost "NOT POSSIBLE" to above recommendation, so may be it cannot be implemented.. but in case you guys work with many other tech guys over at your place, if you find it that this can be implemented, pls let me know ASAP, since this would be I guess ideal solution for me..

Why ideal solution -- Because -- like I have given u example of 1 form (page), I have many other pages and "Reset" button all over, and I have to do similar thing in all the pages, so if I do like JS way etc, I will have to do it in all pages, since in all pages, default values, name of form objects etc are different..
So any help with implementing would be idea approach for me.. let me know if you find out anything for any of your friends, any other guys here at this forum etc..

Thanks


Well, I will try the js way now as soon as I am back.. (in few mins) and will ask u questions..

Thanks buddies for all your help here
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12345007
Shivani,

Sorry, just get back to EE. I will try my Reset button and see what I can do for you.

Dave
0
 

Author Comment

by:shivani
ID: 12345154
Supra,

Let me know if you have any solution for
transforming html from struts as below


<input type=text name=test value="111">888</input>

Thus default value remains 111, and selected value becomes 888.

see my above comment for details..

Celdric, I know I told u that I have give u JSP layout here, but I got trapped with some work, that I could not do it, but I need to give it to you so that you can help me understand how this is working here.. I am sorry about it..

I am right now working on js script, seems to be working well for me..

I just created 2 js functions

clearForm (to empty all fields)
loadDefaults (to load default values)


below are functions I intend to use:

function clearTextSelectFieldsForm(){
  var len = document.forms[0].elements.length;
  for (var i=0; i<len ; i++ ){
  if (document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'select'){
   document.forms[0].elements[i].value = '';
  }
 }


function loadDefaults(){
   document.forms[0].elements["tradeDateFrom"].value = "<%=String.valueOf(prevBusinessDate)%>";
   document.forms[0].elements["reconSource"].value="Dollar";
   document.forms[0].elements["tradeDateTo"].value=<%=String.valueOf(currentDt)%>
 }


inside my jsp, i have

<%@ page language="java" import="java.text.SimpleDateFormat,java.util.Date"%>
<%@ page language="java" import="com.citi.soft.util.BusinessDate"%>


<%
      SimpleDateFormat dtFormat = new SimpleDateFormat("yyyyMMdd");
      String currentDt = dtFormat.format(new Date());
      long prevBusinessDate = 0L;
      try {
        prevBusinessDate =
        BusinessDate.getInstance().getPreviousBusinessDate(
                                                  BusinessDate.US, currentDt);
        } catch(Exception ex) {
           ex.printStackTrace();
          }

%>


well, any suggestions to do it better way, I don't really like it, since it is too much hard-coding looks like, but let me know if there is any better and easy way to do it..

Celdric, I will be posting JSP stuff here soon, and woud really appreciate if you can explain me some of it, will give me understanding about struts, and would be help..

I guess when u say JSP LAYOUT, you mean, what URL i hit, and what is in xml file, and what is in action in brief,   thats what u want right?
0
 

Author Comment

by:shivani
ID: 12345186
Ok,

Just figured out, that I had to change

in my below script

function clearTextSelectFieldsForm(){
  var len = document.forms[0].elements.length;
  for (var i=0; i<len ; i++ ){
  if (document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'select'){
   document.forms[0].elements[i].value = '';
  }
 }

  if (document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'select'){


to

  if (document.forms[0].elements[i].type == 'text' || document.forms[0].elements[i].type == 'select-one'){


Looks like this soln is working right now.. i will test it more


let me know if there is something better i can do here



0
 
LVL 1

Expert Comment

by:Celdric
ID: 12346398
By JSP layout, I mean whic tags are you using in the form, and how manye= html:forms
are there, inputs, etc.. but if the JS solution is working, then we are all set :D

Im glad some of my ideas helped you at all ;)
0
 
LVL 4

Expert Comment

by:Rick_Townsend
ID: 12429412
Shivani, if this question is solved, please allocate points and close the question.  Looks like Celdric gave you the most help, so he should probably get most of the points.  (Although, if I'm being honest, I feel I should get some points too.  I do have some ego!)
:)
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12432767
I agree :D
0
 

Author Comment

by:shivani
ID: 12472735
Hey All,
Sorry for the delay.

This question is solved.. I appreciate all the help I got because of which I was able to solve my problem here.

I will allocate the points now.

Problem is solved, however, Celdric, I would really appreciate if I can get some additional help from you to understand the architecture here .. As I told you, I know some of Java (not alot). Here they are using JAVA-JSP-STRUTS-JSLT ETC ETC. I don't understand how a request is transfered from webpage to server to back .. etc.. I mean the overflow..

would you be kind to help me understand that..

I can desribe you in an email exactly what is happning, what page I am hitting , and response I am getting.. and together we can understand it more..

But experts-exchange forum would not be right place to discuss this since this is some specific to me, not generic helpful to public.. do you agree..?? would you share email adress to help me with this, if you cannot I understand!!

Best Regards and Thanks everybody for all your help again!

0
 
LVL 1

Expert Comment

by:Celdric
ID: 12472882
my mail is my nickname at hotmail.
I dont want to post it because of spam bots, buts its easy to figure out :D
Sure, Ill be happy to be your pen-pal and help you with your questions.
You can add me to MSN, Im sure chatting after the inital mail explaining the desgin flow will
be more dynamic.

Regards!
0
 

Author Comment

by:shivani
ID: 12474751
well, thanks celdric , problem is I cannot directly chat.. since no IM (instant messaging) works (they have been blocked here).. so I have to email you.. unless you know some trick which can help me configuring msn so that it works..:)

anyway, I will email you soon.. and may be we can exchange emails ... is it okay? or actually i can chat with you in the night (usa time), not sure what time would be in your country.. do you know if this would be okay to you?
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12475334
Im afraid I cant chat at night, no comp at home (kinda healty, infront of comp all day)
Im on U.S. Central time, and about MSN
check this link:
http://webmessenger.msn.com/

Read ya later! :D
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now