struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chuckcavan...@attbi.com
Subject Re: DynaActionForm problem with non-string objects
Date Thu, 25 Apr 2002 18:49:46 GMT
I replied to Peter directly, but let me copy the 
relevant parts to the group so that everyone sees the 
response.

I'm using a message from the resource bundle That looks 
like this: 

"The {0} is required for login" 

The substitution parameter {0} can be anything you want 
and you can pass it into a new ActionError like this: 

new ActionError("global.error.login.requiredfield", 
someStringValue );

The idea here is that I may need to show this message 
for multiple fields and instead of creating multiple 
messages in the bundle that only differ by a single 
parameter, I can just use one message and dynamically 
insert the parameter value.

The code in Chapter 3 was supposed to stick the 
pinNumberLabel into the ActionError constructor like 
this:

new ActionError("global.error.login.requiredfield", 
pinNumberLabel );

but this is a bug on my part. The reason that I get the 
value of the pinNumberLabel from the message bundle is 
because it must also be localized for the user's locale. 
The code should have looked like this:

String pinNumberLabel = resources.getMessage
( "label.pinnumber" );

// Create an error message for the missing pingNumber 
value
ActionError newError = new ActionError
("global.error.login.requiredfield", pinNumberLabel );
errors.add(ActionErrors.GLOBAL_ERROR, newError);

Thanks for bringing this up and I'll be sure to fix it 
in the Chapter.

As far as your other comments, I think what you asking 
for will come in the rest of the book. There will 
definitely be hints and tips for using Struts that will 
be helpful. There are web architecture diagrams and UML 
diagrams throughout all of the chapters. Chapter 3 was 
just supposed to be a short overview of the framework 
using the banking example. 

I think that you'll be pleased with the rest of the 
book, as soon as I can write it and get the rest of the 
chapters out to the community.

Chuck
> 
> Chuck Cavaness
> 
>    // Check and see if the pin number is missing
>        if(pinNumber == null || pinNumber.length() == 0) {
>          String pinNumberLabel = resources.getMessage( "label.pinnumber" );
> 
>          // Create an error message for the missing pingNumber value
>          ActionError newError =
>            new ActionError("global.error.login.requiredfield", "Pin Number");
>          errors.add(ActionErrors.GLOBAL_ERROR, newError);
>        }
>        // Return the ActionErrors, in any.
>        return errors;
> 
> 
> On page 22 of chapter 3 of the preview book.  What is
> the `pinNumberLabel' all about?
> 
> I think the chapter 3 is very big. There is lot to take in.
> ValueObject side bar could be reserved for a latter chapter.
> 
> Also I think for JSP side of thing. How does the Page designer
> or person who has to rigourous  follow an e-style guide look and feel
> get into the picture?
> 
> Hints and tips for using Struts could be helpful.
> Web architecture diagram.
> May be a UML diagram might help here.
> 
> --
> Peter Pilgrim                       ++44 (0)207-545-9923
> 
> ............................................ Swamped under electronic mails
> 
> 
> ---------------------------------------- Message History 
> ----------------------------------------
> 
> 
> From:  Chuck Cavaness <chuckcavaness@attbi.com> on 25/04/2002 07:41 AST
> 
> Please respond to "Struts Users Mailing List" <struts-user@jakarta.apache.org>
> 
> To:    "Struts Users Mailing List" <struts-user@jakarta.apache.org>
> cc:
> Subject:    Re: DynaActionForm problem with non-string objects
> 
> 
> I think that you'll have to extend the framework. The "initial" value is
> really designed to be a primitive or one of the wrappers around it.  The
> ConvertUtils "convert" method is used and it's not really capable of doing
> what you want it to do. I think you might take a look at extending the
> FormPropertyConfig class, rather than the DynaActionForm. The
> DynaActionForm uses a Map already and should be capable of dealing with
> Objects. It's the initialization portion of the process that you need to
> override and I believe that starts in the FormPropertyConfig class.
> 
> Chuck Cavaness
> 
> At 11:38 AM 4/19/2002 -0300, you wrote:
> >I'm using some DynaActionForms, but some of them
> >require more complex objects with nested fields, and
> >not only Strings as fields.
> >The problem is that I can only seem to set my objects
> >as null, and it causes problems in the JSPs.
> >Consider this example, taken from struts-config.xml:
> >
> >     <form-bean
> >type="org.apache.struts.action.DynaActionForm"
> >name="myForm">
> >         <form-property name="myObject"
> >type="vo.MyObject" />
> >     </form-bean>
> >
> >
> >I could not use the "initial" property of the
> >form-property element because my object is not a
> >String. So it is set to null instead.
> >All I want is a new instance of the object to be
> >created as the field's initial value.
> >I could set a newly allocated object to the Dynamic
> >form myself, but it sounds like a rather crude
> >solution to me.
> >Isn't there a better way to do this, or will I have to
> >extend the DynaActionForm class to solve this issue?
> >
> >
> >=====
> >----------------------------------------
> >Frederico Ferro Schuh
> >fred_schuh@yahoo.com.br
> >ICQ: 20486081
> >
> >_______________________________________________________________________________
> ________________
> >Yahoo! Empregos
> >O trabalho dos seus sonhos pode estar aqui. Cadastre-se hoje mesmo no
> >Yahoo! Empregos e tenha acesso a milhares de vagas abertas!
> >http://br.empregos.yahoo.com/
> >
> >--
> >To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> >For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
> 
> 
> 
> 
> 
> 
> --
> 
> This e-mail may contain confidential and/or privileged information. If you are > not
the intended recipient (or have received this e-mail in error) please notify 
> the sender immediately and destroy this e-mail. Any unauthorized copying, 
> disclosure or distribution of the material in this e-mail is strictly forbidden.
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>
> 

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message