You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ma...@ensam.eu on 2011/02/17 09:06:34 UTC
Multiple field and modelDriven
Hi everybody,
I have a class named User which contain some information about user .
I have made a form in my JSP and an action which is modelDriven with my User class.
Public class User implements modelDriven<User>{}...
My question is about multiple field with same id in my JSP. My User class have a field named streetaddresses (which is linked with an active directory field of the same name). In my form, I want to put 3 input field for streetaddresses (streetaddresses line 1, streetaddresses line2 and streetaddresses line3).
If I do this, the three field will be concatenated using comma (line1, line2, line3)
Is there a way to change the separator comma with another thing (like \r\n) ? (line1\r\nline2\r\nline3)
And will it will prepopulate the three field splitting the getStreetAddresses field using the separator when I will want to make a form to modify informations ?
Streetaddresses = line1\r\nline2\r\nline3\r\n -> streetaddresses line1 = line1 -> streetaddresses line2 = line2....
Thanks
Matthieu MARC
------
Matthieu.marc@ensam.eu<ma...@ensam.eu>
Responsable du Service Informatique
Arts et Métiers ParisTech - Angers
RE: Multiple field and modelDriven
Posted by Ma...@ensam.eu.
I used the struts 2.2.1.1 version
-----Message d'origine-----
De : Maurizio Cucchiara [mailto:maurizio.cucchiara@gmail.com]
Envoyé : jeudi 17 février 2011 10:28
À : Struts Users Mailing List
Objet : Re: Multiple field and modelDriven
Which struts version?
Maurizio Cucchiara
Il giorno 17/feb/2011 09.07, <Ma...@ensam.eu> ha scritto:
> Hi everybody,
>
> I have a class named User which contain some information about user .
>
> I have made a form in my JSP and an action which is modelDriven with
> my
User class.
>
> Public class User implements modelDriven<User>{}...
>
> My question is about multiple field with same id in my JSP. My User
> class
have a field named streetaddresses (which is linked with an active directory field of the same name). In my form, I want to put 3 input field for streetaddresses (streetaddresses line 1, streetaddresses line2 and streetaddresses line3).
> If I do this, the three field will be concatenated using comma (line1,
line2, line3)
>
> Is there a way to change the separator comma with another thing (like
\r\n) ? (line1\r\nline2\r\nline3)
>
> And will it will prepopulate the three field splitting the
getStreetAddresses field using the separator when I will want to make a form to modify informations ?
>
> Streetaddresses = line1\r\nline2\r\nline3\r\n -> streetaddresses line1
> =
line1 -> streetaddresses line2 = line2....
>
> Thanks
>
> Matthieu MARC
>
> ------
> Matthieu.marc@ensam.eu<ma...@ensam.eu>
> Responsable du Service Informatique
> Arts et Métiers ParisTech - Angers
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Multiple field and modelDriven
Posted by Maurizio Cucchiara <ma...@gmail.com>.
Which struts version?
Maurizio Cucchiara
Il giorno 17/feb/2011 09.07, <Ma...@ensam.eu> ha scritto:
> Hi everybody,
>
> I have a class named User which contain some information about user .
>
> I have made a form in my JSP and an action which is modelDriven with my
User class.
>
> Public class User implements modelDriven<User>{}...
>
> My question is about multiple field with same id in my JSP. My User class
have a field named streetaddresses (which is linked with an active directory
field of the same name). In my form, I want to put 3 input field for
streetaddresses (streetaddresses line 1, streetaddresses line2 and
streetaddresses line3).
> If I do this, the three field will be concatenated using comma (line1,
line2, line3)
>
> Is there a way to change the separator comma with another thing (like
\r\n) ? (line1\r\nline2\r\nline3)
>
> And will it will prepopulate the three field splitting the
getStreetAddresses field using the separator when I will want to make a form
to modify informations ?
>
> Streetaddresses = line1\r\nline2\r\nline3\r\n -> streetaddresses line1 =
line1 -> streetaddresses line2 = line2....
>
> Thanks
>
> Matthieu MARC
>
> ------
> Matthieu.marc@ensam.eu<ma...@ensam.eu>
> Responsable du Service Informatique
> Arts et Métiers ParisTech - Angers
>
RE : RE: Multiple field and modelDriven
Posted by Ma...@ensam.eu.
Thanks, for the information, I was an aspect of Struts2 I have not yet learned. So I do, and it is very interesting.
I tried to go this way for my problem.
My Action class : public class myAction implements ModelDriver<User>;
My User class from another java package : public class User { public String getStreetAddress(); public void setStreetAddress(String value); }
I create a file : src/org/another/java/package/User-conversion.properties containing : streetAddress=org.myapp.conversion.AddressConverter
My converter class is :
public class AddressConverter extends StrutsTypeConverter {
@Override
public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
// TODO
return null;
}
@Override
public String convertToString(Map arg0, Object arg1) {
StringBuffer strbuf = new StringBuffer();
if (arg1 instanceof String[]){
String[] addr = (String[])arg1;
for (int i=0; i<addr.length; i++){
strbuf.append(addr[i]);
strbuf.append("\r\n");
}
return strbuf.toString();
}
return null;
}
}
My JSP file is :
<s:form>
<s:textfield key="address.streetAddress" id="streetAddress1" name="address.streetAddress" />
<s:textfield key="address.streetAddress" id="streetAddress2" name="address.streetAddress" />
</s:form>
When submitting the form, convertToString() is called and conversion is done.
#streetAddress1=line1,#streetAddres2=line2 -> convertToString() -> return "line1\r\nline2\r\n" -> User.setStreetAddress("line1\r\nline2\r\n");
My problem is now when returning info the form, when prepopulating form field. The convertToString() is called (I was thinking I will be the other one convertFromString() but not). And so I am not able to split my User.getStreetAddress() value in order to put value into the String[].
Matthieu MARC
----
Matthieu MARC
Service Informatique
Arts et Métiers ParisTech - Centre d'Angers
matthieu.marc@ensam.eu
________________________________________
De : Maurizio Cucchiara [maurizio.cucchiara@gmail.com]
Date d'envoi : jeudi 17 février 2011 10:41
À : Struts Users Mailing List
Objet : Re: RE: Multiple field and modelDriven
I'm not sure, maybe type conversion is the answer to your question.
Have you already seen this [1]?
[1] http://struts.apache.org/2.2.1/docs/type-conversion.html
Maurizio Cucchiara
Il giorno 17/feb/2011 10.36, <Ma...@ensam.eu> ha scritto:
> My User Class came from another java library which bind User class to an
Active Directory User. I would like to find a solution without modifying
this java library.
>
> ... but If there is no solution, I will modify my User class.
>
> Matthieu MARC
>
>
> -----Message d'origine-----
> De : Maurizio Cucchiara [mailto:maurizio.cucchiara@gmail.com]
> Envoyé : jeudi 17 février 2011 10:31
> À : Struts Users Mailing List
> Objet : Re: Multiple field and modelDriven
>
> Pardon, I didn't see model driven stuff.
> Have you tryied to change your address field to an array string or a
simple collection?
>
> Maurizio Cucchiara
>
> Il giorno 17/feb/2011 09.07, <Ma...@ensam.eu> ha scritto:
>> Hi everybody,
>>
>> I have a class named User which contain some information about user .
>>
>> I have made a form in my JSP and an action which is modelDriven with
>> my
> User class.
>>
>> Public class User implements modelDriven<User>{}...
>>
>> My question is about multiple field with same id in my JSP. My User
>> class
> have a field named streetaddresses (which is linked with an active
directory field of the same name). In my form, I want to put 3 input field
for streetaddresses (streetaddresses line 1, streetaddresses line2 and
streetaddresses line3).
>> If I do this, the three field will be concatenated using comma (line1,
> line2, line3)
>>
>> Is there a way to change the separator comma with another thing (like
> \r\n) ? (line1\r\nline2\r\nline3)
>>
>> And will it will prepopulate the three field splitting the
> getStreetAddresses field using the separator when I will want to make a
form to modify informations ?
>>
>> Streetaddresses = line1\r\nline2\r\nline3\r\n -> streetaddresses line1
>> =
> line1 -> streetaddresses line2 = line2....
>>
>> Thanks
>>
>> Matthieu MARC
>>
>> ------
>> Matthieu.marc@ensam.eu<ma...@ensam.eu>
>> Responsable du Service Informatique
>> Arts et Métiers ParisTech - Angers
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: RE: Multiple field and modelDriven
Posted by Maurizio Cucchiara <ma...@gmail.com>.
I'm not sure, maybe type conversion is the answer to your question.
Have you already seen this [1]?
[1] http://struts.apache.org/2.2.1/docs/type-conversion.html
Maurizio Cucchiara
Il giorno 17/feb/2011 10.36, <Ma...@ensam.eu> ha scritto:
> My User Class came from another java library which bind User class to an
Active Directory User. I would like to find a solution without modifying
this java library.
>
> ... but If there is no solution, I will modify my User class.
>
> Matthieu MARC
>
>
> -----Message d'origine-----
> De : Maurizio Cucchiara [mailto:maurizio.cucchiara@gmail.com]
> Envoyé : jeudi 17 février 2011 10:31
> À : Struts Users Mailing List
> Objet : Re: Multiple field and modelDriven
>
> Pardon, I didn't see model driven stuff.
> Have you tryied to change your address field to an array string or a
simple collection?
>
> Maurizio Cucchiara
>
> Il giorno 17/feb/2011 09.07, <Ma...@ensam.eu> ha scritto:
>> Hi everybody,
>>
>> I have a class named User which contain some information about user .
>>
>> I have made a form in my JSP and an action which is modelDriven with
>> my
> User class.
>>
>> Public class User implements modelDriven<User>{}...
>>
>> My question is about multiple field with same id in my JSP. My User
>> class
> have a field named streetaddresses (which is linked with an active
directory field of the same name). In my form, I want to put 3 input field
for streetaddresses (streetaddresses line 1, streetaddresses line2 and
streetaddresses line3).
>> If I do this, the three field will be concatenated using comma (line1,
> line2, line3)
>>
>> Is there a way to change the separator comma with another thing (like
> \r\n) ? (line1\r\nline2\r\nline3)
>>
>> And will it will prepopulate the three field splitting the
> getStreetAddresses field using the separator when I will want to make a
form to modify informations ?
>>
>> Streetaddresses = line1\r\nline2\r\nline3\r\n -> streetaddresses line1
>> =
> line1 -> streetaddresses line2 = line2....
>>
>> Thanks
>>
>> Matthieu MARC
>>
>> ------
>> Matthieu.marc@ensam.eu<ma...@ensam.eu>
>> Responsable du Service Informatique
>> Arts et Métiers ParisTech - Angers
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
RE: Multiple field and modelDriven
Posted by Ma...@ensam.eu.
My User Class came from another java library which bind User class to an Active Directory User. I would like to find a solution without modifying this java library.
... but If there is no solution, I will modify my User class.
Matthieu MARC
-----Message d'origine-----
De : Maurizio Cucchiara [mailto:maurizio.cucchiara@gmail.com]
Envoyé : jeudi 17 février 2011 10:31
À : Struts Users Mailing List
Objet : Re: Multiple field and modelDriven
Pardon, I didn't see model driven stuff.
Have you tryied to change your address field to an array string or a simple collection?
Maurizio Cucchiara
Il giorno 17/feb/2011 09.07, <Ma...@ensam.eu> ha scritto:
> Hi everybody,
>
> I have a class named User which contain some information about user .
>
> I have made a form in my JSP and an action which is modelDriven with
> my
User class.
>
> Public class User implements modelDriven<User>{}...
>
> My question is about multiple field with same id in my JSP. My User
> class
have a field named streetaddresses (which is linked with an active directory field of the same name). In my form, I want to put 3 input field for streetaddresses (streetaddresses line 1, streetaddresses line2 and streetaddresses line3).
> If I do this, the three field will be concatenated using comma (line1,
line2, line3)
>
> Is there a way to change the separator comma with another thing (like
\r\n) ? (line1\r\nline2\r\nline3)
>
> And will it will prepopulate the three field splitting the
getStreetAddresses field using the separator when I will want to make a form to modify informations ?
>
> Streetaddresses = line1\r\nline2\r\nline3\r\n -> streetaddresses line1
> =
line1 -> streetaddresses line2 = line2....
>
> Thanks
>
> Matthieu MARC
>
> ------
> Matthieu.marc@ensam.eu<ma...@ensam.eu>
> Responsable du Service Informatique
> Arts et Métiers ParisTech - Angers
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Multiple field and modelDriven
Posted by Maurizio Cucchiara <ma...@gmail.com>.
Pardon, I didn't see model driven stuff.
Have you tryied to change your address field to an array string or a simple
collection?
Maurizio Cucchiara
Il giorno 17/feb/2011 09.07, <Ma...@ensam.eu> ha scritto:
> Hi everybody,
>
> I have a class named User which contain some information about user .
>
> I have made a form in my JSP and an action which is modelDriven with my
User class.
>
> Public class User implements modelDriven<User>{}...
>
> My question is about multiple field with same id in my JSP. My User class
have a field named streetaddresses (which is linked with an active directory
field of the same name). In my form, I want to put 3 input field for
streetaddresses (streetaddresses line 1, streetaddresses line2 and
streetaddresses line3).
> If I do this, the three field will be concatenated using comma (line1,
line2, line3)
>
> Is there a way to change the separator comma with another thing (like
\r\n) ? (line1\r\nline2\r\nline3)
>
> And will it will prepopulate the three field splitting the
getStreetAddresses field using the separator when I will want to make a form
to modify informations ?
>
> Streetaddresses = line1\r\nline2\r\nline3\r\n -> streetaddresses line1 =
line1 -> streetaddresses line2 = line2....
>
> Thanks
>
> Matthieu MARC
>
> ------
> Matthieu.marc@ensam.eu<ma...@ensam.eu>
> Responsable du Service Informatique
> Arts et Métiers ParisTech - Angers
>