Re: JSON plugin suggest : parse String value to Number with null / 0
Thanks,Maurizio, This is not a wrong approach. but can be take a improved for easier use. :P Regards. On Tue, Nov 23, 2010 at 12:10 PM, Maurizio Cucchiara maurizio.cucchi...@gmail.com wrote: Hi Knight, I take your point, JSONPopulator.convertPrimitive function maybe uses a wrong approach. Does anyone know why convert method process is driven by value and type instead of target type only? 2010/11/23 Knight Chen dolt131...@gmail.com Hi All, Thanks for reply, and sorry for my poor English. In this case: I have a POJO: public class UserDTO { private int age; ... public void setAge(int age) { this.age = age; } } And Action has a property with this type: public Class UserAction { private UserDTO userInfo; ... public void setUserInfo(UserDTO userInfo { this.userInfo = userInfo; } ... } when I use ajax request and JSON format to transfer this UserDTO obj, this UserDTO is Serialization from html page's text input field, and age input field is empty(user not enter and business logic allow this), then this JSON String will be like this: {'userInfo' : { 'age' : ''}} so, when use JSON plugin to parse this JSON string to UserAction's userInfo property,there will be a Number format exception ( for input String ) I check JSONPopulator.java , it has process null value for int(or other number primitive type) with default value 0, I think if it can parse the to int/Integer(or other number type) with 0/null like the same process above mentioned, if do this will easier the front process, because front JS code will not to check the age's type,and transform the empty text input value to null. Just a suggeset. Thanks all. Regards, On Tue, Nov 23, 2010 at 9:46 AM, Maurizio Cucchiara maurizio.cucchi...@gmail.com wrote: I'm not sure understand what you mean, it could be ognl conversion related. For further details, could you provide the NPE stack? 2010/11/22 Knight Chen dolt131...@gmail.com Hi all, I often encounter Number format exception when I use JSON plugin to parse input String from AJAX request to Number, because in Web front, that will be a zero length String transfer to backend if the text input has no enter, so will encounter the Number format exception for input String . I check the JSONPopulator, that has process the null value to 0 when parse to Number type, but not process the String , So can JSONPopulator to support process String to null or 0,that will be easier web front develop. -- Knight Chen - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Maurizio Cucchiara -- Knight Chen - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Maurizio Cucchiara -- Knight Chen - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
RE: JSON plugin suggest : parse String value to Number with null / 0
driven off the Introspector.getBeanInfo public void populateObject(Object object, final Map elements) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, IntrospectionException, IllegalArgumentException, JSONException, InstantiationException { Class clazz = object.getClass(); BeanInfo info = Introspector.getBeanInfo(clazz); from the object parameter sent as first parameter to populateObject e.g. rootObject = invocation.getAction(); if ((contentType != null) contentType.equalsIgnoreCase(application/json)) { // load JSON object Object obj = JSONUtil.deserialize(request.getReader()); if (obj instanceof Map) { Map json = (Map) obj; // clean up the values if (dataCleaner != null) dataCleaner.clean(, json); // populate fields populator.populateObject(rootObject, json); if the target attribute is available in object acquired by invocation.getAction() then you should see the target does this answer your question? Happy Thanksgiving to one and all Martin __ Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni. Date: Wed, 24 Nov 2010 20:16:45 +0800 Subject: Re: JSON plugin suggest : parse String value to Number with null / 0 From: dolt131...@gmail.com To: user@struts.apache.org Thanks,Maurizio, This is not a wrong approach. but can be take a improved for easier use. :P Regards. On Tue, Nov 23, 2010 at 12:10 PM, Maurizio Cucchiara maurizio.cucchi...@gmail.com wrote: Hi Knight, I take your point, JSONPopulator.convertPrimitive function maybe uses a wrong approach. Does anyone know why convert method process is driven by value and type instead of target type only? 2010/11/23 Knight Chen dolt131...@gmail.com Hi All, Thanks for reply, and sorry for my poor English. In this case: I have a POJO: public class UserDTO { private int age; ... public void setAge(int age) { this.age = age; } } And Action has a property with this type: public Class UserAction { private UserDTO userInfo; ... public void setUserInfo(UserDTO userInfo { this.userInfo = userInfo; } ... } when I use ajax request and JSON format to transfer this UserDTO obj, this UserDTO is Serialization from html page's text input field, and age input field is empty(user not enter and business logic allow this), then this JSON String will be like this: {'userInfo' : { 'age' : ''}} so, when use JSON plugin to parse this JSON string to UserAction's userInfo property,there will be a Number format exception ( for input String ) I check JSONPopulator.java , it has process null value for int(or other number primitive type) with default value 0, I think if it can parse the to int/Integer(or other number type) with 0/null like the same process above mentioned, if do this will easier the front process, because front JS code will not to check the age's type,and transform the empty text input value to null. Just a suggeset. Thanks all. Regards, On Tue, Nov 23, 2010 at 9:46 AM, Maurizio Cucchiara maurizio.cucchi...@gmail.com wrote: I'm not sure understand what you mean, it could be ognl conversion related. For further details, could you provide the NPE stack? 2010/11/22 Knight Chen dolt131...@gmail.com Hi all, I often encounter Number format exception when I use JSON plugin to parse input String from AJAX request to Number, because in Web front, that will be a zero length String transfer to backend if the text input has no enter, so will encounter the Number format exception for input String . I check the JSONPopulator, that has process the null value to 0 when parse to Number type, but not process
Re: Spring context for package
Josep -- That sounds a little radical. Do you mind if I ask why? Is the unique namespace per package not enough separation? Hey, if strict separation is what you desire, you could package each S2 package in it's own project and move the package namespace to the web root context and be done with it. Is your multi-package web application really multiple web applications? Peace, Scott 2010/11/24 Josep María Formentí Serra jmforme...@aia.es Scott, it's interesting, I didn't know that, but i would like to have different application context in the same war, specifically, i would like to have an application context for each package that is defined in struts.xml. Thanks, Josep Maria 2010/11/17 stanl...@gmail.com Josep -- I believe this is what you are looking for. http://blog.springsource.com/2007/06/11/using-a-shared-parent-application-context-in-a-multi-war-spring-application/ Peace, Scott 2010/11/17 Josep María Formentí Serra jmforme...@aia.es Thanks Dave and Chris, Chris, that it's nice, we are going to modify it in our project. But our real problem is that we have two independent modules (and struts package for each one) and many spring beans have the same name. Then we have to change bean names when we detect a conflict. I think it will be better have a separated spring context for module (or struts package). I think that one solution is use an struts interceptor to get the spring beans (something like com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor) but my knowledge about that it's very poor. Josep Maria 2010/11/12 Chris Pratt thechrispr...@gmail.com If you are talking about per Java package, not that I know of. If you mean per Struts package, same thing. But if you mean per jar file, there is a way. If you set your contextConfigLocation to something like WEB-INF/applicationContext.xml,classpath*:pluginContext.xml then Spring will load your Application wide context from the WEB-INF directory (or you can make that WEB-INF/classes if you want), then it will load each pluginContext.xml file it finds on the CLASSPATH. Since the root directory of each jar file in the WEB-INF/lib directory is considered to be on the CLASSPATH, it will automatically include those beans, kind of like the start of a Plug-In architecture. You can so a similar thing with the struts-plugin.xml support built into Struts 2 to make a pretty robust Plug-in system in your application. (*Chris*) 2010/11/12 Josep María Formentí Serra jmforme...@aia.es Hi, We are working in a new project using struts2 + spring + hibernate. We have many packages defined in struts.xml, one for module. We have configured spring using this guide: http://struts.apache.org/2.0.14/docs/spring-plugin.html, where you define one spring context (using the context param: contextConfigLocation). Is it possible to define a different spring context for each struts package? Thanks in advance, Josep Maria -- --- -- - - - Grupo AIA - http://www.aia.es Josep Mª Formentí Serra jmforme...@aia.ptv.es Telf.: +34 93 504 49 00 Fax.: +34 93 580 21 88 --- -- - - - _ ___ __ _ _ _ _ The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. -- --- -- - - - Grupo AIA - http://www.aia.es Josep Mª Formentí Serra jmforme...@aia.ptv.es Telf.: +34 93 504 49 00 Fax.: +34 93 580 21 88 --- -- - - - _ ___ __ _ _ _ _ The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and
Re: JSON plugin suggest : parse String value to Number with null / 0
2010/11/24 Martin Gainty mgai...@hotmail.com if the target attribute is available in object acquired by invocation.getAction() then you should see the target does this answer your question? Actually, It doesn't. I meant that conversion methods like convertPrimitive (see the code below) use to take class type and value as argument and they always try to understand the kind of type they're facing, choosing by value (for this reason I called value driven). Why don't they choose conversion by type destination? private Object convertPrimitive(Class clazz, Object value, Method method) throws JSONException { if (value == null) { if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) return (short) 0; ... } else if (value instanceof Number) { Number number = (Number) value; -- Maurizio Cucchiara
Issue regarding error messages
Hi I am using s:actionerror /, where the messages will pulled from the resource bundle. I want my messages to be on the bottom of the fields rather than top of the field. Thanks Prabhu
Re: JSON plugin suggest : parse String value to Number with null / 0
Does this possible? In source code: Object org.apache.struts2.json.JSONPopulator.convertPrimitive(Class clazz, Object value, Method method) throws JSONException { if (value == null) { if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) return (short) 0; else if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) return (byte) 0; else if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) return 0; else if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) return 0L; else if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) return 0f; else if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) return 0d; else if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) return Boolean.FALSE; else return null; } else if … I suggest change the first line to (or other more reasonable code like this) : If (value == null || ( !String.class.equals(clazz) (value instanceof String) (.equals(value { ... this can process empty string to a right value, and no throw a Exception : Number formcat exception for input string . does it more smart? sorry for my poor english. Regards. On Thu, Nov 25, 2010 at 12:43 AM, Maurizio Cucchiara maurizio.cucchi...@gmail.com wrote: 2010/11/24 Martin Gainty mgai...@hotmail.com if the target attribute is available in object acquired by invocation.getAction() then you should see the target does this answer your question? Actually, It doesn't. I meant that conversion methods like convertPrimitive (see the code below) use to take class type and value as argument and they always try to understand the kind of type they're facing, choosing by value (for this reason I called value driven). Why don't they choose conversion by type destination? private Object convertPrimitive(Class clazz, Object value, Method method) throws JSONException { if (value == null) { if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) return (short) 0; ... } else if (value instanceof Number) { Number number = (Number) value; -- Maurizio Cucchiara -- Knight Chen - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Issue regarding error messages
You can define *labelposition*=top on css_xhtml theme. take a look at http://struts.apache.org/2.1.8/docs/cssxhtml-theme.html 2010/11/24 Prabhubalaji Ragavan prabhubalaji.raga...@gmail.com Hi I am using s:actionerror /, where the messages will pulled from the resource bundle. I want my messages to be on the bottom of the fields rather than top of the field. Thanks Prabhu -- Maurizio Cucchiara
Re: Issue regarding error messages
Sorry, I said something stupid. Forget it. Anyway in that page you can see how define css position of error messages .errorLabel {font-style:italic; color:red; } .errorMessage {font-weight:bold; text-align: center; color:red; } .checkboxLabel {} .checkboxErrorLabel {color:red; } .required {color:red;} It would be enough otherwise you should consider to overwrite template. 2010/11/25 Maurizio Cucchiara maurizio.cucchi...@gmail.com You can define *labelposition*=top on css_xhtml theme. take a look at http://struts.apache.org/2.1.8/docs/cssxhtml-theme.html 2010/11/24 Prabhubalaji Ragavan prabhubalaji.raga...@gmail.com Hi I am using s:actionerror /, where the messages will pulled from the resource bundle. I want my messages to be on the bottom of the fields rather than top of the field. Thanks Prabhu -- Maurizio Cucchiara -- Maurizio Cucchiara