You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Hill <an...@gridnode.com> on 2002/09/27 07:43:01 UTC

RE: How to call an array setter

The usual way to call an array setter method is with an array. Nulls are
also acceptable.

getMessageCode() in the gridDeterminations thinghy returns what type?

What compilation / runtime error are you experiencing?


-----Original Message-----
From: mail [mailto:rea-family@attbi.com]
Sent: Friday, September 27, 2002 13:49
To: struts-user@jakarta.apache.org
Subject: How to call an array setter


I must be brain-dead right now.  Can anyone tell me how to call an array
setter method?

ex.

ResponseProcessForm:

	private String[] msgCode = null;

	public void setMsgCode(String[] msgCode) {
		this.msgCode = msgCode;
	}

	public String[] getMsgCode() {
		return msgCode;
	}

ResponseProcessAction:

	/*
	 *This does not work, but not sure how to call the method??
	 */
	responseProcessForm.setMsgCode(gridDeterminations.getMessageCode());



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Is it really worth the effort to have a single instance of the Action?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 27 Sep 2002, Andrew Hill wrote:

> Date: Fri, 27 Sep 2002 15:51:06 +0800
> From: Andrew Hill <an...@gridnode.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>,
>      andrew.david.hill@gridnode.com
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Is it really worth the effort to have a single instance of the
>     Action?
>
> Given that for modern JVMs object creation and cleanup isnt the chore it
> used to be , I am wondering if it might not be more convienient to create a
> new Action instance for each request.
>

The WebWorks framework (by Rickard Oberg) actually does things in the
manner you suggest, and goes one step further -- he combines what we think
of as the form bean and the Action into a single class, and calls all the
property setters for your request fields directly on the "Action" instance
before calling it's execute() method.  Therefore, no separate form bean
class is needed.

If I had thought of this design pattern in the first place, I'd have been
pretty tempted to use it.  However, changing the semantics of a
fundamental piece of Struts this radically doesn't seem like a good idea
at this point, because it would reduce performance (albeit by a small
amount) on existing Struts apps that are already programmed with thread
safe Actions.

The other concern I have is that this would encourage you to code your
business logic in the Action directly, instead of delegating it to some
logic bean.  I view the most appropriate role of an Action to be as an
adapter between the servlet-API-based web environment and the business
logic of your application, which should *not* depend on any presentation
layer APIs itself.


Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Is it really worth the effort to have a single instance of the Action?

Posted by Andrew Hill <an...@gridnode.com>.
Given that for modern JVMs object creation and cleanup isnt the chore it
used to be , I am wondering if it might not be more convienient to create a
new Action instance for each request.

This would eliminate the need to write the Actions in a thread-safe manner
and allow for the use of member variables  (though such would only exist
during that request obviously).

It would then be quite tempting to pass in the mapping, actionForm, request,
response to the constructor and have them as member variables. (Not that
there is any particular benefit to this, except perhaps as syntactical
sugar)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


[OT][JavaScript][Lazy] Product Rego number automatic JavaScript focus shifting

Posted by Andrew Hill <an...@gridnode.com>.
<pleasedomyworkforme>

<excuse sin="sloth">
Doubtless their are tons on resources on the net but its Friday ,Im feeling
lazy, and Im sure many of you have already done this...
<excuse>

Ive got a product registration field on a form which consists in the html of
a few <input> fields.
I want the focus to shift automatically to the next field when the first is
completed.

Anyone out there already got a suitable JavaScript function I can set as one
of the onXXX handlers they could give me for this?

</pleasedomyworkforme>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: How to call an array setter

Posted by mail <re...@attbi.com>.
I was braindead.  This code took care of it:

for(int i = 0; i < determinationsArray.length; i++)
{
	gridDeterminations = (GridDeterminations) determinationsArray[i];

	msgCode[i] = gridDeterminations.getMessageCode();

}

responseProcessForm.setMsgCode(msgCode);


-----Original Message-----
From: Adrian Brown [mailto:adrianjonbrown@yahoo.com.au]
Sent: Thursday, September 26, 2002 11:49 PM
To: Struts Users Mailing List
Subject: RE: How to call an array setter


for this, try:

return new String[] { "string1", "string2", "string3",
"string4", "string5", "string6", "string7" };

Adrian


 --- mail <re...@attbi.com> wrote: > I placed
this in the Action class and everything
> compiled, but it moved
> everything iteration of gridDetermination
> MessageCodes into only the first
> array iteration.  For example, if I have 7
> MessageCodes to load into the
> MsgCode array, I only get one MsgCode in the array.
> How should I do this to
> create an array of MsgCode's?
>
> Thanks!
>
> ResponseProcessAction:
> 	responseProcessForm.setMsgCode(new String[]
> {gridDeterminations.getMessageCode()});
>
> ResponseProcessForm:
> 	public void setMsgCode(String[] msgCode) {
> 		this.msgCode = msgCode;
> 	}
>
> 	public String[] getMsgCode() {
> 		return msgCode;
> 	}
>
> -----Original Message-----
> From: Eddie Bush [mailto:ekbush@swbell.net]
> Sent: Thursday, September 26, 2002 10:54 PM
> To: Struts Users Mailing List
> Subject: Re: How to call an array setter
>
>
> setMsgCode(new String[] {
> gridDeterminations.getMessageCode() });
>
> If it's expecting an array, you'll have to give it
> one.
>
> mail wrote:
>
> >getMessageCode() returns a String.
> >
> >The error message I get is:
> > setMsgCode(java.lang.String[]) in
> com.coramhc.grid.ResponseProcessForm
> >cannot be applied to (java.lang.String)
> >
> >Any ideas?
> >
>
> --
> Eddie Bush
>
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>

http://mobile.yahoo.com.au - Yahoo! Messenger for SMS
- Always be connected to your Messenger Friends

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: How to call an array setter

Posted by Adrian Brown <ad...@yahoo.com.au>.
for this, try:

return new String[] { "string1", "string2", "string3",
"string4", "string5", "string6", "string7" };

Adrian
 

 --- mail <re...@attbi.com> wrote: > I placed
this in the Action class and everything
> compiled, but it moved
> everything iteration of gridDetermination
> MessageCodes into only the first
> array iteration.  For example, if I have 7
> MessageCodes to load into the
> MsgCode array, I only get one MsgCode in the array. 
> How should I do this to
> create an array of MsgCode's?
> 
> Thanks!
> 
> ResponseProcessAction:
> 	responseProcessForm.setMsgCode(new String[]
> {gridDeterminations.getMessageCode()});
> 
> ResponseProcessForm:
> 	public void setMsgCode(String[] msgCode) {
> 		this.msgCode = msgCode;
> 	}
> 
> 	public String[] getMsgCode() {
> 		return msgCode;
> 	}
> 
> -----Original Message-----
> From: Eddie Bush [mailto:ekbush@swbell.net]
> Sent: Thursday, September 26, 2002 10:54 PM
> To: Struts Users Mailing List
> Subject: Re: How to call an array setter
> 
> 
> setMsgCode(new String[] {
> gridDeterminations.getMessageCode() });
> 
> If it's expecting an array, you'll have to give it
> one.
> 
> mail wrote:
> 
> >getMessageCode() returns a String.
> >
> >The error message I get is:
> > setMsgCode(java.lang.String[]) in
> com.coramhc.grid.ResponseProcessForm
> >cannot be applied to (java.lang.String)
> >
> >Any ideas?
> >
> 
> --
> Eddie Bush
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>  

http://mobile.yahoo.com.au - Yahoo! Messenger for SMS
- Always be connected to your Messenger Friends

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: How to call an array setter

Posted by mail <re...@attbi.com>.
I placed this in the Action class and everything compiled, but it moved
everything iteration of gridDetermination MessageCodes into only the first
array iteration.  For example, if I have 7 MessageCodes to load into the
MsgCode array, I only get one MsgCode in the array.  How should I do this to
create an array of MsgCode's?

Thanks!

ResponseProcessAction:
	responseProcessForm.setMsgCode(new String[]
{gridDeterminations.getMessageCode()});

ResponseProcessForm:
	public void setMsgCode(String[] msgCode) {
		this.msgCode = msgCode;
	}

	public String[] getMsgCode() {
		return msgCode;
	}

-----Original Message-----
From: Eddie Bush [mailto:ekbush@swbell.net]
Sent: Thursday, September 26, 2002 10:54 PM
To: Struts Users Mailing List
Subject: Re: How to call an array setter


setMsgCode(new String[] { gridDeterminations.getMessageCode() });

If it's expecting an array, you'll have to give it one.

mail wrote:

>getMessageCode() returns a String.
>
>The error message I get is:
> setMsgCode(java.lang.String[]) in com.coramhc.grid.ResponseProcessForm
>cannot be applied to (java.lang.String)
>
>Any ideas?
>

--
Eddie Bush




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: How to call an array setter

Posted by Eddie Bush <ek...@swbell.net>.
setMsgCode(new String[] { gridDeterminations.getMessageCode() });

If it's expecting an array, you'll have to give it one.

mail wrote:

>getMessageCode() returns a String.
>
>The error message I get is:
> setMsgCode(java.lang.String[]) in com.coramhc.grid.ResponseProcessForm
>cannot be applied to (java.lang.String)
>
>Any ideas?
>

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: How to call an array setter

Posted by Adrian Brown <ad...@yahoo.com.au>.
Hi,

A String cannot be handed in when it expects a String
array. Try

public String[] getMessageCode() {
     return new String[] { "string here" };
}

Adrian

 --- mail <re...@attbi.com> wrote: >
getMessageCode() returns a String.
> 
> The error message I get is:
>  setMsgCode(java.lang.String[]) in
> com.coramhc.grid.ResponseProcessForm
> cannot be applied to (java.lang.String)
> 
> Any ideas?
> 
> -----Original Message-----
> From: Andrew Hill
> [mailto:andrew.david.hill@gridnode.com]
> Sent: Thursday, September 26, 2002 10:43 PM
> To: Struts Users Mailing List
> Subject: RE: How to call an array setter
> 
> 
> The usual way to call an array setter method is with
> an array. Nulls are
> also acceptable.
> 
> getMessageCode() in the gridDeterminations thinghy
> returns what type?
> 
> What compilation / runtime error are you
> experiencing?
> 
> 
> -----Original Message-----
> From: mail [mailto:rea-family@attbi.com]
> Sent: Friday, September 27, 2002 13:49
> To: struts-user@jakarta.apache.org
> Subject: How to call an array setter
> 
> 
> I must be brain-dead right now.  Can anyone tell me
> how to call an array
> setter method?
> 
> ex.
> 
> ResponseProcessForm:
> 
> 	private String[] msgCode = null;
> 
> 	public void setMsgCode(String[] msgCode) {
> 		this.msgCode = msgCode;
> 	}
> 
> 	public String[] getMsgCode() {
> 		return msgCode;
> 	}
> 
> ResponseProcessAction:
> 
> 	/*
> 	 *This does not work, but not sure how to call the
> method??
> 	 */
> 
>
responseProcessForm.setMsgCode(gridDeterminations.getMessageCode());
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>  

http://mobile.yahoo.com.au - Yahoo! Messenger for SMS
- Always be connected to your Messenger Friends

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: How to call an array setter

Posted by mail <re...@attbi.com>.
getMessageCode() returns a String.

The error message I get is:
 setMsgCode(java.lang.String[]) in com.coramhc.grid.ResponseProcessForm
cannot be applied to (java.lang.String)

Any ideas?

-----Original Message-----
From: Andrew Hill [mailto:andrew.david.hill@gridnode.com]
Sent: Thursday, September 26, 2002 10:43 PM
To: Struts Users Mailing List
Subject: RE: How to call an array setter


The usual way to call an array setter method is with an array. Nulls are
also acceptable.

getMessageCode() in the gridDeterminations thinghy returns what type?

What compilation / runtime error are you experiencing?


-----Original Message-----
From: mail [mailto:rea-family@attbi.com]
Sent: Friday, September 27, 2002 13:49
To: struts-user@jakarta.apache.org
Subject: How to call an array setter


I must be brain-dead right now.  Can anyone tell me how to call an array
setter method?

ex.

ResponseProcessForm:

	private String[] msgCode = null;

	public void setMsgCode(String[] msgCode) {
		this.msgCode = msgCode;
	}

	public String[] getMsgCode() {
		return msgCode;
	}

ResponseProcessAction:

	/*
	 *This does not work, but not sure how to call the method??
	 */
	responseProcessForm.setMsgCode(gridDeterminations.getMessageCode());



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>