You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Sebastien Arbogast <se...@gmail.com> on 2005/05/18 21:53:06 UTC

[CForms] Edit action inside a repeater row

Hi,

I have a repeater listing a set of users using output's and I'd like
to add some "edit" button or link to each row in order to call some
flowscript function that displays another form to edit the information
related to the corresponding row. And my problem is to know how I can
get the id of the current row and make a link using that value. For
example I'd like to introduce some link like that:
<a href="edit-user?userid=[the id of the current row]">Edit</a>
Is it possible ? How should I proceed because I have absolutely no
idea about how I can integrate that with my existing CForm ?

Thx in advance

-- 
Sebastien ARBOGAST

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


Re: [CForms] Edit action inside a repeater row

Posted by Sebastien Arbogast <se...@gmail.com>.
That's it. I finally found it :

var name = form.getWidget().getSubmitWidget().getParent().lookupWidget("name").getValue();

Thank you very much for your help Carlos.

Cheers

-- 
Sebastien ARBOGAST

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


Re: [CForms] Edit action inside a repeater row

Posted by Sebastien Arbogast <se...@gmail.com>.
>   Hi Sebastien.
>   yes, this do not work in that way.
>   you have to call the new form when the control return to
>   flowscript.
> 
>   for example:
> 
>   form.load(...);
>   form.showForm(...);
>   form.save(...);
> 
>   // in the next line you need to obtain what widget fire the sumbit
>   if (form.submitId == "edit") {
>      editUser(form.getWidget().getSubmitWidget().getParent().getId());
>   }
>   ...
>   ...
> 
>   but, the value retrieve with
> form.getWidget().getSubmitWidget().getParent().getId() is the position
> of the row inside the repeater (maybe in the bean is a collection). with
> this value you need retrieve from the collection the real object to
> edit.

Thank you very much Carlos ! You can't imagine the service you're doing to me.
Thanks to your tip I managed to get and display the id and everything
works fine. Now I still don't understand how I can find more data
thanks to this id. What would be marvelous would be to get the value
of the "name" output widget in the line corresponding to the id. I
tried to look at the Widget API but I still don't understand how I can
do that.

FYI here is my binding definition:

<fb:context xmlns:fb="http://apache.org/cocoon/forms/1.0#binding" path=".">
    <fb:repeater id="users" parent-path="." row-path="users">
        <fb:identity>
            <fb:value id="id" path="@id"/>
        </fb:identity>
        <fb:on-bind>
            <fb:value id="name" path="name"/>
            <fb:value id="email" path="email"/>
            <fb:value id="active" path="active"/>
        </fb:on-bind>
    </fb:repeater>
</fb:context>

And here is my flowscript code that displays the users list :
function list_users(form){
    getSchaman();
    var repository = schaman.getRepository();
    form.load(repository);
    form.showForm("internal/display-users-list");
    form.save(repository);
    
    // in the next line you need to obtain what widget fire the sumbit
    if (form.submitId == "edit") {
        var userid = form.getWidget().getSubmitWidget().getParent().getId();
        cocoon.sendPage("internal/message",{variable_name:"userid",variable_value:userid});
    }
    else{
        cocoon.sendPage("users-list");
    }
}

How can I use the "userid" variable to retrieve the value of the field
whose id is "name" in the row whose id is userid ?

--
Sébastien Arbogast

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


Re: [CForms] Edit action inside a repeater row

Posted by Carlos Chávez <cc...@agssa.net>.
Sebastien Arbogast Escribio :-)
> First of all thank you very much for your answer Carlos. It's
> difficult to get answers at present time.
> I tried to integrate your suggestion in my form using a fd:submit
> widget. Here is my form definition :
>
> <fd:form id="data"
> xmlns:fd="http://apache.org/cocoon/forms/1.0#definition"
>     xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
>     <fd:widgets>
>         <fd:repeater id="users">
>             <fd:label><i18n:text key="users-list"/></fd:label>
>             <fd:widgets>
>                 <fd:output id="id">
>                     <fd:datatype base="long"/>
>                 </fd:output>
>                 <fd:output id="name">
>                     <fd:label><i18n:text key="user-name"/></fd:label>
>                     <fd:datatype base="string"/>
>                 </fd:output>
>                 <fd:submit id="edit" action-command="edit-user"
> validate="true">
>                     <fd:label>edit-user</fd:label>
>                     <fd:on-action>
>
> editUser(form.getWidget().getSubmitWidget().getParent().getId());
>                     </fd:on-action>
>                 </fd:submit>
>             </fd:widgets>
>         </fd:repeater>
>     </fd:widgets>
> </fd:form>
>
> As you can see I try to call a flowscript function with the id as a
> parameter and this flowscript function is supposed to display a form
> to edit the information of the user with the corresponding id.
> But when I click on the button nothing happens ? The current form is
> just redisplayed and a continuation is created and that's it. No
> javascript error. No exception. I really don't know what's going on.
> Do you have any idea ? Anyone ?

  Hi Sebastien.
  yes, this do not work in that way.
  you have to call the new form when the control return to
  flowscript.

  for example:

  form.load(...);
  form.showForm(...);
  form.save(...);

  // in the next line you need to obtain what widget fire the sumbit
  if (form.submitId == "edit") {
     editUser(form.getWidget().getSubmitWidget().getParent().getId());
  }
  ...
  ...

  but, the value retrieve with
form.getWidget().getSubmitWidget().getParent().getId() is the position
of the row inside the repeater (maybe in the bean is a collection). with
this value you need retrieve from the collection the real object to
edit.

  Cheers.
  Carlos Chávez.

>
> Thx in advance.
>
> --
> Sebastien ARBOGAST
>


-- 
Carlos Chávez

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


Re: [CForms] Edit action inside a repeater row

Posted by Sebastien Arbogast <se...@gmail.com>.
First of all thank you very much for your answer Carlos. It's
difficult to get answers at present time.
I tried to integrate your suggestion in my form using a fd:submit
widget. Here is my form definition :

<fd:form id="data" xmlns:fd="http://apache.org/cocoon/forms/1.0#definition" 
    xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
    <fd:widgets>
        <fd:repeater id="users">
            <fd:label><i18n:text key="users-list"/></fd:label>
            <fd:widgets>
                <fd:output id="id">
                    <fd:datatype base="long"/>
                </fd:output>
                <fd:output id="name">
                    <fd:label><i18n:text key="user-name"/></fd:label>
                    <fd:datatype base="string"/>
                </fd:output>
                <fd:submit id="edit" action-command="edit-user" validate="true">
                    <fd:label>edit-user</fd:label>
                    <fd:on-action>
                       
editUser(form.getWidget().getSubmitWidget().getParent().getId());
                    </fd:on-action>
                </fd:submit>
            </fd:widgets>
        </fd:repeater>
    </fd:widgets>
</fd:form>

As you can see I try to call a flowscript function with the id as a
parameter and this flowscript function is supposed to display a form
to edit the information of the user with the corresponding id.
But when I click on the button nothing happens ? The current form is
just redisplayed and a continuation is created and that's it. No
javascript error. No exception. I really don't know what's going on.
Do you have any idea ? Anyone ?

Thx in advance.

-- 
Sebastien ARBOGAST

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


Re: [CForms] Edit action inside a repeater row

Posted by Carlos Chávez <cc...@agssa.net>.
Sebastien Arbogast Escribio :-)
> Hi,
>
> I have a repeater listing a set of users using output's and I'd like
> to add some "edit" button or link to each row in order to call some
> flowscript function that displays another form to edit the information
> related to the corresponding row. And my problem is to know how I can
> get the id of the current row and make a link using that value. For
> example I'd like to introduce some link like that:
> <a href="edit-user?userid=[the id of the current row]">Edit</a>
> Is it possible ? How should I proceed because I have absolutely no
> idea about how I can integrate that with my existing CForm ?
>
> Thx in advance
  Hi Sebastien.

  I'm using form.getWidget().getSubmitWidget().getParent().getId()
  to obtain the position row in the repeater of the widget that fire
  a submit.

  cheers,
  Carlos Chávez.

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


-- 
Carlos Chávez

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