You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by kaouki <in...@gmail.com> on 2007/10/25 16:19:41 UTC

[S2] Problem while retrieving data from JSP

Hi,
I get this bean in my action in order to modify it in my jsp:
Catalogue {
Long id;
String title;
String description;
Collection<Produit> produits
}
In this jsp, I have two fieds: title and description, and a table of Produit
with checkboxes.
These ones enable the user to remove the products from the catalogue.

In my save action, I get the catalogue (property of the action) and a Long[]
(the id of the checked products).
The problem is that the Products Collection of the Catalogue and its id are
null.

So, if I want update some attributes of my bean, I have to put the bean in
Session ? or all the unchanged attributes in hidden fields ?

I'm grateful for any input on the matter. Cheers.
-- 
View this message in context: http://www.nabble.com/-S2--Problem-while-retrieving-data-from-JSP-tf4691128.html#a13407615
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] Problem while retrieving data from JSP

Posted by kaouki <in...@gmail.com>.
Ok, but I don't understand... ^^
Here is my Action:
public class CatalogueAction extends ActionSupport {
private Catalogue catalogue;
(...)
@RequiredStringValidator(message = "Titre obligatoire", fieldName =
"catalogue.titre")
    public String save() {
        if (logger.isInfoEnabled()) {
            logger.info("[WEB] Sauvegarde du catalogue");
        }
        this.catalogueService.saveOrUpdateCatalogue(catalogue);
       
this.addActionMessage(this.messageResources.getMessage("catalogue.save.success",
getLocale()));
        return Action.SUCCESS;
    }
}
In my edit.jsp, I have this form:
<s:form action="save" validate="true">
	<s:hidden name="catalogue.id" value="catalogue.id" />
	<tr>
		<td><s:textfield id="titre" label="Titre" name="catalogue.titre" /></td>
	</tr>
	<tr>
		<td><s:textfield id="description" label="description"
name="catalogue.description"/></td>
	</tr>
...

When the user submits this form, I get the catalogue in my Action but just
with the new values, and the others are set to null.
So, when I have to re-attach the object ? before the save action ?


newton.dave wrote:
> 
> You don't have to put the values not on the form in
> hidden fields: if you have the ID then you re-attach
> the Hibernate object, set the new values that were on
> the form, and update.
> 
> Unless you keep the actual object in session (whether
> you do it via ScopedModelDriven or not isn't
> relevant), or never detach it from the Hibernate
> session, I'm not sure what else you can do
> 
> d.
> 
> --- kaouki <in...@gmail.com> wrote:
> 
>> 
>> I would like to find a better way to do that ... if
>> it is possible ...
>> Because I would have the same probleme with all my
>> beans (Hibernate
>> entities).
>> 
>> If I want to render an entity bean E in my view
>> (with 4 or 5 properties,
>> nested beans or not), and the user updates 2
>> properties and submits the
>> form, I get E with the 2 updated properties but the
>> others are set to null.
>> So I can not merge my udpated entity (in my
>> Hibernate Dao) ... 
>> 
>> Is there a solution to avoid that ? Perhaps by using
>> interceptors like
>> Preparable or ModelDriven ?
>> 
>> 
>> Igor Vlasov wrote:
>> > 
>> > I think you must put the ID's in hidden fields and
>> then they will fill up
>> > with id's from your collection on jsp page
>> > 
>> > In save method  wou will analyse the recieved
>> data.
>> > 
>> > 
>> > kaouki wrote:
>> >> 
>> >> Hi,
>> >> I get this bean in my action in order to modify
>> it in my jsp:
>> >> Catalogue {
>> >> Long id;
>> >> String title;
>> >> String description;
>> >> Collection<Produit> produits
>> >> }
>> >> In this jsp, I have two fieds: title and
>> description, and a table of
>> >> Produit with checkboxes.
>> >> These ones enable the user to remove the products
>> from the catalogue.
>> >> 
>> >> In my save action, I get the catalogue (property
>> of the action) and a
>> >> Long[] (the id of the checked products).
>> >> The problem is that the Products Collection of
>> the Catalogue and its id
>> >> are null.
>> >> 
>> >> So, if I want update some attributes of my bean,
>> I have to put the bean
>> >> in Session ? or all the unchanged attributes in
>> hidden fields ?
>> >> 
>> >> I'm grateful for any input on the matter. Cheers.
>> >> 
>> > 
>> > 
>> 
>> -- 
>> View this message in context:
>>
> http://www.nabble.com/-S2--Problem-while-retrieving-data-from-JSP-tf4691128.html#a13426242
>> Sent from the Struts - User mailing list archive at
>> Nabble.com.
>> 
>> 
>>
> ---------------------------------------------------------------------
>> 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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Problem-while-retrieving-data-from-JSP-tf4691128.html#a13427449
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] Problem while retrieving data from JSP

Posted by Dave Newton <ne...@yahoo.com>.
You don't have to put the values not on the form in
hidden fields: if you have the ID then you re-attach
the Hibernate object, set the new values that were on
the form, and update.

Unless you keep the actual object in session (whether
you do it via ScopedModelDriven or not isn't
relevant), or never detach it from the Hibernate
session, I'm not sure what else you can do

d.

--- kaouki <in...@gmail.com> wrote:

> 
> I would like to find a better way to do that ... if
> it is possible ...
> Because I would have the same probleme with all my
> beans (Hibernate
> entities).
> 
> If I want to render an entity bean E in my view
> (with 4 or 5 properties,
> nested beans or not), and the user updates 2
> properties and submits the
> form, I get E with the 2 updated properties but the
> others are set to null.
> So I can not merge my udpated entity (in my
> Hibernate Dao) ... 
> 
> Is there a solution to avoid that ? Perhaps by using
> interceptors like
> Preparable or ModelDriven ?
> 
> 
> Igor Vlasov wrote:
> > 
> > I think you must put the ID's in hidden fields and
> then they will fill up
> > with id's from your collection on jsp page
> > 
> > In save method  wou will analyse the recieved
> data.
> > 
> > 
> > kaouki wrote:
> >> 
> >> Hi,
> >> I get this bean in my action in order to modify
> it in my jsp:
> >> Catalogue {
> >> Long id;
> >> String title;
> >> String description;
> >> Collection<Produit> produits
> >> }
> >> In this jsp, I have two fieds: title and
> description, and a table of
> >> Produit with checkboxes.
> >> These ones enable the user to remove the products
> from the catalogue.
> >> 
> >> In my save action, I get the catalogue (property
> of the action) and a
> >> Long[] (the id of the checked products).
> >> The problem is that the Products Collection of
> the Catalogue and its id
> >> are null.
> >> 
> >> So, if I want update some attributes of my bean,
> I have to put the bean
> >> in Session ? or all the unchanged attributes in
> hidden fields ?
> >> 
> >> I'm grateful for any input on the matter. Cheers.
> >> 
> > 
> > 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/-S2--Problem-while-retrieving-data-from-JSP-tf4691128.html#a13426242
> Sent from the Struts - User mailing list archive at
> Nabble.com.
> 
> 
>
---------------------------------------------------------------------
> 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: [S2] Problem while retrieving data from JSP

Posted by kaouki <in...@gmail.com>.
I would like to find a better way to do that ... if it is possible ...
Because I would have the same probleme with all my beans (Hibernate
entities).

If I want to render an entity bean E in my view (with 4 or 5 properties,
nested beans or not), and the user updates 2 properties and submits the
form, I get E with the 2 updated properties but the others are set to null.
So I can not merge my udpated entity (in my Hibernate Dao) ... 

Is there a solution to avoid that ? Perhaps by using interceptors like
Preparable or ModelDriven ?


Igor Vlasov wrote:
> 
> I think you must put the ID's in hidden fields and then they will fill up
> with id's from your collection on jsp page
> 
> In save method  wou will analyse the recieved data.
> 
> 
> kaouki wrote:
>> 
>> Hi,
>> I get this bean in my action in order to modify it in my jsp:
>> Catalogue {
>> Long id;
>> String title;
>> String description;
>> Collection<Produit> produits
>> }
>> In this jsp, I have two fieds: title and description, and a table of
>> Produit with checkboxes.
>> These ones enable the user to remove the products from the catalogue.
>> 
>> In my save action, I get the catalogue (property of the action) and a
>> Long[] (the id of the checked products).
>> The problem is that the Products Collection of the Catalogue and its id
>> are null.
>> 
>> So, if I want update some attributes of my bean, I have to put the bean
>> in Session ? or all the unchanged attributes in hidden fields ?
>> 
>> I'm grateful for any input on the matter. Cheers.
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Problem-while-retrieving-data-from-JSP-tf4691128.html#a13426242
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] Problem while retrieving data from JSP

Posted by Igor Vlasov <vi...@mail.ru>.
I think you must put the ID's in hidden fields and then they will fill up
with id's from your collection on jsp page

In save method  wou will analyse the recieved data.


kaouki wrote:
> 
> Hi,
> I get this bean in my action in order to modify it in my jsp:
> Catalogue {
> Long id;
> String title;
> String description;
> Collection<Produit> produits
> }
> In this jsp, I have two fieds: title and description, and a table of
> Produit with checkboxes.
> These ones enable the user to remove the products from the catalogue.
> 
> In my save action, I get the catalogue (property of the action) and a
> Long[] (the id of the checked products).
> The problem is that the Products Collection of the Catalogue and its id
> are null.
> 
> So, if I want update some attributes of my bean, I have to put the bean in
> Session ? or all the unchanged attributes in hidden fields ?
> 
> I'm grateful for any input on the matter. Cheers.
> 

-- 
View this message in context: http://www.nabble.com/-S2--Problem-while-retrieving-data-from-JSP-tf4691128.html#a13421508
Sent from the Struts - User mailing list archive at Nabble.com.


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