How to retrive data from a form and save to database

View: New views
4 Messages — Rating Filter:   Alert me  

How to retrive data from a form and save to database

by elvenfire :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi everyone,

I am using Apache cocoon 2.2,  hibernate and spring with mysql database.

I just want to know how could i retrieve an input and save it to database. Kindly correct my codes

here's my jx.xml code:
<form method="post" action="${cocoon.continuation.id}">
        Last Name: <input type="text" name="last_name"/>
        Save Person
</form>


flow.js

function newPerson() {
        var demoBean = cocoon.getComponent("demo");
        var lastName = cocoon.request.get("last_name");
        var person = demoBean.getNewPerson(lastName);
        cocoon.sendPage("page,createPerson", {"person" : person});
}

MyBean.java
    public String getNewPerson(String lastName) {
          Person p = new Person();
          p.setLastName(lastName);
        Session s = Cewf.getInstance().getHibernateSession();
        s.save(p);
        s.flush();
        return ("Person #" + p.getPersonId() + " at " + p.getLastName());
   
    }

I can save to the database but I do not know how to retrieve the parameter from the user's input.

Thanks :)



Re: How to retrive data from a form and save to database

by Andre Juffer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

elvenfire wrote:

> Hi everyone,
>
> I am using Apache cocoon 2.2,  hibernate and spring with mysql database.
>
> I just want to know how could i retrieve an input and save it to database.
> Kindly correct my codes
>
> here's my jx.xml code:
> <form method="post" action="${cocoon.continuation.id}">
> Last Name: <input type="text" name="last_name"/>
> func,newPerson Save Person
> </form>
>
>
> flow.js
> function newPerson() {
> var demoBean = cocoon.getComponent("demo");
> var lastName = cocoon.request.get("last_name");
>  

This should be:

var lastName = cocoon.request.getParameter("last_name");



> var person = demoBean.getNewPerson(lastName);
> cocoon.sendPage("page,createPerson", {"person" : person});
> }
>
> MyBean.java
>     public String getNewPerson(String lastName) {
>  Person p = new Person();
>  p.setLastName(lastName);
>         Session s = Cewf.getInstance().getHibernateSession();
>         s.save(p);
>         s.flush();
>         return ("Person #" + p.getPersonId() + " at " + p.getLastName());
>    
>     }
>
> I can save to the database but I do not know how to retrieve the parameter
> from the user's input.
>
> Thanks :) :working:
>
>
>
>  


--
Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juffer@...
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat                   | WWW: www.strubiocat.oulu.fi
NordProt                     | WWW: www.nordprot.org
Triacle Biocomputing         | WWW: www.triacle-bc.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: How to retrive data from a form and save to database

by elvenfire :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Andrew,

I tried it but it did not work. Any other solutions?


Andre Juffer wrote:
elvenfire wrote:
> Hi everyone,
>
> I am using Apache cocoon 2.2,  hibernate and spring with mysql database.
>
> I just want to know how could i retrieve an input and save it to database.
> Kindly correct my codes
>
> here's my jx.xml code:
> <form method="post" action="${cocoon.continuation.id}">
> Last Name: <input type="text" name="last_name"/>
> func,newPerson Save Person
> </form>
>
>
> flow.js
> function newPerson() {
> var demoBean = cocoon.getComponent("demo");
> var lastName = cocoon.request.get("last_name");
>  

This should be:

var lastName = cocoon.request.getParameter("last_name");



> var person = demoBean.getNewPerson(lastName);
> cocoon.sendPage("page,createPerson", {"person" : person});
> }
>
> MyBean.java
>     public String getNewPerson(String lastName) {
>  Person p = new Person();
>  p.setLastName(lastName);
>         Session s = Cewf.getInstance().getHibernateSession();
>         s.save(p);
>         s.flush();
>         return ("Person #" + p.getPersonId() + " at " + p.getLastName());
>    
>     }
>
> I can save to the database but I do not know how to retrieve the parameter
> from the user's input.
>
> Thanks :) :working:
>
>
>
>  


--
Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juffer@oulu.fi
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat                   | WWW: www.strubiocat.oulu.fi
NordProt                     | WWW: www.nordprot.org
Triacle Biocomputing         | WWW: www.triacle-bc.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org

Re: How to retrive data from a form and save to database

by Andre Juffer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

elvenfire wrote:
> Hi Andrew,
>
> I tried it but it did not work. Any other solutions?

Your newPerson() functionshould also include statements like

var form =  new Form(...);
form.showForm(...);
var lastName = cocoon.request.getParameter("last_name");


The sitemap should include something like:

<map:match pattern="new-person">
   <map:call function="newPerson" />
  </map:match>

>
>
>
> Andre Juffer wrote:
>> elvenfire wrote:
>>> Hi everyone,
>>>
>>> I am using Apache cocoon 2.2,  hibernate and spring with mysql database.
>>>
>>> I just want to know how could i retrieve an input and save it to
>>> database.
>>> Kindly correct my codes
>>>
>>> here's my jx.xml code:
>>> <form method="post" action="${cocoon.continuation.id}">
>>> Last Name: <input type="text" name="last_name"/>
>>> func,newPerson Save Person
>>> </form>
>>>
>>>
>>> flow.js
>>> function newPerson() {
>>> var demoBean = cocoon.getComponent("demo");
>>> var lastName = cocoon.request.get("last_name");
>>>  
>> This should be:
>>
>> var lastName = cocoon.request.getParameter("last_name");
>>
>>
>>
>>> var person = demoBean.getNewPerson(lastName);
>>> cocoon.sendPage("page,createPerson", {"person" : person});
>>> }
>>>
>>> MyBean.java
>>>     public String getNewPerson(String lastName) {
>>>  Person p = new Person();
>>>  p.setLastName(lastName);
>>>         Session s = Cewf.getInstance().getHibernateSession();
>>>         s.save(p);
>>>         s.flush();
>>>         return ("Person #" + p.getPersonId() + " at " + p.getLastName());
>>>    
>>>     }
>>>
>>> I can save to the database but I do not know how to retrieve the
>>> parameter
>>> from the user's input.
>>>
>>> Thanks :) :working:
>>>
>>>
>>>
>>>  
>>
>> --
>> Andre H. Juffer              | Phone: +358-8-553 1161
>> Biocenter Oulu and           | Fax: +358-8-553-1141
>> Department of Biochemistry   | Email: andre.juffer@...
>> University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
>> StruBioCat                   | WWW: www.strubiocat.oulu.fi
>> NordProt                     | WWW: www.nordprot.org
>> Triacle Biocomputing         | WWW: www.triacle-bc.com
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>>
>>
>


--
Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juffer@...
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat                   | WWW: www.strubiocat.oulu.fi
NordProt                     | WWW: www.nordprot.org
Triacle Biocomputing         | WWW: www.triacle-bc.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...