You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Penyihir Kecil <pe...@gmail.com> on 2007/12/15 16:37:01 UTC

t5 : how to handle add and edit form in one page only ?

i get another problem here ^_^
when i tried to make add and edit form in one page...
in my grid table there is a link to edit the row...
i used this code to add and edit (in one page) :

package edu.its.dreamteam.web.pages.admin;

import org.apache.tapestry.ValueEncoder;
import org.apache.tapestry.annotations.Component;
import org.apache.tapestry.annotations.Persist;
import org.apache.tapestry.corelib.components.Form;
import org.apache.tapestry.ioc.annotations.Inject;

import edu.its.dreamteam.daf.beans.Position;
import edu.its.dreamteam.daf.dao.IPositionDao;
import edu.its.dreamteam.web.pages.BaseFormPage;
import edu.its.dreamteam.web.util.StringValueEncoder;

public class PositionForm extends BaseFormPage {
    @Inject
    private IPositionDao positionDao;

    @Persist
    private Position position;


    @Component
    private Form positionForm;



    public Position getPosition() {
        if(position == null){
            position = new Position();
        }
        return position;
    }

    public void setPosition(Position position) {
        this.position = position;
    }

    public IPositionDao getPositionDao() {
        return positionDao;
    }

    public ValueEncoder<String> getValueEncoder(){
        return new StringValueEncoder();
    }

    void onPrepare(){
        if(position == null){
            position = new Position();
        }
    }

    Object onSuccessFromPositionForm(){
        if(getPosition().getIdPosition()==null){
            getPosition().setIdPosition(getIdPrimaryKey().generateId());
            getPositionDao().insert(getPosition());
        }else{
            getPositionDao().update(getPosition());
            setPosition(null);
        }

        return PositionGrid.class;
    }

    void onActionFromClear(){
        setPosition(null);
        positionForm.clearErrors();
    }

    void onActivate(String idPosition){
        if(idPosition!=null && !idPosition.equals("")){
            setPosition((Position)
getPositionDao().findByPrimaryKey(idPosition));
        }


    }

    String onPassivate(){
        return getPosition().getIdPosition();
    }


}

after i finished edit the row. i want to add new one, but the strange is
i still get the past value of edit page (the form showed the last edit
entry).
am i missing something in my code ??
could anyone help me ?

thnx u