RE: Generating logs w/Log4J in ActionClass

2003-08-24 Thread Kapadia Mitesh-C23457
Thanks Navjot -

Quick question -- are you sure the .properties file must be in your classpath?

-Original Message-
From: Navjot Singh [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 22, 2003 10:10 AM
To: Struts Users Mailing List
Subject: RE: Generating logs w/Log4J in ActionClass


i just vaguely remember
private Logger logger = Logger.getLogger(Test.class); logger.debug(Better Check log4j 
docs);

and keep the log4j.properties file in classpath.

hth
navjot singh


|-Original Message-
|From: Kapadia Mitesh-C23457 [mailto:[EMAIL PROTECTED]
|Sent: Thursday, August 21, 2003 9:25 PM
|To: [EMAIL PROTECTED]
|Subject: Generating logs w/Log4J in ActionClass
|
|
|I have the appropriate configurations completed to use Log4J w/Tomcat.
|However, how would I invoke Log4J from within my action class to generate
|DEBUG statements? 
|I have the following package imported: 
|import org.apache.log4j.*; 
|Any examples would be most appreciated. 
|Thanks in advance. 
|- Mitesh 
|

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: validation, input page, and request-scoped variables

2003-08-24 Thread ll
Thanks for the reply. So in your save action your form input is the 
action that sets up the form. Meaning that in your struts-config for 
the save action you have input=/edit.do or input=/add.do...? Which 
one do you choose?

Also, as I understand it, this can only work if the action doesn't set 
any of the form fields. Do your actions set any form fields? If not, 
then I guess you can always use the add action. But in my case the 
add action sets some values (for example to preselect a default item in 
an options list), and of course the edit action also sets values (it 
looks up the values from the database).  So after submitting, if the 
validation fails, the form field values are changed, they are not what 
the user just typed.

Or am I misunderstanding something?

Thanks...

On Saturday, Aug 23, 2003, at 13:42 Canada/Eastern, Adam Hardy wrote:

Hi II
I use your method 1. My add and edit actions use the same JSP and both 
submit to the same save action. In my add, I set the id to 0, so on 
save, it knows that this is an add and not an edit.

I had to make a decision not to allow 0s as ids in the database. 
Possibly I could have used a negative number instead, as long as it 
validates.

Adam

On 08/23/2003 07:29 PM ll wrote:
Here's my problem: I have a form page that uses some request-scoped 
attributes for some things it shows on the page (other than the form 
field data). I always access the page through an action which sets up 
the attributes. But if validation fails when I submit the form, then 
those request attributes no longer exist because the input forwards 
to the jsp page without going through the action again.
Two possible solutions:
1. On the save action, use input=/person/add so that when 
validation fails control is forwarded back through the action, which 
can then set up the request attributes again.
- problem: I use the same page from an edit action, which takes a 
person id parameter and pre-fills the form. If I do it this way I 
will need two save actions, one that uses the edit page as the 
input and one that uses the add page as the input. Then the form 
can't be shared, because I the submit action will need to change 
depending on whether it is an add or an edit.
2. Store the attributes in the session instead of the request.
- problem: if the user has two browser windows open to the same form 
then the values displayed in the page could be wrong because they are 
shared
- problem: these attributes won't get removed later from the request 
(without a lot of work on my part)
Has anyone else encountered this problem? How do most people do this?
Thanks!
This is roughly what my struts-config setup looks like:
action path=/person/add
type=mypackage.PersonAction
name=PersonalInfoForm
scope=request
validate=false
parameter=personalInfoFormBlank
forward name=continue 
path=/WEB-INF/docs/jsp/person/personalInfoForm.jsp/
/action
action path=/person/edit
type=mypackage.PersonAction
name=PersonalInfoForm
scope=request
validate=false
parameter=personalInfoFormFilled
forward name=continue 
path=/WEB-INF/docs/jsp/person/personalInfoForm.jsp/
/action
action path=/person/savePersonalInfo
type=mypackage.PersonAction
name=PersonalInfoForm
scope=request
input=/WEB-INF/docs/jsp/person/personalInfoForm.jsp
parameter=personalInfoFormSubmit
forward name=continue path=/app/main/
/action
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
struts 1.1 + tomcat 4.1.27 + java 1.4.2
Linux 2.4.20 RH9
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: How to dynamically decide the properties of the DynaValidator/DynaActionForm

2003-08-24 Thread R Balaji
well, in the jsp, i would be getting all the dynaproperties.. and be 
enumerating them while printing the keys and values in the UI. I managed 
to to do this, and able to display the bean details.

I too realized that i should handle the reset method. I will try that.

Yes, my business tier will give the information regarding the valid 
values of each attribute. I believe that i can use this for validating 
the properties. But i too do not know how far i can use dynavalidator 
and the validation framework.

Do you have any suggestions other than my  current dynamic bean 
population design ?.

Regards,
R Balaji


Adam Hardy wrote:

I read your solution for populating the dynaform. How do you display 
it in JSP? I mean, how does the JSP know what the field names are?

I don't really know the internal workings of the dynavalidator form 
and how struts would populate the form bean with request parameters. 
You would probably have to do the same formbean initialization in the 
bean's reset method, otherwise the request parameters will probably 
not get saved to it.

Once you get that far, then validation becomes an issue. At design 
time you don't what the fields of a form will be - but do you know how 
any particular type of field should be validated? If so, how do you 
know? Is that in the design?

Adam

On 08/23/2003 05:34 PM R Balaji wrote:

Yes, Adam .. this is a valid point , that i need to consider.

But, it is almost impossible to define a bean for each type of data, 
in my application. I need to use the dynabean and dynaclass , some how.

I managed to find a solution for populating the bean ,  now i have to 
find a solution for validation too.

Suggest me  a suitable validation approach..

With Regards,
R Balaji
Adam Hardy wrote:

I can see that you could just iterate over the unknown form 
properties in the JSP, but how would you label them? And when the 
form is submitted, how would you validate them?

I think you would be better advised to add your list of properties 
as beans to your form. In each bean you could also have a label and 
a validation.

my 2 cents.
Adam


On 08/23/2003 12:03 PM Mark Lowe wrote:

You cant dynamically add properties to DynaActionForms. I'm not 
sure  why you've a problem with just adding the fields to you form 
bean in  struts config. I've demonstrated how to literally do what 
you want, but  you'd have to specify the properties you want in you 
jsp anyway. But  here goes

You could create a new form bean copy the properties across from 
you  old one and then add some new stuff..

DynaActionForm oldForm = (DynaActionForm) form;

//get the map out and mess with this and life should be simpler 
that  using the dynaBean
Map oldFormMap = oldForm.getMap();

oldFormMap.put(statusChangeTime,A new Time);

DynaActionForm newForm = new DynaActionForm();

BeanUtils.populate(newForm, oldFormMap);

If this doesn't work you can try constructing all you dyna 
properties,  having a DynaProperty[] array and then use the 
dynaBean constructer  that takes a properties array.

Cheers Mark

On Saturday, August 23, 2003, at 04:42 AM, R Balaji wrote:

Dear All,
I have an application which returns a varity of properties, which 
can  not be decided at design time. I would like to populate the 
Business  data into a dynaValidatorForm and display them.

In this case, it is not possible to  specify all the properties 
as  form-property. If i set  properties, without specifying them 
in the  struts-config.xml, i am getting exception as mentioned below.

java.lang.IllegalArgumentException: Invalid property name  
'statusChangeTime'
at  
org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm. 
java:598)
at  
org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:412)
at  
com.adventnet.nms.webclient.topo.details.ObjectDetailsHandler.populateV 
iewBean(ObjectDetailsHandler.java:63)
at  
com.adventnet.nms.webclient.topo.details.ObjectDetailsHandler.fetchObje 
ctDetails(ObjectDetailsHandler.java:49)
at  
com.adventnet.nms.webclient.topo.details.ObjectDetailsAction.execute(Ob 
jectDetailsAction.java:54)

Please help me , in this regards,

Thanks in Advance.
With Regards,
R Balaji
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






Re: Tiles Definition problem

2003-08-24 Thread [EMAIL PROTECTED]
Bryce,

You don't have to write the path wbeginning witha a slash.

Try this:

forward name=defaulttile redirect=true path=default.layout/

Antonio Gonzalez


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



bean:message to fmt:message

2003-08-24 Thread Erez Efrati

In my resource properties file I have key in the following format:

button.next=xxx
..

I am trying to move from bean:message key=button.next / which works
just fine, to fmt:message value=button.next /

And I get the following error:

Attribute value invalid according to the specified TLD' 

Why? Can't fmt:message accept these kind of keys (with a dot char)?

Thanks,
Erez



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to dynamically decide the properties of the DynaValidator/DynaActionForm

2003-08-24 Thread Adam Hardy
Concerning the validation, what you do depends on whether all the 
possible different validation mechanisms are limited to a defined set, 
or whether it is an unbounded set that you cannot limit at design time.

On 08/24/2003 07:06 AM R Balaji wrote:
well, in the jsp, i would be getting all the dynaproperties.. and be 
enumerating them while printing the keys and values in the UI. I managed 
to to do this, and able to display the bean details.

I too realized that i should handle the reset method. I will try that.

Yes, my business tier will give the information regarding the valid 
values of each attribute. I believe that i can use this for validating 
the properties. But i too do not know how far i can use dynavalidator 
and the validation framework.

Do you have any suggestions other than my  current dynamic bean 
population design ?.

Regards,
R Balaji


Adam Hardy wrote:

I read your solution for populating the dynaform. How do you display 
it in JSP? I mean, how does the JSP know what the field names are?

I don't really know the internal workings of the dynavalidator form 
and how struts would populate the form bean with request parameters. 
You would probably have to do the same formbean initialization in the 
bean's reset method, otherwise the request parameters will probably 
not get saved to it.

Once you get that far, then validation becomes an issue. At design 
time you don't what the fields of a form will be - but do you know how 
any particular type of field should be validated? If so, how do you 
know? Is that in the design?

Adam

On 08/23/2003 05:34 PM R Balaji wrote:

Yes, Adam .. this is a valid point , that i need to consider.

But, it is almost impossible to define a bean for each type of data, 
in my application. I need to use the dynabean and dynaclass , some how.

I managed to find a solution for populating the bean ,  now i have to 
find a solution for validation too.

Suggest me  a suitable validation approach..

With Regards,
R Balaji
Adam Hardy wrote:

I can see that you could just iterate over the unknown form 
properties in the JSP, but how would you label them? And when the 
form is submitted, how would you validate them?

I think you would be better advised to add your list of properties 
as beans to your form. In each bean you could also have a label and 
a validation.

my 2 cents.
Adam


On 08/23/2003 12:03 PM Mark Lowe wrote:

You cant dynamically add properties to DynaActionForms. I'm not 
sure  why you've a problem with just adding the fields to you form 
bean in  struts config. I've demonstrated how to literally do what 
you want, but  you'd have to specify the properties you want in you 
jsp anyway. But  here goes

You could create a new form bean copy the properties across from 
you  old one and then add some new stuff..

DynaActionForm oldForm = (DynaActionForm) form;

//get the map out and mess with this and life should be simpler 
that  using the dynaBean
Map oldFormMap = oldForm.getMap();

oldFormMap.put(statusChangeTime,A new Time);

DynaActionForm newForm = new DynaActionForm();

BeanUtils.populate(newForm, oldFormMap);

If this doesn't work you can try constructing all you dyna 
properties,  having a DynaProperty[] array and then use the 
dynaBean constructer  that takes a properties array.

Cheers Mark

On Saturday, August 23, 2003, at 04:42 AM, R Balaji wrote:

Dear All,
I have an application which returns a varity of properties, which 
can  not be decided at design time. I would like to populate the 
Business  data into a dynaValidatorForm and display them.

In this case, it is not possible to  specify all the properties 
as  form-property. If i set  properties, without specifying them 
in the  struts-config.xml, i am getting exception as mentioned below.

java.lang.IllegalArgumentException: Invalid property name  
'statusChangeTime'
at  
org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm. 
java:598)
at  
org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:412)
at  
com.adventnet.nms.webclient.topo.details.ObjectDetailsHandler.populateV 
iewBean(ObjectDetailsHandler.java:63)
at  
com.adventnet.nms.webclient.topo.details.ObjectDetailsHandler.fetchObje 
ctDetails(ObjectDetailsHandler.java:49)
at  
com.adventnet.nms.webclient.topo.details.ObjectDetailsAction.execute(Ob 
jectDetailsAction.java:54)

Please help me , in this regards,

Thanks in Advance.
With Regards,
R Balaji
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--
struts 1.1 + tomcat 4.1.27 + java 1.4.2
Linux 2.4.20 RH9
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: 

RE: bean:message to fmt:message

2003-08-24 Thread Erez Efrati
Oops, sorry I mixed up key with value, 

I still get ???MyForm.title??? on fmt:message key=MyForm.title /

In my web.xml I put as documented in JSTL specs:

  context-param
param-namejavax.servlet.jsp.jstl.fmt.localizationContext
a/param-name
param-valueresources.application/param-value
  /context-param

This all works with bean:message. 
Any ideas why?

Erez

-Original Message-
From: Erez Efrati [mailto:[EMAIL PROTECTED] 
Sent: Sunday, August 24, 2003 1:20 PM
To: 'Struts Users Mailing List'
Subject: bean:message to fmt:message


In my resource properties file I have key in the following format:

button.next=xxx
..

I am trying to move from bean:message key=button.next / which works
just fine, to fmt:message value=button.next /

And I get the following error:

Attribute value invalid according to the specified TLD' 

Why? Can't fmt:message accept these kind of keys (with a dot char)?

Thanks,
Erez



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: validation, input page, and request-scoped variables

2003-08-24 Thread Adam Hardy
Ah, I see I missed out a bit of the logic.

My action class has a part that is executed for every action mapping, 
which fetches the necessary related data, such as dropdown lists (but 
not the actual object's properties).

What else the action does is dependent on the result of a bit of logic 
which is executed after the mandatory processing mentioned above.

I'm having problems describing it, perhaps it's easier to understand 
just looking at the xml:

actionpath=/secure/startSectionInsert
   type=org.blacksail.linklib.section.SectionAction
   name=sectionForm
  scope=request
   validate=false
  parameter=blank
  roles=user
  set-property property=secure value=false/
  forward name=finished   path=.section/
/action
actionpath=/secure/startSectionUpdate
   type=org.blacksail.linklib.section.SectionAction
   name=sectionForm
  scope=request
   validate=false
  parameter=display
  roles=user
  set-property property=secure value=false/
  forward name=finished   path=.section/
/action
actionpath=/secure/sectionUpdate
   type=org.blacksail.linklib.section.SectionAction
   name=sectionForm
  scope=request
   validate=true
  parameter=save
  input=/secure/sectionValidateFailed.do
  roles=user
  set-property property=secure value=false/
  forward name=failed path=.section/
  forward name=displaypath=/secure/startSectionUpdate.do/
  forward name=finished   path=/secure/library.do 
redirect=true/
/action
actionpath=/secure/sectionValidateFailed
   type=org.blacksail.linklib.section.SectionAction
   name=sectionForm
  scope=request
  parameter=finished
  roles=user
  set-property property=secure value=false/
  forward name=finished   path=.section/
/action

Both insert and update submit to update. The last mapping there just 
does the mandatory getting the required dropdown lists.

HTH
Adam
On 08/24/2003 02:13 AM ll wrote:
Thanks for the reply. So in your save action your form input is the 
action that sets up the form. Meaning that in your struts-config for the 
save action you have input=/edit.do or input=/add.do...? Which one 
do you choose?

Also, as I understand it, this can only work if the action doesn't set 
any of the form fields. Do your actions set any form fields? If not, 
then I guess you can always use the add action. But in my case the add 
action sets some values (for example to preselect a default item in an 
options list), and of course the edit action also sets values (it looks 
up the values from the database).  So after submitting, if the 
validation fails, the form field values are changed, they are not what 
the user just typed.

Or am I misunderstanding something?

Thanks...

On Saturday, Aug 23, 2003, at 13:42 Canada/Eastern, Adam Hardy wrote:

Hi II
I use your method 1. My add and edit actions use the same JSP and both 
submit to the same save action. In my add, I set the id to 0, so on 
save, it knows that this is an add and not an edit.

I had to make a decision not to allow 0s as ids in the database. 
Possibly I could have used a negative number instead, as long as it 
validates.

Adam

On 08/23/2003 07:29 PM ll wrote:

Here's my problem: I have a form page that uses some request-scoped 
attributes for some things it shows on the page (other than the form 
field data). I always access the page through an action which sets up 
the attributes. But if validation fails when I submit the form, then 
those request attributes no longer exist because the input forwards 
to the jsp page without going through the action again.
Two possible solutions:
1. On the save action, use input=/person/add so that when 
validation fails control is forwarded back through the action, which 
can then set up the request attributes again.
- problem: I use the same page from an edit action, which takes a 
person id parameter and pre-fills the form. If I do it this way I 
will need two save actions, one that uses the edit page as the 
input and one that uses the add page as the input. Then the form 
can't be shared, because I the submit action will need to change 
depending on whether it is an add or an edit.
2. Store the attributes in the session instead of the request.
- problem: if the user has two browser windows open to the same form 
then the values displayed in the page could be wrong because they are 
shared
- problem: these attributes won't get removed later from the request 
(without a lot of work on my part)
Has anyone else encountered this problem? How do most people do this?
Thanks!
This is roughly what my struts-config setup looks like:
action path=/person/add
type=mypackage.PersonAction
name=PersonalInfoForm

Re: bean:message to fmt:message

2003-08-24 Thread Adam Hardy
Hi Erez,

had similar problems myself. Specifying the application resources in 
web.xml didn't work for me for hours because I'd spelt it wrong - 
perhaps you should check you have it spelt correctly (is that really a 
small r for resources.application, and with a dot? could it be 
resourceApplication.properties?) I think tomcat looks for a class with 
the extension .properties

Plus the param-name looks a bit messed up, although that's probably just 
a cut  paste slip-up.

Try seeing if the fmt:message tag can find it by placing the bundle 
attribute on the tag itself.



On 08/24/2003 01:28 PM Erez Efrati wrote:
Oops, sorry I mixed up key with value, 

I still get ???MyForm.title??? on fmt:message key=MyForm.title /

In my web.xml I put as documented in JSTL specs:

  context-param
param-namejavax.servlet.jsp.jstl.fmt.localizationContext
a/param-name
param-valueresources.application/param-value
  /context-param
This all works with bean:message. 
Any ideas why?

Erez

-Original Message-
From: Erez Efrati [mailto:[EMAIL PROTECTED] 
Sent: Sunday, August 24, 2003 1:20 PM
To: 'Struts Users Mailing List'
Subject: bean:message to fmt:message

In my resource properties file I have key in the following format:

button.next=xxx
..
I am trying to move from bean:message key=button.next / which works
just fine, to fmt:message value=button.next /
And I get the following error:

Attribute value invalid according to the specified TLD' 

Why? Can't fmt:message accept these kind of keys (with a dot char)?

Thanks,
Erez


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
struts 1.1 + tomcat 4.1.27 + java 1.4.2
Linux 2.4.20 RH9
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: bean:message to fmt:message

2003-08-24 Thread Erez Efrati
Hi Adam,

I found what was the problem but was a bit ashamed of telling :)
I was missing the locale settings in my web.xml. 

  context-param
param-namejavax.servlet.jsp.jstl.fmt.locale/param-name
param-valueiw/param-value
  /context-param

Now it all works just fine,

Erez

-Original Message-
From: Adam Hardy [mailto:[EMAIL PROTECTED] 
Sent: Sunday, August 24, 2003 12:50 PM
To: Struts Users Mailing List
Subject: Re: bean:message to fmt:message

Hi Erez,

had similar problems myself. Specifying the application resources in 
web.xml didn't work for me for hours because I'd spelt it wrong - 
perhaps you should check you have it spelt correctly (is that really a 
small r for resources.application, and with a dot? could it be 
resourceApplication.properties?) I think tomcat looks for a class with 
the extension .properties

Plus the param-name looks a bit messed up, although that's probably just

a cut  paste slip-up.

Try seeing if the fmt:message tag can find it by placing the bundle 
attribute on the tag itself.



On 08/24/2003 01:28 PM Erez Efrati wrote:
 Oops, sorry I mixed up key with value, 
 
 I still get ???MyForm.title??? on fmt:message key=MyForm.title /
 
 In my web.xml I put as documented in JSTL specs:
 
   context-param
 param-namejavax.servlet.jsp.jstl.fmt.localizationContext
 a/param-name
 param-valueresources.application/param-value
   /context-param
 
 This all works with bean:message. 
 Any ideas why?
 
 Erez
 
 -Original Message-
 From: Erez Efrati [mailto:[EMAIL PROTECTED] 
 Sent: Sunday, August 24, 2003 1:20 PM
 To: 'Struts Users Mailing List'
 Subject: bean:message to fmt:message
 
 
 In my resource properties file I have key in the following format:
 
 button.next=xxx
 ..
 
 I am trying to move from bean:message key=button.next / which
works
 just fine, to fmt:message value=button.next /
 
 And I get the following error:
 
 Attribute value invalid according to the specified TLD' 
 
 Why? Can't fmt:message accept these kind of keys (with a dot char)?
 
 Thanks,
 Erez
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

-- 
struts 1.1 + tomcat 4.1.27 + java 1.4.2
Linux 2.4.20 RH9


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



How to get Messages Resources from the validate method?

2003-08-24 Thread [EMAIL PROTECTED]
In order to avoid using the deprecated getResources method from the 
ActionServlet, I would like to know how to get access to the module 
message resources bundles configured in the struts-config.xml from the 
ActionForm validate method.

Thanks.

Antonio Gonzalez




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: How to dynamically decide the properties of the DynaValidator/DynaActionForm

2003-08-24 Thread Mark Lowe
Okay .. I've been thinking about this.

I think it might work something like this..

form-property name=beans property=java.util.ArrayList /

The arrayList will be a container for your beans with indexed  
properties.

So in jsp we're thinking, or aiming for

logic:iterate id=bean name=myForm property=beans
bean:write name=bean property=key[%= index %] /
html:text name=bean property=value[%= index %]  /
/logic:iterate
So we have a bean thats mapped backed, or something here's some pseudo  
code.

public class MyBean {

	private Map map;

public Object[] getKeys() {
return map.keySet().toArray();
}

public Object[] getValues() {
ArrayList list = new ArrayList();
Object[] keys = getKeys();

for(int i = 0;i  keys.length;i++) {
String value = map.get(keys[i].toString());
list.add(value);
}

return list.toArray();
}
public String getKey(int i) {
return keys[i].toString();  
}

public String getValue(int i) {
String key = getKey(i);
return map.get(key);
}
public void setKey(int i, String str) {
keys[i] = str;
}
public void setValue(int i , String str) {
map.put(getKey(i),str);
}
...
well you get the idea..
Am I tree barking, smoking crack or something but Its starting look  
possible.. el should help move the scriptlets out, but using indexed,  
mapped properties looks like it may do the job.. the bean could have a  
double sided array it returns to keep the keys and values in the  
correct order. The keys are after all the illusion that the properties  
have names, when really they are associated via index. When it comes  
time to write to a db or something the bean could return a map and the  
key=value pairs should all be there ready.

Cheers mark

On Saturday, August 23, 2003, at 06:51 PM, Adam Hardy wrote:

I read your solution for populating the dynaform. How do you display  
it in JSP? I mean, how does the JSP know what the field names are?

I don't really know the internal workings of the dynavalidator form  
and how struts would populate the form bean with request parameters.  
You would probably have to do the same formbean initialization in the  
bean's reset method, otherwise the request parameters will probably  
not get saved to it.

Once you get that far, then validation becomes an issue. At design  
time you don't what the fields of a form will be - but do you know how  
any particular type of field should be validated? If so, how do you  
know? Is that in the design?

Adam

On 08/23/2003 05:34 PM R Balaji wrote:
Yes, Adam .. this is a valid point , that i need to consider.
But, it is almost impossible to define a bean for each type of data,  
in my application. I need to use the dynabean and dynaclass , some  
how.
I managed to find a solution for populating the bean ,  now i have to  
find a solution for validation too.
Suggest me  a suitable validation approach..
With Regards,
R Balaji
Adam Hardy wrote:
I can see that you could just iterate over the unknown form  
properties in the JSP, but how would you label them? And when the  
form is submitted, how would you validate them?

I think you would be better advised to add your list of properties  
as beans to your form. In each bean you could also have a label and  
a validation.

my 2 cents.
Adam


On 08/23/2003 12:03 PM Mark Lowe wrote:

You cant dynamically add properties to DynaActionForms. I'm not  
sure  why you've a problem with just adding the fields to you form  
bean in  struts config. I've demonstrated how to literally do what  
you want, but  you'd have to specify the properties you want in you  
jsp anyway. But  here goes

You could create a new form bean copy the properties across from  
you  old one and then add some new stuff..

DynaActionForm oldForm = (DynaActionForm) form;

//get the map out and mess with this and life should be simpler  
that  using the dynaBean
Map oldFormMap = oldForm.getMap();

oldFormMap.put(statusChangeTime,A new Time);

DynaActionForm newForm = new DynaActionForm();

BeanUtils.populate(newForm, oldFormMap);

If this doesn't work you can try constructing all you dyna  
properties,  having a DynaProperty[] array and then use the  
dynaBean constructer  that takes a properties array.

Cheers Mark

On Saturday, August 23, 2003, at 04:42 AM, R Balaji wrote:

Dear All,
I have an application which returns a varity of properties, which  
can  not be decided at design time. I would like to populate the  
Business  data into a dynaValidatorForm and display them.

In this case, it is not possible to  specify all the properties as  
 form-property. If i set  properties, without specifying them in  
the  struts-config.xml, i am getting 

Design question...

2003-08-24 Thread Keith Pemberton
I have a JSP page that contains entries from a database.  I am getting
the items using a DTO that is passed from a session EJB.  What I would
like to be able to do is to specify a parameter in the URL named
offset that when changed would display the next results from the
database.  Couple of questions... Would it be considered presentation
logic to perform the action of getting the DTO from the session bean
within the JSP page?  I really don't want to do it that way because I'm
trying to keep the layers as separate as possible.  So, if I don't do it
that way, I will have to use Action classes and html:links that can pass
the parameter to action class?

My real question is what is the best way of dealing with EJBs in the
presentation layer?  I know that I have to get a DTO of the information
that I want, but usually the methods of the DTO take parameters that I
can't pass to the DTO in the JSP page.  I have read over and over the
Oreilly Struts book but it still is confusing me.  Thanks for any help!

Keith Pemberton
-- 
Keith Pemberton [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



DynaForm Beans and Indexed Text fields.

2003-08-24 Thread Joel
I'm having a problem using Indexed text fields with DynaActionForms. I 
can make a jsp display my indexed text fields just fine using the 
logic:iterate and html:text custom tags. The problem is when I 
submit the form, there is a problem populating the DynaActionForm with 
my indexed text values. I'm wondering if the problem is the fact that 
the collection used is a java.util.List populated with by own custom 
beans, each bean containing three String fields with their own 
getters/setters. I'm wondering if I can use DynaActionForms in this 
instance. Below is a copy of my DynaActionForms Config, the jsp code 
that utilizes the form and the error message I get when the form is 
submitted. Any input would be of great help.

Thanks,

Joel.

Here's my DynaActionForm Bean declaration in struts-config.xml:

form-bean
name=persistRateInfo
type=org.apache.struts.action.DynaActionForm
!-- Specify the dynamic properties of the form --
form-property name=hazardInsRate type=java.lang.String/
form-property name=dealOneTerm type=java.lang.String/
form-property name=dealOneIR type=java.lang.String/
form-property name=dealOnePercentageDown type=java.lang.String/
form-property name=dealTwoTerm type=java.lang.String/
form-property name=dealTwoIR type=java.lang.String/
form-property name=dealTwoPercentageDown type=java.lang.String/
form-property name=dealThreeTerm type=java.lang.String/
form-property name=dealThreeIR type=java.lang.String/
form-property name=dealThreePercentageDown type=java.lang.String/
form-property name=pmiRanges type=java.util.List/
/form-bean
Here's the loop I use in the jsp that needs to display the values of 
pmiRanges. of the form bean:

logic:iterate id=pmiRanges name=persistRateInfo property=pmiRanges
tr
td style=font-family: sans; font-size: 12; width=100Low: /td
td style=font-family: sans; font-size: 12;
html:text name=pmiRanges property=low indexed=true size=5/
/td
td style=font-family: sans; font-size: 12; width=100High: /td
td style=font-family: sans; font-size: 12;
html:text name=pmiRanges property=high indexed=true size=5/
/td
td style=font-family: sans; font-size: 12; width=100Rate: /td
td style=font-family: sans; font-size: 12;
html:text name=pmiRanges property=rate indexed=true size=5/
/td
/tr
/logic:iterate
Now I use a Struts Action to preload this form bean with values from a 
database. It does this fine. When the jsp is called for the first time, 
it utilizes the form bean, and the List perfectly and displays the 
indexed text fields just like I want it to. here is an example row of 
rendered text fields:

tr
td style=font-family: sans; font-size: 12; width=100Low: /td
td style=font-family: sans; font-size: 12;
input type=text name=pmiRanges[0].low size=5 value=10.0
/td

td style=font-family: sans; font-size: 12; width=100High: /td
td style=font-family: sans; font-size: 12;
input type=text name=pmiRanges[0].high size=5 value=15.0
/td
td style=font-family: sans; font-size: 12; width=100Rate: /td
td style=font-family: sans; font-size: 12;
input type=text name=pmiRanges[0].rate size=5 value=5.7
/td
/tr
The problem comes in when I try to submit the form to save the form 
values. It doesn't seem that the form bean can be populated with
the indexed values. I get the follwoing Exception:

?

java.lang.NullPointerException: No indexed value for 'pmiRanges[0]'
at org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:293)
at 
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:474)
at 
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
at 
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)
at 
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Java Question

2003-08-24 Thread Kapadia Mitesh-C23457
 I've been trying to compile my BLB (Business Logic Bean) and have been
 getting errors during compilation.  I haven't a clue as to how I could
 debug this.  Any assistance would be appreciated.
 
 Thanks in advance.
 
 - Mitesh
 
 Error Messages during compilation:
 
 [javac] Compiling 2 source files to
 C:\jakarta-tomcat-4.1.27\webapps\benchmark\WEB-INF\classes
 [javac]
 C:\jakarta-tomcat-4.1.27\webapps\benchmark\WEB-INF\src\net\reumann\OrgIdSe
 rvice.java:56: stmt is already defined in execute(net.reumann.DataHash)
 [javac] Statement stmt =
 conn.createStatement();
 [javac]   ^
 [javac]
 C:\jakarta-tomcat-4.1.27\webapps\benchmark\WEB-INF\src\net\reumann\OrgIdSe
 rvice.java:57: rs is already defined in execute(net.reumann.DataHash)
 [javac] ResultSet rs =
 stmt.executeQuery(SELECT FACIL_ID, FACIL_NAME, FACIL_NAME_SHORT, ORG_ID
 FROM FACILITY WHERE FACIL_ID = ' + facilId + ');
 [javac]   ^
 [javac] 2 errors
 
 Here is the code from my BLB:
 
 package net.reumann;
 
 import java.io.*;
 import java.util.ArrayList;
 import javax.servlet.*;
 import javax.servlet.http.*;
 import java.sql.*;
 import javax.sql.*;
 import net.reumann.*;
 import org.apache.struts.action.Action;
 import org.apache.struts.action.ActionForward;
 import org.apache.struts.action.ActionMapping;
 import org.apache.struts.action.ActionForm;
 import org.apache.log4j.*;
 import org.apache.commons.beanutils.BeanUtils;
 
 
 public class OrgIdService implements Serializable {
 
   //Declare and initialize variables
   Connection conn = null;
   Statement stmt = null;
   ResultSet rs = null;
   ArrayList facilList = new ArrayList();
 
   //The execute() method of OrgIdService is called by OrgIdAction to
 execute a query against the SS Test DB
   public ArrayList execute(DataHash beanHash) {
 
   //Get mode from DataHash
   int mode = beanHash.getMode();
 
   try{
   switch (mode)   {
   case 0:
   
 Class.forName(oracle.jdbc.driver.OracleDriver);
   conn =
 DriverManager.getConnection(jdbc:oracle:thin:@sources:1521:TEST,Test123
 4,Test1234);
   Statement stmt =
 conn.createStatement();
   ResultSet rs =
 stmt.executeQuery(SELECT DISTINCT FACIL_ID FROM FACILITY);
 
   //Read ResultSet into instance of
 FacilBean and add to facilList Array object
   while (rs.next()) {
   FacilBean facil = new
 FacilBean();
   
 facil.setFacilId(rs.getString(FACIL_ID));
   facilList.add(facil);
   }
 
   //Close ResultSet and Connection
 objects
   rs.close();
   conn.close();
   case 1:
   //Extract the facilId from the
 DataHash to query the FACILITY table
   String facilId = (String)
 beanHash.get(FacilId);
 
   
 Class.forName(oracle.jdbc.driver.OracleDriver);
   conn =
 DriverManager.getConnection(jdbc:oracle:thin:@sources:1521:TEST,Test123
 4,Test1234);
   Statement stmt =
 conn.createStatement();
   ResultSet rs =
 stmt.executeQuery(SELECT FACIL_ID, FACIL_NAME, FACIL_NAME_SHORT, ORG_ID
 FROM FACILITY WHERE FACIL_ID = ' + facilId + ');
 
   //Read ResultSet into instance of
 FacilBean and add to facilList Array object
   while (rs.next()) {
   FacilBean facil = new
 FacilBean();
   
 facil.setFacilId(rs.getString(FACIL_ID));
   
 facil.setFacilName(rs.getString(FACIL_NAME));
   
 facil.setFacilName(rs.getString(FACIL_NAME_SHORT));
   
 facil.setOrgId(rs.getString(ORG_ID));
   facilList.add(facil);
   }
 
   //Close ResultSet and Connection
 objects
   rs.close();
   conn.close();
   default:
   return null;
   }//end Switch
   }//end try
   catch (Exception e) {
   return null;
   e.printStackTrace();
   }//end catch
 
   //Return facilList Array Object to 

Re: Java Question

2003-08-24 Thread Dan Tran
Try to import only what you need, not the whole package. It can help you to
trouble shoot this problem

-D
- Original Message - 
From: Kapadia Mitesh-C23457 [EMAIL PROTECTED]
Newsgroups: Struts
Sent: Sunday, August 24, 2003 11:32 AM
Subject: Java Question


  I've been trying to compile my BLB (Business Logic Bean) and have been
  getting errors during compilation.  I haven't a clue as to how I could
  debug this.  Any assistance would be appreciated.
 
  Thanks in advance.
 
  - Mitesh
 
  Error Messages during compilation:
 
  [javac] Compiling 2 source files to
  C:\jakarta-tomcat-4.1.27\webapps\benchmark\WEB-INF\classes
  [javac]
 
C:\jakarta-tomcat-4.1.27\webapps\benchmark\WEB-INF\src\net\reumann\OrgIdSe
  rvice.java:56: stmt is already defined in execute(net.reumann.DataHash)
  [javac] Statement stmt =
  conn.createStatement();
  [javac]   ^
  [javac]
 
C:\jakarta-tomcat-4.1.27\webapps\benchmark\WEB-INF\src\net\reumann\OrgIdSe
  rvice.java:57: rs is already defined in execute(net.reumann.DataHash)
  [javac] ResultSet rs =
  stmt.executeQuery(SELECT FACIL_ID, FACIL_NAME, FACIL_NAME_SHORT, ORG_ID
  FROM FACILITY WHERE FACIL_ID = ' + facilId + ');
  [javac]   ^
  [javac] 2 errors
 
  Here is the code from my BLB:
 
  package net.reumann;
 
  import java.io.*;
  import java.util.ArrayList;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  import javax.sql.*;
  import net.reumann.*;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import org.apache.struts.action.ActionForm;
  import org.apache.log4j.*;
  import org.apache.commons.beanutils.BeanUtils;
 
 
  public class OrgIdService implements Serializable {
 
  //Declare and initialize variables
  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;
  ArrayList facilList = new ArrayList();
 
  //The execute() method of OrgIdService is called by OrgIdAction to
  execute a query against the SS Test DB
  public ArrayList execute(DataHash beanHash) {
 
  //Get mode from DataHash
  int mode = beanHash.getMode();
 
  try{
  switch (mode) {
  case 0:
 
  Class.forName(oracle.jdbc.driver.OracleDriver);
  conn =
 
DriverManager.getConnection(jdbc:oracle:thin:@sources:1521:TEST,Test123
  4,Test1234);
  Statement stmt =
  conn.createStatement();
  ResultSet rs =
  stmt.executeQuery(SELECT DISTINCT FACIL_ID FROM FACILITY);
 
  //Read ResultSet into instance of
  FacilBean and add to facilList Array object
  while (rs.next()) {
  FacilBean facil = new
  FacilBean();
 
  facil.setFacilId(rs.getString(FACIL_ID));
  facilList.add(facil);
  }
 
  //Close ResultSet and Connection
  objects
  rs.close();
  conn.close();
  case 1:
  //Extract the facilId from the
  DataHash to query the FACILITY table
  String facilId = (String)
  beanHash.get(FacilId);
 
 
  Class.forName(oracle.jdbc.driver.OracleDriver);
  conn =
 
DriverManager.getConnection(jdbc:oracle:thin:@sources:1521:TEST,Test123
  4,Test1234);
  Statement stmt =
  conn.createStatement();
  ResultSet rs =
  stmt.executeQuery(SELECT FACIL_ID, FACIL_NAME, FACIL_NAME_SHORT, ORG_ID
  FROM FACILITY WHERE FACIL_ID = ' + facilId + ');
 
  //Read ResultSet into instance of
  FacilBean and add to facilList Array object
  while (rs.next()) {
  FacilBean facil = new
  FacilBean();
 
  facil.setFacilId(rs.getString(FACIL_ID));
 
  facil.setFacilName(rs.getString(FACIL_NAME));
 
  facil.setFacilName(rs.getString(FACIL_NAME_SHORT));
 
  facil.setOrgId(rs.getString(ORG_ID));
  facilList.add(facil);
  }
 
  //Close ResultSet and Connection
  objects
  rs.close();
  conn.close();
  default:
  return null;
  }//end Switch
  }//end try
  catch (Exception e) {
  return null;
  e.printStackTrace();
  }//end catch
 
  //Return facilList Array Object to OrgIdAction
  return facilList;
  }//end Execute () method
  }//end class


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: DynaForm Beans and Indexed Text fields.

2003-08-24 Thread Alex Shneyderman
You should set scope of the bean as session. 

 -Original Message-
 From: Joel [mailto:[EMAIL PROTECTED]
 Sent: Sunday, August 24, 2003 11:59 AM
 To: [EMAIL PROTECTED]
 Subject: DynaForm Beans and Indexed Text fields.
 
 
 I'm having a problem using Indexed text fields with DynaActionForms. I
 can make a jsp display my indexed text fields just fine using the
 logic:iterate and html:text custom tags. The problem is when I
 submit the form, there is a problem populating the DynaActionForm with
 my indexed text values. I'm wondering if the problem is the fact that
 the collection used is a java.util.List populated with by own custom
 beans, each bean containing three String fields with their own
 getters/setters. I'm wondering if I can use DynaActionForms in this
 instance. Below is a copy of my DynaActionForms Config, the jsp code
 that utilizes the form and the error message I get when the form is
 submitted. Any input would be of great help.
 
 Thanks,
 
 Joel.
 
 
 Here's my DynaActionForm Bean declaration in struts-config.xml:
 
 form-bean
 name=persistRateInfo
 type=org.apache.struts.action.DynaActionForm
 
 !-- Specify the dynamic properties of the form --
 form-property name=hazardInsRate type=java.lang.String/
 form-property name=dealOneTerm type=java.lang.String/
 form-property name=dealOneIR type=java.lang.String/
 form-property name=dealOnePercentageDown type=java.lang.String/
 form-property name=dealTwoTerm type=java.lang.String/
 form-property name=dealTwoIR type=java.lang.String/
 form-property name=dealTwoPercentageDown type=java.lang.String/
 form-property name=dealThreeTerm type=java.lang.String/
 form-property name=dealThreeIR type=java.lang.String/
 form-property name=dealThreePercentageDown
type=java.lang.String/
 form-property name=pmiRanges type=java.util.List/
 /form-bean
 
 Here's the loop I use in the jsp that needs to display the values of
 pmiRanges. of the form bean:
 
 logic:iterate id=pmiRanges name=persistRateInfo
property=pmiRanges
 tr
 td style=font-family: sans; font-size: 12; width=100Low: /td
 td style=font-family: sans; font-size: 12;
 html:text name=pmiRanges property=low indexed=true size=5/
 /td
 
 td style=font-family: sans; font-size: 12; width=100High: /td
 td style=font-family: sans; font-size: 12;
 html:text name=pmiRanges property=high indexed=true size=5/
 /td
 
 td style=font-family: sans; font-size: 12; width=100Rate: /td
 td style=font-family: sans; font-size: 12;
 html:text name=pmiRanges property=rate indexed=true size=5/
 /td
 /tr
 /logic:iterate
 
 Now I use a Struts Action to preload this form bean with values from a
 database. It does this fine. When the jsp is called for the first
time,
 it utilizes the form bean, and the List perfectly and displays the
 indexed text fields just like I want it to. here is an example row of
 rendered text fields:
 
 tr
 td style=font-family: sans; font-size: 12; width=100Low: /td
 td style=font-family: sans; font-size: 12;
 input type=text name=pmiRanges[0].low size=5 value=10.0
 
 /td
 
 td style=font-family: sans; font-size: 12; width=100High: /td
 td style=font-family: sans; font-size: 12;
 input type=text name=pmiRanges[0].high size=5 value=15.0
 /td
 
 td style=font-family: sans; font-size: 12; width=100Rate: /td
 td style=font-family: sans; font-size: 12;
 
 input type=text name=pmiRanges[0].rate size=5 value=5.7
 /td
 /tr
 
 The problem comes in when I try to submit the form to save the form
 values. It doesn't seem that the form bean can be populated with
 the indexed values. I get the follwoing Exception:
 
 ?
 
 java.lang.NullPointerException: No indexed value for 'pmiRanges[0]'
   at
 org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:293)
   at

org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt
il
 s.java:474)
   at

org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUt
il
 s.java:428)
   at

org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUti
ls
 .java:770)
   at

org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.jav
a:
 801)
   at
 org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
   at
 org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
 
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Java Question

2003-08-24 Thread Mark Lowe
Read the messages its telling you what's going on..

You've got 2 errors..

1. stmt is already defined
2. that rs is already defined
I don't know how much simpler this could be..

On Sunday, August 24, 2003, at 07:32 PM, Kapadia Mitesh-C23457 wrote:

I've been trying to compile my BLB (Business Logic Bean) and have been
getting errors during compilation.  I haven't a clue as to how I could
debug this.  Any assistance would be appreciated.
Thanks in advance.

- Mitesh

Error Messages during compilation:

[javac] Compiling 2 source files to
C:\jakarta-tomcat-4.1.27\webapps\benchmark\WEB-INF\classes
[javac]
C:\jakarta-tomcat-4.1.27\webapps\benchmark\WEB- 
INF\src\net\reumann\OrgIdSe
rvice.java:56: stmt is already defined in  
execute(net.reumann.DataHash)
[javac] Statement stmt =
conn.createStatement();
[javac]   ^
[javac]
C:\jakarta-tomcat-4.1.27\webapps\benchmark\WEB- 
INF\src\net\reumann\OrgIdSe
rvice.java:57: rs is already defined in execute(net.reumann.DataHash)
[javac] ResultSet rs =
stmt.executeQuery(SELECT FACIL_ID, FACIL_NAME, FACIL_NAME_SHORT,  
ORG_ID
FROM FACILITY WHERE FACIL_ID = ' + facilId + ');
[javac]   ^
[javac] 2 errors

Here is the code from my BLB:

package net.reumann;

import java.io.*;
import java.util.ArrayList;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.*;
import net.reumann.*;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.log4j.*;
import org.apache.commons.beanutils.BeanUtils;
public class OrgIdService implements Serializable {

//Declare and initialize variables
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
ArrayList facilList = new ArrayList();
//The execute() method of OrgIdService is called by OrgIdAction to
execute a query against the SS Test DB
public ArrayList execute(DataHash beanHash) {
//Get mode from DataHash
int mode = beanHash.getMode();
		try{
			switch (mode)	{
case 0:
	
Class.forName(oracle.jdbc.driver.OracleDriver);
	conn =
DriverManager.getConnection(jdbc:oracle:thin:@sources:1521:TEST,Tes 
t123
4,Test1234);
	Statement stmt =
conn.createStatement();
	ResultSet rs =
stmt.executeQuery(SELECT DISTINCT FACIL_ID FROM FACILITY);

//Read ResultSet into instance of
FacilBean and add to facilList Array object
while (rs.next()) {
FacilBean facil = new
FacilBean();

facil.setFacilId(rs.getString(FACIL_ID));
facilList.add(facil);
}
//Close ResultSet and Connection
objects
rs.close();
conn.close();
case 1:
//Extract the facilId from the
DataHash to query the FACILITY table
String facilId = (String)
beanHash.get(FacilId);
	
Class.forName(oracle.jdbc.driver.OracleDriver);
	conn =
DriverManager.getConnection(jdbc:oracle:thin:@sources:1521:TEST,Tes 
t123
4,Test1234);
	Statement stmt =
conn.createStatement();
	ResultSet rs =
stmt.executeQuery(SELECT FACIL_ID, FACIL_NAME, FACIL_NAME_SHORT,  
ORG_ID
FROM FACILITY WHERE FACIL_ID = ' + facilId + ');

//Read ResultSet into instance of
FacilBean and add to facilList Array object
while (rs.next()) {
FacilBean facil = new
FacilBean();

facil.setFacilId(rs.getString(FACIL_ID));

facil.setFacilName(rs.getString(FACIL_NAME));

facil.setFacilName(rs.getString(FACIL_NAME_SHORT));

facil.setOrgId(rs.getString(ORG_ID));
facilList.add(facil);
}
//Close ResultSet and Connection
objects
rs.close();
conn.close();
default:
return null;
}//end Switch
}//end try
catch (Exception e) {
return null;
e.printStackTrace();
}//end catch
//Return facilList Array Object to OrgIdAction
return facilList;
}//end 

Re: DynaForm Beans and Indexed Text fields.

2003-08-24 Thread Joel


Alex Shneyderman wrote:

You should set scope of the bean as session. 

When, in the jsp page?  In the StrutsAction I use to preload the form? 
An example would be great

 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Java Question

2003-08-24 Thread Oliver Reflé
Hi,
you are declaring your stmt variable twice. This is not allowed.
Just use name stmt.

Check below to find the error

Olli
  
  package net.reumann;
  
  import java.io.*;
  import java.util.ArrayList;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.sql.*;
  import javax.sql.*;
  import net.reumann.*;
  import org.apache.struts.action.Action;
  import org.apache.struts.action.ActionForward;
  import org.apache.struts.action.ActionMapping;
  import org.apache.struts.action.ActionForm;
  import org.apache.log4j.*;
  import org.apache.commons.beanutils.BeanUtils;
  
  
  public class OrgIdService implements Serializable {
  
  //Declare and initialize variables
  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;
  ArrayList facilList = new ArrayList();
  
  //The execute() method of OrgIdService is called by OrgIdAction to
  execute a query against the SS Test DB
  public ArrayList execute(DataHash beanHash) {
  
  //Get mode from DataHash
  int mode = beanHash.getMode();
  
  try{
  switch (mode)   {
  case 0:
  
  Class.forName(oracle.jdbc.driver.OracleDriver);
  conn =
 
 DriverManager.getConnection(jdbc:oracle:thin:@sources:1521:TEST,Test123
  4,Test1234);

//here you declare stmt
  Statement stmt =
  conn.createStatement();


  ResultSet rs =
  stmt.executeQuery(SELECT DISTINCT FACIL_ID FROM FACILITY);
  
  //Read ResultSet into instance of
  FacilBean and add to facilList Array object
  while (rs.next()) {
  FacilBean facil = new
  FacilBean();
  
  facil.setFacilId(rs.getString(FACIL_ID));
  facilList.add(facil);
  }
  
  //Close ResultSet and Connection
  objects
  rs.close();
  conn.close();
  case 1:
  //Extract the facilId from the
  DataHash to query the FACILITY table
  String facilId = (String)
  beanHash.get(FacilId);
  
  
  Class.forName(oracle.jdbc.driver.OracleDriver);
  conn =
 
 DriverManager.getConnection(jdbc:oracle:thin:@sources:1521:TEST,Test123
  4,Test1234);

here again
  Statement stmt =
  conn.createStatement();


  ResultSet rs =
  stmt.executeQuery(SELECT FACIL_ID, FACIL_NAME, FACIL_NAME_SHORT, ORG_ID
  FROM FACILITY WHERE FACIL_ID = ' + facilId + ');
  
  //Read ResultSet into instance of
  FacilBean and add to facilList Array object
  while (rs.next()) {
  FacilBean facil = new
  FacilBean();
  
  facil.setFacilId(rs.getString(FACIL_ID));
  
  facil.setFacilName(rs.getString(FACIL_NAME));
  
  facil.setFacilName(rs.getString(FACIL_NAME_SHORT));
  
  facil.setOrgId(rs.getString(ORG_ID));
  facilList.add(facil);
  }
  
  //Close ResultSet and Connection
  objects
  rs.close();
  conn.close();
  default:
  return null;
  }//end Switch
  }//end try
  catch (Exception e) {
  return null;
  e.printStackTrace();
  }//end catch
  
  //Return facilList Array Object to OrgIdAction
  return facilList;
  }//end Execute () method
  }//end class
 

-- 
COMPUTERBILD 15/03: Premium-e-mail-Dienste im Test
--
1. GMX TopMail - Platz 1 und Testsieger!
2. GMX ProMail - Platz 2 und Preis-Qualitätssieger!
3. Arcor - 4. web.de - 5. T-Online - 6. freenet.de - 7. daybyday - 8. e-Post


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: DynaForm Beans and Indexed Text fields.

2003-08-24 Thread Alex Shneyderman
 In the StrutsAction I use to preload the form?

yep

If you specify name attribute for your action mapping struts will create
form bean upon request to your action. So whatever action causes your
bean to be instantiated would need scope attribute to be set to session.

action path=/yourAction type=your.action.class 
name=yourFormName scope=session

Alex.



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: DynaForm Beans and Indexed Text fields.

2003-08-24 Thread Mark Lowe
In the action tag is the form scoped to session?

Cheers Mark

On Sunday, August 24, 2003, at 04:59 PM, Joel wrote:

I'm having a problem using Indexed text fields with DynaActionForms. I  
can make a jsp display my indexed text fields just fine using the  
logic:iterate and html:text custom tags. The problem is when I  
submit the form, there is a problem populating the DynaActionForm with  
my indexed text values. I'm wondering if the problem is the fact that  
the collection used is a java.util.List populated with by own custom  
beans, each bean containing three String fields with their own  
getters/setters. I'm wondering if I can use DynaActionForms in this  
instance. Below is a copy of my DynaActionForms Config, the jsp code  
that utilizes the form and the error message I get when the form is  
submitted. Any input would be of great help.

Thanks,

Joel.

Here's my DynaActionForm Bean declaration in struts-config.xml:

form-bean
name=persistRateInfo
type=org.apache.struts.action.DynaActionForm
!-- Specify the dynamic properties of the form --
form-property name=hazardInsRate type=java.lang.String/
form-property name=dealOneTerm type=java.lang.String/
form-property name=dealOneIR type=java.lang.String/
form-property name=dealOnePercentageDown type=java.lang.String/
form-property name=dealTwoTerm type=java.lang.String/
form-property name=dealTwoIR type=java.lang.String/
form-property name=dealTwoPercentageDown type=java.lang.String/
form-property name=dealThreeTerm type=java.lang.String/
form-property name=dealThreeIR type=java.lang.String/
form-property name=dealThreePercentageDown type=java.lang.String/
form-property name=pmiRanges type=java.util.List/
/form-bean
Here's the loop I use in the jsp that needs to display the values of  
pmiRanges. of the form bean:

logic:iterate id=pmiRanges name=persistRateInfo  
property=pmiRanges
tr
td style=font-family: sans; font-size: 12; width=100Low: /td
td style=font-family: sans; font-size: 12;
html:text name=pmiRanges property=low indexed=true size=5/
/td

td style=font-family: sans; font-size: 12; width=100High: /td
td style=font-family: sans; font-size: 12;
html:text name=pmiRanges property=high indexed=true size=5/
/td
td style=font-family: sans; font-size: 12; width=100Rate: /td
td style=font-family: sans; font-size: 12;
html:text name=pmiRanges property=rate indexed=true size=5/
/td
/tr
/logic:iterate
Now I use a Struts Action to preload this form bean with values from a  
database. It does this fine. When the jsp is called for the first  
time, it utilizes the form bean, and the List perfectly and displays  
the indexed text fields just like I want it to. here is an example row  
of rendered text fields:

tr
td style=font-family: sans; font-size: 12; width=100Low: /td
td style=font-family: sans; font-size: 12;
input type=text name=pmiRanges[0].low size=5 value=10.0
/td

td style=font-family: sans; font-size: 12; width=100High: /td
td style=font-family: sans; font-size: 12;
input type=text name=pmiRanges[0].high size=5 value=15.0
/td
td style=font-family: sans; font-size: 12; width=100Rate: /td
td style=font-family: sans; font-size: 12;
input type=text name=pmiRanges[0].rate size=5 value=5.7
/td
/tr
The problem comes in when I try to submit the form to save the form  
values. It doesn't seem that the form bean can be populated with
the indexed values. I get the follwoing Exception:

?

java.lang.NullPointerException: No indexed value for 'pmiRanges[0]'
	at  
org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:293)
	at  
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyU 
tils.java:474)
	at  
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyU 
tils.java:428)
	at  
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUt 
ils.java:770)
	at  
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.ja 
va:801)
	at  
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
	at org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Java Question

2003-08-24 Thread Mike Whittaker


 I've been trying to compile my BLB (Business Logic Bean) and have been
 getting errors during compilation.  I haven't a clue as to how I could
 debug this.  Any assistance would be appreciated.



ResultSet rs =
stmt.executeQuery(SELECT FACIL_ID, FACIL_NAME, FACIL_NAME_SHORT, ORG_ID
FROM FACILITY WHERE FACIL_ID = ' + facilId + ');

Change that line to:

rs =
stmt.executeQuery(SELECT FACIL_ID, FACIL_NAME, FACIL_NAME_SHORT, ORG_ID
FROM FACILITY WHERE FACIL_ID = ' + facilId + ');

You can not redeclare a variable in the same scope.

The way you were trying to do it was have two variables called rs in the
same scope, the ammendment, simply replaces one resultset with another, for
the object reference - rs.

--
Mike W


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



JSR 168 conflict with Struts?

2003-08-24 Thread Clay Richardson
I apologize if anyone has already asked this question, but I searched
the board and didn’t see it.

JSR 168 has the following line in it (Section PLT.16.3):
 
“Servlets and JSPs included from portlets should not use the servlet
RequestDispatcher forward method as its behavior may be
non-deterministic.”
 
I am no expert on Struts, although I have used it quite a bit.  It seems
that if I wanted to wrap my Struts app in a Portlet and access various
actions through the PortletRequestDispatcher (the most logical
approach), I would run afoul of this warning.
 
Lacking an implementation to test my hypothesis (*$# IBM legal
department), I am unsure whether this actually fails or not.  My gut
instinct is that it probably wouldn’t, but that it may not be reliable
across implementations of servlet and portlet containers.  
 
I wanted to get some thoughts from the Struts community about this
possible issue.  Also, I wanted to know what the impact would be of
using RequestDispatcher’s include method instead?  Or at least providing
the facility to portlet developers?
 
I apologize if I have wrongly assumed anything in my question.  This is
my best estimate based on what I have read.
 
Thanks,
 
 
Clay Richardson
 
 
W. Clay Richardson
Adjunct Professor of Computer Science
Northern Virginia Graduate Center
Virginia Polytechnic Institute and State University
 
“Oh, and how is education supposed to make me feel smarter?  Besides,
every time I learn something new, it pushes some old stuff out of my
brain.  Remember when I took that home wine-making course and I forgot
how to drive?” – Homer J. Simpson


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]