Java Mailing List Archive

http://www.gg3721.com/

Home » Struts Users Mailing List »

user Digest 27 Jun 2008 05:26:41 -0000 Issue 8114

user-digest-help

2008-06-27


Author LoginPost Reply

user Digest 27 Jun 2008 05:26:41 -0000 Issue 8114

Topics (messages 188210 through 188231):

Re: Struts 2 And Hibernate Problem
 188210 by: cree

Re: [S2] autocompleter action extension
 188211 by: Laurie Harper

Re: [S2] TypeConversion and generics
 188212 by: Lukasz Lenart
 188214 by: Pierre Thibaudeau
 188217 by: Pierre Thibaudeau
 188218 by: Lukasz Lenart
 188220 by: Pierre Thibaudeau
 188222 by: Chris Pratt
 188223 by: Pierre Thibaudeau
 188224 by: Chris Pratt

Re: Struts list
 188213 by: Laurie Harper

Re: Newbie: Call a servlet in another application and set attribute
 188215 by: Laurie Harper

Re: validation problem
 188216 by: Laurie Harper

Re: Struts 2 - Repopulate controls when validation fails
 188219 by: bob fuller

Unit Testing - change ObjectFactory - override config
 188221 by: Greg Lindholm

<s:fielderror /> - how to provide an understandable error message to the enduser?
 188225 by: xianwinwin
 188226 by: xianwinwin
 188227 by: Dave Newton

Re: [s2] Whats the most strutsy way of doing....
 188228 by: Jeromy Evans

Re: Strange problem with content disposition
 188229 by: Jeromy Evans

Re: [struts] Slow performance with Struts2
 188230 by: yorlick kilroy

Re: Struts Themes Problem - help
 188231 by: Narayana S

Administrivia:

---------------------------------------------------------------------
To post to the list, e-mail: user@(protected)
To unsubscribe, e-mail: user-digest-unsubscribe@(protected)
For additional commands, e-mail: user-digest-help@(protected)

----------------------------------------------------------------------

Attachment: user_188210.ezm (zipped)

I cannot believe I missed that, my reports showed how obviously it was
creating singletons and never configured it not to. Thanks for the
information, resolved the problem within minutes of reading your response.

Thanks again!
--
Sent from the Struts - User mailing list archive at Nabble.com.


Attachment: user_188211.ezm (zipped)
My guess is that using an action extension of .html creates a conflict
with the Dojo template resources, which are .html files. If you look at
your access logs (or use Firebug to see what XHR requests are being made
during page rendering), you'll see what I mean.

The easiest thing to do is pick a different action extension (maybe .htm
or .xhtml). If you really need to be able to use .html as the action
extension, you'll have to figure out how to prevent Dojo template
requests from being treated as action requests.

L.

Pierre Goupil wrote:
> Hello all,
>
> I would like my S2 project to be mapped to .html actions, so I have
> set this up :
>
> - struts.action.extension=html in my struts.properties
>
> - <constant name="xwork.action.extension" value="html" /> in my
> xwork-default.xml
>
> - <constant name="struts.action.extension" value="html" /> in my
> struts-default.xml.
>
> Please note that for the two last ones, I have simply added the
> property to the original file provided in the jar.
>
> It works, in the sense that my actions respond and display my JSPs as
> desired. BUT I can't figure out how to have the auto-completer tag to
> work. If I use the .html extension, I get the following exception :
>
> ---
> Could not find action or result
> There is no Action mapped for action name ComboBox. - [unknown location]
>  at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
>  at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
>  at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494)
>  at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
>  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
>  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
>  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
>  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
>  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
>  at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
>  at java.lang.Thread.run(Thread.java:619)
> ---
>
> I think this is because Struts is looking for an .action action
> extension : if I revert back to the default .action extension, it all
> works. But as you can guess, I would like to be able to use whatever
> extension I wish to.
>
> A clue, anyone ?
>
> Thanx in advance,
>
> Pierre GOUPIL


Attachment: user_188212.ezm (zipped)
Hi,

I don't know why you use such generic action class? And as I know OGNL
support generics and it will try to convert to given type without
TypeConversion


Regards
--
Lukasz
http://www.lenart.org.pl/

Attachment: user_188214.ezm (zipped)
Hi Lukasz

I don't know why you use such generic action class?

;)
Well, I haven't shown you the purpose of any of the objects. (In fact, the
full hierarchy is highly more complex than what is shown in my previous
post; there are 29 objects involved...)


> And as I know OGNL support generics and it will try to convert to given
> type without TypeConversion
>

I wish it did, except that I keep getting an exception (as mentioned in
previous post)...
http://struts.apache.org/2.1.2/docs/type-conversion.html#TypeConversion-GenericsandErasure

Attachment: user_188217.ezm (zipped)
I realize that I may have been stingy on the exception stack trace. Here is
more of it.
Notice that, nowhere in there is my StringToIntegerConverter actually
called. (It would have logged the occurrence.)

15:22:37,762 DEBUG ParametersInterceptor:58 - Setting params propertyId => [
295 ]
15:22:37,777 DEBUG XWorkConverter:58 - key from method name... propertyId -
setPropertyId
15:22:37,778 DEBUG XWorkConverter:58 - propertyId:propertyId
15:22:37,862 DEBUG XWorkConverter:58 -
propertyId:com.mywebapp.converters.StringToIntegerConverter@(protected)
15:22:37,869 DEBUG XWorkConverter:58 - Class:
com.mywebapp.actions2.GroupContribAction
15:22:37,873 DEBUG XWorkConverter:58 - key from method name... propertyId -
setPropertyId
15:22:37,875 DEBUG XWorkConverter:58 - propertyId:propertyId
15:22:37,906 DEBUG XWorkConverter:58 -
propertyId:com.mywebapp.converters.StringToIntegerConverter@(protected)
ognl.MethodFailedException: Method "setPropertyId" failed for object
com.infloox.contrib.actions2.NaturalizationContribAction@(protected):
[Ljava.lang.String; cannot be cast to
java.lang.Integer]
  at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:823)
  at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:964)
  at
ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:75)
  at
ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:131)
  at
com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27)
  at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1656)
  at
com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty(CompoundRootAccessor.java:59)
  at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1656)
  at ognl.ASTProperty.setValueBody(ASTProperty.java:101)
  at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
  at ognl.SimpleNode.setValue(SimpleNode.java:246)
  at ognl.Ognl.setValue(Ognl.java:476)
  at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:197)
  at
com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:150)
  at
com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:138)
  at
com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:205)
  at
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:162)
  ... and 40 more lines
/-- Encapsulated exception ------------\
java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to
java.lang.Integer
  at
com.mywebapp.actions2.GroupContribAction.setPropertyId(GroupContribAction.java:1)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:517)
  ...
\--------------------------------------/
expr: propertyId val: [Ljava.lang.String;@(protected):
ognl.OgnlContext@6aa88a90root:[com.mywebapp.actions2.GroupContribAction@(protected),
com.opensymphony.xwork2.DefaultTextProvider@(protected):
[Ljava.lang.String;@(protected)
15:22:37,949 ERROR ParametersInterceptor:24 - ParametersInterceptor -
[setParameters]: Unexpected Exception caught setting 'propertyId' on 'class
com.infloox.contrib.actions2.NaturalizationContribAction: Error setting
expression 'propertyId' with value '[Ljava.lang.String;@(protected)'


2008/6/26 Pierre Thibaudeau <pierre.thibaudeau@(protected)>:

> I am aware that, when applying request parameters to an action, Struts
> cannot guess the actual type of parameters determined by a generic type
> (because of erasure at compile time).
>
> However, I am assuming that if a non-generic action class extends an
> abstract generic one, it should be possible in the non-generic child to
> force the type conversion explicitely. Isn't that the case? At the moment,
> I seemingly cannot get Struts to realize that I did specify a type
> conversion and I keeping getting the following exception (whether my forced
> conversion is in place or not):
> java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to
> java.lang.Integer
> ...
>

Attachment: user_188218.ezm (zipped)
Try to change order of your interceptors as below

      <interceptor-stack name="contribStack">
         <interceptor-ref name="paramsPrepareParamsStack"/>
         <interceptor-ref name="autoLogin"/>
      </interceptor-stack>


Regards
--
Lukasz
http://www.lenart.org.pl/

Attachment: user_188220.ezm (zipped)
I tried your suggestion. Unfortunately, the exception is exactly as before.
(In practice, it would not have been a good idea to put the autoLogin
interceptor after the prepare interceptor, but I am definitely willing to
try anything!)

2008/6/26 Lukasz Lenart <lukasz.lenart@(protected)>:

> Try to change order of your interceptors as below
>
>       <interceptor-stack name="contribStack">
>          <interceptor-ref name="paramsPrepareParamsStack"/>
>          <interceptor-ref name="autoLogin"/>
>       </interceptor-stack>
>

Attachment: user_188222.ezm (zipped)
How does your case differ from the example on the Type Conversion page
you referenced? It seems to me you're trying to do exactly what that
page says you can't?
(*Chris*)

On Thu, Jun 26, 2008 at 12:56 PM, Pierre Thibaudeau
<pierre.thibaudeau@(protected):
> I tried your suggestion. Unfortunately, the exception is exactly as before.
> (In practice, it would not have been a good idea to put the autoLogin
> interceptor after the prepare interceptor, but I am definitely willing to
> try anything!)
>
> 2008/6/26 Lukasz Lenart <lukasz.lenart@(protected)>:
>
>> Try to change order of your interceptors as below
>>
>>       <interceptor-stack name="contribStack">
>>          <interceptor-ref name="paramsPrepareParamsStack"/>
>>          <interceptor-ref name="autoLogin"/>
>>       </interceptor-stack>
>>
>

Attachment: user_188223.ezm (zipped)
2008/6/26 Chris Pratt <thechrispratt@(protected)>:

> How does your case differ from the example on the Type Conversion page
> you referenced? It seems to me you're trying to do exactly what that
> page says you can't?
>

My understanding of
http://struts.apache.org/2.1.2/docs/type-conversion.html#TypeConversion-GenericsandErasure
is that Struts cannot *infer* the actual type of a generified type. (And
that was the very first statement I made at the beginning of this thread.)
Which is exactly why I intend to *specify* the conversion (and not let
Struts attempt to do something which it can't do).

It's obvious from the erasure of generics that Struts could not (even in
theory) deduce the correct conversion. But if I specify my own converter,
why does it fail to make use of it? I don't see that the reference I quoted
makes any comment about that...

Attachment: user_188224.ezm (zipped)
On Thu, Jun 26, 2008 at 3:04 PM, Pierre Thibaudeau
<pierre.thibaudeau@(protected):
> 2008/6/26 Chris Pratt <thechrispratt@(protected)>:
>
>> How does your case differ from the example on the Type Conversion page
>> you referenced? It seems to me you're trying to do exactly what that
>> page says you can't?
>>
>
> My understanding of
> http://struts.apache.org/2.1.2/docs/type-conversion.html#TypeConversion-GenericsandErasure
> is that Struts cannot *infer* the actual type of a generified type. (And
> that was the very first statement I made at the beginning of this thread.)
> Which is exactly why I intend to *specify* the conversion (and not let
> Struts attempt to do something which it can't do).
>
> It's obvious from the erasure of generics that Struts could not (even in
> theory) deduce the correct conversion. But if I specify my own converter,
> why does it fail to make use of it? I don't see that the reference I quoted
> makes any comment about that...
>

Ahhh, that's the piece I missed. Seems like that should work, but I
haven't had to try anything like that. Sorry.
(*Chris*)

Attachment: user_188213.ezm (zipped)
Sonu S wrote:
> HI,
>
> I have to show list in my jsp page. I am using <html:select>
>
> i am getting two lists from data base and it is in employee form bean: first
> list is for employee no and second list is for name. i want to display
> employee name in <option> and want to use employee no as VALUE in <option>
> so list would have employee no as value and name will be displayed to user.
>
> i am not sure how to do it with two lists as i have two different lists, one
> list for emp no and one list for employee name. My form bean name is
> employeeForm and list names are employeeNoList and employeeNameList. Please
> help me... some code example would be a help for me. I am using struts 1.1

Your best bet is to zip the two lists together into a map and provide a
getter on your form bean for that map. Failing that, you'll need to
iterate one of the lists (using c:forEach or logic:iterate) and handle
dereferencing into the other list explicitly. That might look something
like this (untested):

 <html:select property="xxx" ...>
  <logic:iterate id="val" indexId="idx"
     name="employeeForm" property="emplyeeNoList">
    <option name="xxx" value="${val}">
     <bean:write name="employeeForm"
        property="employeeNameList[${idx}]"/>
    </option>
  </logic:iterate>
 </html:select>

L.


Attachment: user_188215.ezm (zipped)
Nils-Helge Garli Hegvik wrote:
> I believe most servlet containers prevent sharing of session objects
> between applications by default. But it probably can be configured to
> be allowed (consult the documentation for your server to find out

I know some containers support this, but it is container-specific
functionality and outside of the servlet spec.

> how). A shared cache is also an option. But the easiest would be to
> put them in the same application.

Agreed. Other options include a web service or other RPC mechanism, a
shared database, serialization to/from a shared disk location, etc. In
all cases you will need to be able to serialize the data you want to
pass and 're-hydrate' it on the other end.

L.

>
> Nils-H
>
> On Wed, Jun 25, 2008 at 7:29 PM, Mustafa Cayci <acayci@(protected):
>> Hello Dave,
>> Let me try to understan what you mean. Are you saying that I should be doing this
>>   public ActionForward execute(ActionMapping mapping, ActionForm form,
>>                       HttpServletRequest request,
>>                       HttpServletResponse response) throws Exception {
>> ....
>>      HttpSession session = request.getSession();
>>      session.setAttribute("Principal",principal);
>>      response.sendRedirect("/testsqlservlet/testsqlservlet");
>> ...
>> Because this did not work.
>> Thanks,
>> Mustafa
>>
>> ----- Original Message ----
>> From: Dave Newton <newton.dave@(protected)>
>> To: Struts Users Mailing List <user@(protected)>
>> Sent: Wednesday, June 25, 2008 12:58:09 PM
>> Subject: Re: Newbie: Call a servlet in another application and set attribute
>>
>> --- On Wed, 6/25/08, Mustafa Cayci <acayci@(protected):
>>> I am fairly new to Struts. I have two applications. AppA
>>> is a Struts application and AppB is another application. I
>>> have an Action class in AppA. Within execute() method, I am
>>> creating some objects. I would like to call the servlet in
>>> AppB and somehow I want to pass these objects to the
>>> servlet in AppB. SO far I have this
>>>
>>>   public ActionForward execute(ActionMapping mapping,
>>> ActionForm form,
>>>                       HttpServletRequest
>>> request,
>>>                       HttpServletResponse
>>> response) throws Exception {
>>> ...
>>>
>>> response.sendRedirect("/testsqlservlet/testsqlservlet?Object="
>>> + object);
>>> ...
>>>
>>> But this is a problem because even if I use SSL (i.e.
>>> https://) this redirect will be in cleartext and anybody
>>> can modify the "object". What are my options? I
>>> am hope I explained myself clearly.
>> Put it in the session?
>>
>> That's not passing the object, either; that's passing the string representation of the object. A bit different.
>>
>> Dave
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>


Attachment: user_188216.ezm (zipped)
Why not just validate all fields with type="requiredstring" and set
short-circuit="true" on them? Wouldn't that do what you want? See the
Short-Circuiting Validator section of the validation docs [1] for more
details.

[1] http://struts.apache.org/2.1.2/docs/validation.html

L.

ManiKanta G wrote:
> Hi,
>
> Even I've this problem... Here is my requirement....
>
> I've 3 fields. On successful validation of 1st field ONLY the 2nd field
> should be validated, and only with the successful validation of second,
> then only the 3rd field should be validated against some validation.
>
> I did this by using field validator of type expression, like below...
>
>   *<validators>
>     <field name="returnTo">
>        <field-validator type="requiredstring" >
>           <message>Select 'Return to'</message>
>        </field-validator>
>     </field>
>
>     <field name="sourceId">
>        <field-validator type="fieldexpression">
>           <param name="expression">
>             <![CDATA[((returnTo == null) ||
>                    ((sourceId != null) && (sourceId != "--
>   Select --")))]]></param>
>           <message>Select company/dealer name</message>
>        </field-validator>         </field>
>
>     <field name="drug">
>        <field-validator type="fieldexpression">
>           <param name="expression">
>             <![CDATA[(((returnTo == null) || ((sourceId == null)
>   || (sourceId == "-- Select --"))) ||
>                    ((drugsList.size <= 0) || ((drug != null)
>   && (drug != "-- Select --"))))]]></param>
>           <message>Select drug</message>
>        </field-validator>
>     </field>
>
>   </validators>*
>
> With this, the second case working as it supposed. The second field will
> be validated ONLY when the first field is not empty (as in the second
> field expression, I m using */returnTo == null/* with short-circuit OR,
> and then the actual validation logic of second field).
>
> But the validation logic of the third field (select box) is not working
> as is supposed to. When I print the expression value using *<s:property
> value="expression_of_the_third_field_....."/>*, it is printing false,
> but the validation is being bypassed.
>
> I've tried many ways. But non of 'em worked for me. Is any one got
> success with this type of validations.
>
> I can implement custom validation using validate(), but I've around 30
> transactional forms with this type of requirements.
>
> Am I doing any this wrong? Can anybody please guide me with this...
>
>
> Thanks,
> ManiKanta
>
>
>
> Dave Newton wrote:
>> You either do conditional validations, implement custom validators, or
>> as Lukasz suggested write your own validate() method. When validation
>> is very complex the last may be the best options.
>>
>> Dave
>>
>> --- On Wed, 6/25/08, Istvan Kozma <kozma_istvan@(protected):
>>
>>> How the validation should be done for fields which are only
>>> displayed in certain conditions? If I do this through the
>>> XML file the validation is done all the time even when the
>>> field is not visible.
>>> Istvan
>>>
>>>
>>> ----- Original Message ----
>>> From: Dave Newton <newton.dave@(protected)>
>>> To: Struts Users Mailing List
>>> <user@(protected)>
>>> Sent: Wednesday, June 25, 2008 3:37:38 PM
>>> Subject: Re: validation problem
>>>
>>> Whoops, as the other reply said, it's the
>>> <s:fielderror...> tag [1], not <s:actionerror>.
>>>
>>> Dave
>>>
>>> [1] http://struts.apache.org/2.x/docs/fielderror.html
>>>
>>> --- On Wed, 6/25/08, Dave Newton
>>> <newton.dave@(protected):
>>>  
>>>> --- On Wed, 6/25/08, Anshu Dhamija wrote:
>>>>    
>>>>> i am facing problem in performing validation
>>>>>      
>>> through
>>>  
>>>>> xml actually i want to display message at the top
>>>>>      
>>> of  
>>>>> my form instaed of at field level can anyone please help me
>>>>>      
>>>> The validation messages are placed in the form by the
>>>>    
>>> S2
>>>  
>>>> form element tags. If you want to modify the output of
>>>> those tags you can modify or create a theme [1].
>>>>
>>>> Using the "simple" theme will also remove
>>>>    
>>> the
>>>  
>>>> validation messages, but you'll lose other useful
>>>> functionality--but that might not be an issue
>>>>    
>>> depending on
>>>  
>>>> your usecase.
>>>>
>>>> The <s:actionerror...> tag [2] will render any
>>>>    
>>> error
>>>  
>>>> messages. A combination of either the simple theme or
>>>>    
>>> a
>>>  
>>>> modified theme plus the action error tag may do what
>>>>    
>>> you
>>>  
>>>> need.
>>>>
>>>> Dave
>>>>
>>>> [1]
>>>>
>>>>    
>>> http://struts.apache.org/2.x/docs/themes-and-templates.html
>>>  
>>>> [2] http://struts.apache.org/2.x/docs/actionerror.html
>>>>    
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>> For additional commands, e-mail:
>>> user-help@(protected)
>>>  
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>> For additional commands, e-mail: user-help@(protected)
>>
>>  
>
>
>
>
> ********** DISCLAIMER **********
> Information contained and transmitted by this E-MAIL is proprietary to
> Sify Limited and is intended for use only by the individual or entity to
> which it is addressed, and may contain information that is privileged,
> confidential or exempt from disclosure under applicable law. If this is
> a forwarded message, the content of this E-MAIL may not have been sent
> with the authority of the Company. If you are not the intended
> recipient, an agent of the intended recipient or a person responsible
> for delivering the information to the named recipient, you are notified
> that any use, distribution, transmission, printing, copying or
> dissemination of this information in any way or in any manner is
> strictly prohibited. If you have received this communication in error,
> please delete this mail & notify us immediately at admin@(protected)
>


Attachment: user_188219.ezm (zipped)

The approach I am taking is from the Struts 2 FAQ...

http://struts.apache.org/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html

Why should it be avoided?


> Date: Thu, 26 Jun 2008 08:32:37 +0200
> From: lukasz.lenart@(protected)
> To: user@(protected)
> Subject: Re: Struts 2 - Repopulate controls when validation fails
>
> Hi,
>
> As I know, use of s:action tag should be avoided, the better option is
> to use Preparable interface, you can use prepare<MethodName>() method
> also.
> http://struts.apache.org/2.x/docs/prepare-interceptor.html
>
>
> Regards
> --
> Lukasz
> http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
> From: bobfuller30004@(protected)
> To: user@(protected)
> Subject: RE: Struts 2 - Repopulate controls when validation fails
> Date: Thu, 26 Jun 2008 02:17:36 +0000
>
>
> Trying again to give out my pseudo JSP...
>
> s:form name="myAction"
> s:textfield name="foo0"/
> s:action name="languages" executeResult="true"/
> s:textfield name="foo1"/
> s:submit/
> /s:form
>
> > From: bobfuller30004@(protected)
> > To: user@(protected)
> > Subject: Struts 2 - Repopulate controls when validation fails
> > Date: Thu, 26 Jun 2008 02:14:28 +0000
> >
> >
> > I'm following the "How do we repopulate controls when validation fails" FAQ located at...
> >
> > http://struts.apache.org/2.x/docs/how-do-we-repopulate-controls-when-validation-fails.html
> >
> > Of the two methods it suggests I am trying to use the 'action tag' method. Using the simple example from the FAQ works fine, but once I move beyond the simple and try to drop my "Languages" control inside the tag of another action I have problems.
> >
> > Here's my pseudo JSP (note MyAction)...
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > MyAction implements validateable and I am validating foo0 and foo1 inside the validate() method. Here's my validate() code...
> >
> > public void validate() {
> > if (foo0 == null || foo0.length() == 0)
> >  addFieldError("foo0", "Foo0 is required");
> > else
> >  foo0 = foo0 + " VALIDATED";
> >
> > if (foo1 == null || foo1.length() == 0)
> >  addFieldError("foo1", "Foo1 is required");
> > else
> >  foo1 = foo1 + " VALIDATED";    
> > }
> >
> > The important thing to note about my validation code is that when the validation succeeds the data entered by the user is updated with the word "VALIDATED". This may seem like an odd thing to do, but it's part of the requirements of the project I'm working on.
> >
> > Visiting http://localhost/MyAction/myAction_input.action works great. The page draws, foo0 is empty, the languages control has languages to choose from, foo1 is empty, the submit button appears. Submitting the form is when I get into problems. Here are three submit paths and their results...
> >
> > 1. foo0 is empty, foo1 is empty. click submit. RESULT - foo0 is empty. foo1 is empty. SUCCESS!
> > 2. foo0 = 'A', foo1 is empty. click submit. RESULT - page redraws. foo0 = 'A VALIDATED'. foo1 is empty. SUCCESS!
> > 3. foo0 is empty, foo1 = 'A'. click submit. RESULT - page redraws. foo0 is empty. foo1 = 'A'. FAIL! - foo1 should say 'A VALIDATED'
> >
> > For some reason MyAction.setFoo1() is being invoked *again* after I set foo1 to 'A VALIDATED' in my validate() code. Why is that happening? I know it has something to do with the Languages control that appears before the foo1 text field, because when I remove the Languages control everything works as expected.
> >
> > Anyone have any ideas about what the Languages control is doing that is causing my foo1 field to get reset to the original submit value? I'd really like to be able to use the 'action tags' approach for repopulating controls, but 'dropping wherever', as suggested in the FAQ (see link above), does not seem to be as easy as it sounds.
> >
> > Thanks.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > _________________________________________________________________
> > The other season of giving begins 6/24/08. Check out the i’m Talkathon.
> > http://www.imtalkathon.com?source=TXT_EML_WLH_SeasonOfGiving
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@(protected)
> > For additional commands, e-mail: user-help@(protected)
> >
>
> _________________________________________________________________
> The i’m Talkathon starts 6/24/08. For now, give amongst yourselves.
> http://www.imtalkathon.com?source=TXT_EML_WLH_LearnMore_GiveAmongst

_________________________________________________________________
Earn cashback on your purchases with Live Search - the search that pays you back!
http://search.live.com/cashback/?&pkw=form=MIJAAF/publ=HMTGL/crea=earncashback

Attachment: user_188221.ezm (zipped)
I want to change the ObjectFactory to use for unit testing so (I think) I need to be able to override struts.xml config settings.

I'm writing some code to unit test actions with the Interceptor stack.
I followed the links off the Guides page under "Unit Testing (TODO)'... these gave me some hints on how to proceed but since they both use Spring (and I don't) I could not get either to work.

Anyway... I was able to get a Dispatcher built using a mock ServletContext (not Spring's) and I was able to use it to create an ActionProxy.  So I feel I'm getting close.
(If anyone knows a better way or where better instructions on how to do this are please let me know.)

I'm using Guice for an ObjectFactory, declared using constants in the struts.xml file.

I need to be able to change the ObjectFactory for unit testing. Either turn off Guice so the default is used (and I will inject objects after I get the proxy) or be able to specify an alternate config (Guice module) for testing.

How can I override the settings in struts.xml for unit testing when creating the Dispatcher ?

Or, if there is a better way any advice would help.

Thanks.






Attachment: user_188225.ezm (zipped)

Hi all,

If the end-user input wrong date-type (eg., date format is incorrect, or for
'number of people' he types 'Q') the 'input' is fired and it shows the error
message.

I do that with the 'return input' and the jsp page (this is ajax-id) looks
like this:


<%@(protected)" %>

udpate Fail<BR>
<s:fielderror />


the problem is that the user see something like this:
Update fail:
Invalid field value for field "Car.returnDate".

obviously returnDate is a field name in Car (that's great for the
developers); but my question is this: How can I show a nice understandable
error message such as: 'error with car return date'


thanks for any pointers
* once again, this is only when the data-type is incorrect.

--
Sent from the Struts - User mailing list archive at Nabble.com.


Attachment: user_188226.ezm (zipped)

Hi all,

If the end-user input wrong date-type (eg., date format is incorrect, or for
'number of people' he types 'Q') the 'input' is fired and it shows the error
message.

I do that with the 'return input' and the jsp page (this is ajax-id) looks
like this:


<%@(protected)" %>

udpate Fail<BR>
<s:fielderror />


the problem is that the user see something like this:
Update fail:
Invalid field value for field "Car.returnDate".

obviously returnDate is a field name in Car (that's great for the
developers); but my question is this: How can I show a nice understandable
error message such as: 'error with car return date'


thanks for any pointers
* once again, this is only when the data-type is incorrect.

--
Sent from the Struts - User mailing list archive at Nabble.com.


Attachment: user_188227.ezm (zipped)
Type conversion errors are added separately from validation errors.

Among the options is to remove the conversion error interceptor from your interceptor stack and use only the validation errors.

Dave

--- On Thu, 6/26/08, xianwinwin <xianwinwin@(protected):

> From: xianwinwin <xianwinwin@(protected)>
> Subject: <s:fielderror /> - how to provide an understandable error message to the enduser?
> To: user@(protected)
> Date: Thursday, June 26, 2008, 6:35 PM
> Hi all,
>
> If the end-user input wrong date-type (eg., date format is
> incorrect, or for
> 'number of people' he types 'Q') the
> 'input' is fired and it shows the error
> message.
>
> I do that with the 'return input' and the jsp page
> (this is ajax-id) looks
> like this:
>
>
> <%@(protected)"
> uri="/struts-tags" %>
>
> udpate Fail<BR>
> <s:fielderror />
>
>
> the problem is that the user see something like this:
> Update fail:
> Invalid field value for field "Car.returnDate".
>
> obviously returnDate is a field name in Car (that's
> great for the
> developers); but my question is this: How can I show a nice
> understandable
> error message such as: 'error with car return date'
>
>
> thanks for any pointers
> * once again, this is only when the data-type is incorrect.
>
>
> --
> View this message in context:
> http://www.nabble.com/%3Cs%3Afielderror--%3E----how-to-provide-an-understandable-error-message-to-the-enduser--tp18144819p18144819.html
> Sent from the Struts - User mailing list archive at
> Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail:
> user-help@(protected)

Attachment: user_188228.ezm (zipped)
Al Sutton wrote:
> Dave,
>
> I'm completely agree it's a great idea and useful thing to do, but the
> problem is what to put into the cookie and how to map it to the user.
>
> My current favourite is encrypt the properties you want to store
> (using AES for speed and JCE support), then decrypt and inject when
> needed. Cookies should be considered limited to 4K (due to the joys of
> RFC2109 Section 6.3), so as long as the data fits joy shall be mine :).
>
> Al.

Hi Al,
Just another variation I use where the useragent requires javascript:
authenticate the user and generate a token; the token doesn't contain
any sensitive data;
the token is saved in a cookie and included in all requests (as cookie,
header or param)
an s2 interceptor checks the token is matched to an authenticated user.
it injects relevant details to actions
    (eg. a store maps tokens to users; server-side manages expiry,
concurrent logins etc)

It's not as fast as encoding login information in the cookie but it
can't be broken. I use the same method to sign XHR requests.

If the user has checked the "remember me" box the javascript gets the
token from the cookie and resumes using it. The server it knows not to
invalidate that token.

Vulnerabilities:
- The token should be unguessable to minimize forged requests;
- as javascript is inscecure, tokens can be stolen from the cookie
(eg. by an advertisement, XSS)

I wrote the above as an S2 plugin. The only problem with releasing it as
a plugin is that the "service that checks tokens" can't be
Xwork'@(protected)
spring or guice) due to its potential external dependencies (eg. an
EntityManager). The same plugin also allows me to apply roles to action
methods (jsr-250).

cheers,
Jeromy Evans


Attachment: user_188229.ezm (zipped)
Paranoid_Fabio wrote:
> Hello. I've a very strange problem using content disposition in stream
> result:
>
> <result name="success" type="stream">
>       ${contentType}
>      downloadStream
>      filename=${fileName}
>      1024
> </result>
>
> fileName is a field of my action class.
> When filename contains no spaces, everything goes fine. But if filename is
> something like "hello song.mp3"
> the browser shows that the file is "hello". I'm sure that the filename is
> correct in my action class because i logged it out.
> Any idea????
>
> thank u!
>
>  

If the filename contains spaces it needs to be in quotes (eg.
filename="${fileName}") The result does not encode the string for the
disposition header in any way.
Have a look at the HTTP header of your response to see if the full
filename is there.




Attachment: user_188230.ezm (zipped)
Hi Al,

thx! you made my day :-) that did the trick!
replacing freemarker 2.3.8 with 2.3.13 speeded up my application by almost
100%
It still doesn't come anywhere near my old struts2 application but I guess
its a fairly small trade-off when considering what struts2 has to offer.

--- joe

On Thu, Jun 26, 2008 at 5:09 PM, Al Sutton <al.sutton@(protected):

> If your benchmark uses multiple threads throw in a freemarker upgrade to
> 2.3.13 and have another spin :).
>
> One thing you might want to bear in mind is that if you're using a
> persistance framework there maybe some back end fetching taking place
> between a.b.c and a.b.c.d. Even though you write simple beans and accessors
> you can't guarentee whats happening to your objects under the covers.
>
> Al.
>
>
> yorlick kilroy wrote:
>
>> I replaced OGNL 2.6.11 with the latest 2.7.2 Version.
>> I did a bit of benchmarking comparing the two and it absolutely surprised
>> me, that 2.7.2 in some cases is almost twice as slow as 2.6.11
>> The test scenario:
>> iterate a large java.util.List in a jsp. the List contains a pretty large
>> tree of objects. in the jsp I access a String property in the last node of
>> this object graph. OGNL 2.6.11 takes roughly 600 ms to complete, 2.7.2
>> roughly 1050 ms
>>
>> From that I gather that OGNL wasn't designed for high performance when
>> processing large and complex object trees in jsps. I guess I'll have to go
>> back and do it like in the old Struts1 days: use shallow objects like in
>> ActionForms
>>
>> On Wed, Jun 25, 2008 at 8:31 PM, Dale Newfield <Dale@(protected):
>>
>>
>>
>>> yorlick kilroy wrote:
>>>
>>>
>>>
>>>> Still... the "problem" seems to be the OGNL implementation in struts2.
>>>>
>>>>
>>>>
>>> I'm guessing here, but maybe your issues are related to:
>>>
>>> http://jira.opensymphony.com/browse/OGNL-141
>>>
>>> Which has been pushed off in Xwork to 2.5:
>>>
>>> http://jira.opensymphony.com/browse/XW-631
>>>
>>> And which has been pushed off in Struts2 until at least 2.1.3:
>>>
>>> https://issues.apache.org/struts/browse/WW-2128
>>>
>>> You're welcome to update the version of ognl you're using in your own app
>>> (but remember to add javassist if so).
>>>
>>> <s:iterate ... >
>>>
>>>
>>>>   <s:property value="#object.a.b.c.name"/>
>>>>   <s:property value="#object.a.b.c.phone"/>
>>>> </s:iterate>
>>>>
>>>>
>>>>
>>> Theoretically this translates to a straight lookup for #object, then
>>> getA().getB().getC().getName()...
>>> If A, B, and C are just accessors, it should be fast. If they do much
>>> work
>>> to determine what to return, you're doing that work 2*N times (where N is
>>> the number of times through the loop) instead of just once...why would
>>> you
>>> put a long lookup like that in an iterator if it doesn't change with each
>>> iteration?
>>>
>>> -Dale
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>> For additional commands, e-mail: user-help@(protected)
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>

Attachment: user_188231.ezm (zipped)
Hi Laurie,

  Thanks for your reply.

   i found a work around for this. if i am applying as below, my
application could read the values from resource bundle. :) this problem is
solved.

<s:form action="clientAction" theme="simple">
  <tr>
     <td><s:label value="%{getText('app.clientname')}" /></td>
     <td><s:textfield name="clientname" required="true" /></td>
  </tr>
    -----
but here it introduced one more problem, with the xhtml theme we get the
field level validation error messages below the individual control, but the
simple theme is not giving any validation error messages. to get the errors
i used <s:fielderror /> ,it is giving all the field level errors at one
place.

is there any way i can get the filed level error messages as they come in
xhtml theme with simple theme ?





On Fri, Jun 27, 2008 at 12:06 AM, Laurie Harper <laurie@(protected):

> To repeat my previous question:
>
> >> How is it failing? Note that the 'simple' theme generates a lot less
> >> markup, and doesn't generate everything the other themes do. Are I18N
> >> resources failing to get resolved, or is the theme just not generating
> the
> >> things you were expecting to see?
>
> With the simple theme, I would expect the s:label to work the same way, but
> the s:textfield to generate no label (because the simple theme doesn't do
> that). If that's what you're seeing, that's the correct behaviour. If you
> are seeing something different, you need to describe exactly what that is.
>
> L.
>
>
> Narayana S wrote:
>
>> Hi laurie,
>>
>>      <s:form action="TestAction" method="post">
>>     <s:label key="app.indexheader" />
>>     <s:textfield name="cname" key="app.cname"/><br>
>>
>> This is part of the form i am creating, when the theme is default the
>> label
>> could get value app.indexheader from resource bundle and working fine, the
>> text fields also could generate a label with the values given for
>> app.cname,
>> but when simple theme is given ( like <s:form action="TestAction"
>> method="post" theme="simple"> ) the label is not rendered!!
>>
>> can you help me on solving this >?
>>
>>
>> On Mon, Jun 23, 2008 at 11:18 PM, Laurie Harper <laurie@(protected)>
>> wrote:
>>
>> Narayana S wrote:
>>>
>>> Hi Dave,
>>>>
>>>>   thanks for your reply, but when i use simple theme, my application is
>>>> not getting any values from resource bundle..
>>>>
>>>> How is it failing? Note that the 'simple' theme generates a lot less
>>> markup, and doesn't generate everything the other themes do. Are I18N
>>> resources failing to get resolved, or is the theme just not generating
>>> the
>>> things you were expecting to see?
>>>
>>> will this problem be solved by extending theme ?
>>>
>>>> can you provide any best link to extend a theme if it is the solution...
>>>> ?
>>>>
>>>> See the Themes and Templates documentation:
>>>
>>> http://struts.apache.org/2.0.11.1/docs/themes-and-templates.html
>>>
>>> L.
>>>
>>>
>>> On Sun, Jun 22, 2008 at 8:25 PM, Dave Newton <newton.dave@(protected)>
>>>
>>>> wrote:
>>>>
>>>> --- On Sun, 6/22/08, Narayana S <narayanasgs1@(protected):
>>>>
>>>>> The problem is here struts 2 is applying it's own styles to
>>>>>> my page, i want to give my own styles instead of using struts
>>>>>> default styles,
>>>>>>
>>>>>> The easiest answer is to just supply your own CSS styles. You can
>>>>> also
>>>>> extend an existing, or create your own, theme.
>>>>>
>>>>> Dave
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>>>> For additional commands, e-mail: user-help@(protected)
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@(protected)
>>> For additional commands, e-mail: user-help@(protected)
>>>
>>>
>>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>
©2008 gg3721.com - Jax Systems, LLC, U.S.A.