You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Name Surname <wi...@outlook.com> on 2014/10/18 22:32:15 UTC
Update checkbox within Form for changing value of a row
I have a code like this:
/**
*
* @author
*/
public class POS {
@Inject
private Request request;
@Inject
private BiznisLogika tiketDao;
@Inject
private Session session;
@InjectComponent
private Zone result;
@SessionState
@Property
private SearchCriteria criteria;
@SessionState
@Property
private SearchCriteriaTwo criteriaTwo;
@SuppressWarnings("unused")
@Property
private GridDataSource source = new TicketDataSource(session, Tiket.class);
@SuppressWarnings("unused")
@Property
private Tiket currentTicket;
@Property
@Persist
private TiketStatus noviStatus;
@Property
private SelectModel tiketSelectModel;
@Inject
SelectModelFactory selectModelFactory;
@Inject
private Session hibernate;
@Inject
private GenericDao genericDao;
void setupRender() {
criteriaTwo = null;
criteria = null;
}
private final class TicketDataSource extends HibernateGridDataSource {
private TicketDataSource(Session session, @SuppressWarnings("rawtypes") Class entityType) {
super(session, entityType);
}
@Override
public int getAvailableRows() {
return criteria.getSearchPattern() == null ? 0 : super.getAvailableRows();
}
@Override
protected void applyAdditionalConstraints(Criteria crit) {
crit.add(Restrictions.ilike("ticketSerial", criteria.getSearchPattern())).add(Restrictions.ilike("ticketDate", criteriaTwo.getSearchPattern()));
}
}
void onValidateFromDelete() {
// Unfortunately, this method is never called because Checkbox doesn't bubble up VALIDATE. It's a shame because
// this would be the perfect place to validate whether deleting is OK, or to put an entry in deleteCopyByRowNum.
// Please vote for https://issues.apache.org/jira/browse/TAP5-2075 .
}
// The Loop component will automatically call this for every row as it is rendered.
public boolean isDelete() {
return false;
}
// The Loop component will automatically call this for every row on submit.
public void setDelete(boolean delete) {
}
@OnEvent(value = EventConstants.SUCCESS)
Object searchTickets() {
return request.isXHR() ? result.getBody() : null;
}
Object onAction() {
return request.isXHR() ? result.getBody() : null;
}
public ValueEncoder<TiketStatus> getTiketStatusEncoder() {
return new ValueEncoder<TiketStatus>() {
@Override
public String toClient(TiketStatus value) {
// return the given object's ID
return String.valueOf(value);
}
@Override
public TiketStatus toValue(String id) {
return TiketStatus.valueOf(id);
// return (Tiket) genericDao.getById(Tiket.class, Long.parseLong(id));
}
};
}
@CommitAfter
Object onSaveThemAll() {
for (int i = 0; i < source.getAvailableRows(); i++) {
currentTicket.setTicketStatus(noviStatus);
hibernate.merge(currentTicket);
}
return request.isXHR() ? result.getBody() : null;
}
}
"
Buscar
Resultados
or cancel
${message:no-result}
Save"
Now, I want to update when checked checkbox each row of a grid with new Status. I have tried with a method onSaveThemAll, but it doesn't work, since I have no idea how to check if checkbox is checked and how to update each row(ticket) with a new state. Any help is appreciated.
P.S. I have provided an image for better understanding what I want to achieve here.
http://postimg.org/image/lnlwb7fkb/
Re: Update checkbox within Form for changing value of a row
Posted by George Christman <gc...@cardaddy.com>.
There is a few ways to go about this, but I personally think the simplest
way to handle this kind of thing is to add a transient value to your
CurrentTicket
object and set the value in your grid.
Example
@NonVisual
@Transient
private boolean delete;
//getters and setters
Then in the grid
<input t:id="delete" t:type="checkbox" value="currentTicket.delete">
When you submit the form you'll be able to iterate through your list of
tickets and read the delete value.
The other way of doing it is to use a getter / setter for delete and save
the delete boolean in some kind of a map with the object id.
On Sun, Oct 19, 2014 at 7:11 PM, Name Surname <wi...@outlook.com>
wrote:
> For better understanding what I want to achieve I have opened new Q. on
> StackOverflow. Thank you in advance on your efforts to enlighten me. :)
>
>
> http://stackoverflow.com/questions/26456425/updating-checked-property-with-a-value-from-select-button-in-tapestry
>
> > From: wintertime0101@outlook.com
> > To: users@tapestry.apache.org
> > Subject: Update checkbox within Form for changing value of a row
> > Date: Sat, 18 Oct 2014 21:32:15 +0100
> >
> > I have a code like this:
> >
> > /**
> > *
> > * @author
> > */
> > public class POS {
> >
> > @Inject
> > private Request request;
> > @Inject
> > private BiznisLogika tiketDao;
> > @Inject
> > private Session session;
> > @InjectComponent
> > private Zone result;
> > @SessionState
> > @Property
> > private SearchCriteria criteria;
> > @SessionState
> > @Property
> > private SearchCriteriaTwo criteriaTwo;
> > @SuppressWarnings("unused")
> > @Property
> > private GridDataSource source = new TicketDataSource(session,
> Tiket.class);
> > @SuppressWarnings("unused")
> > @Property
> > private Tiket currentTicket;
> > @Property
> > @Persist
> > private TiketStatus noviStatus;
> > @Property
> > private SelectModel tiketSelectModel;
> > @Inject
> > SelectModelFactory selectModelFactory;
> > @Inject
> > private Session hibernate;
> > @Inject
> > private GenericDao genericDao;
> >
> > void setupRender() {
> > criteriaTwo = null;
> > criteria = null;
> > }
> >
> > private final class TicketDataSource extends HibernateGridDataSource
> {
> >
> > private TicketDataSource(Session session,
> @SuppressWarnings("rawtypes") Class entityType) {
> > super(session, entityType);
> > }
> >
> > @Override
> > public int getAvailableRows() {
> > return criteria.getSearchPattern() == null ? 0 :
> super.getAvailableRows();
> > }
> >
> > @Override
> > protected void applyAdditionalConstraints(Criteria crit) {
> > crit.add(Restrictions.ilike("ticketSerial",
> criteria.getSearchPattern())).add(Restrictions.ilike("ticketDate",
> criteriaTwo.getSearchPattern()));
> > }
> > }
> >
> > void onValidateFromDelete() {
> > // Unfortunately, this method is never called because Checkbox
> doesn't bubble up VALIDATE. It's a shame because
> > // this would be the perfect place to validate whether deleting
> is OK, or to put an entry in deleteCopyByRowNum.
> > // Please vote for
> https://issues.apache.org/jira/browse/TAP5-2075 .
> > }
> > // The Loop component will automatically call this for every row as
> it is rendered.
> >
> > public boolean isDelete() {
> > return false;
> > }
> >
> > // The Loop component will automatically call this for every row on
> submit.
> > public void setDelete(boolean delete) {
> > }
> >
> > @OnEvent(value = EventConstants.SUCCESS)
> > Object searchTickets() {
> > return request.isXHR() ? result.getBody() : null;
> > }
> >
> > Object onAction() {
> >
> > return request.isXHR() ? result.getBody() : null;
> >
> > }
> >
> > public ValueEncoder<TiketStatus> getTiketStatusEncoder() {
> > return new ValueEncoder<TiketStatus>() {
> > @Override
> > public String toClient(TiketStatus value) {
> > // return the given object's ID
> > return String.valueOf(value);
> > }
> >
> > @Override
> > public TiketStatus toValue(String id) {
> > return TiketStatus.valueOf(id);
> > // return (Tiket) genericDao.getById(Tiket.class,
> Long.parseLong(id));
> > }
> > };
> > }
> >
> > @CommitAfter
> > Object onSaveThemAll() {
> > for (int i = 0; i < source.getAvailableRows(); i++) {
> > currentTicket.setTicketStatus(noviStatus);
> > hibernate.merge(currentTicket);
> >
> >
> > }
> > return request.isXHR() ? result.getBody() : null;
> >
> > }
> >
> > }
> >
> >
> >
> > "
> >
> >
> >
> >
> >
> >
> > Buscar
> >
> >
> >
> >
> >
> > Resultados
> >
> >
> >
> >
> > or cancel
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > ${message:no-result}
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Save"
> >
> >
> > Now, I want to update when checked checkbox each row of a grid with new
> Status. I have tried with a method onSaveThemAll, but it doesn't work,
> since I have no idea how to check if checkbox is checked and how to update
> each row(ticket) with a new state. Any help is appreciated.
> >
> >
> > P.S. I have provided an image for better understanding what I want to
> achieve here.
> >
> > http://postimg.org/image/lnlwb7fkb/
> >
>
>
--
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York
RE: Update checkbox within Form for changing value of a row
Posted by Name Surname <wi...@outlook.com>.
For better understanding what I want to achieve I have opened new Q. on StackOverflow. Thank you in advance on your efforts to enlighten me. :)
http://stackoverflow.com/questions/26456425/updating-checked-property-with-a-value-from-select-button-in-tapestry
> From: wintertime0101@outlook.com
> To: users@tapestry.apache.org
> Subject: Update checkbox within Form for changing value of a row
> Date: Sat, 18 Oct 2014 21:32:15 +0100
>
> I have a code like this:
>
> /**
> *
> * @author
> */
> public class POS {
>
> @Inject
> private Request request;
> @Inject
> private BiznisLogika tiketDao;
> @Inject
> private Session session;
> @InjectComponent
> private Zone result;
> @SessionState
> @Property
> private SearchCriteria criteria;
> @SessionState
> @Property
> private SearchCriteriaTwo criteriaTwo;
> @SuppressWarnings("unused")
> @Property
> private GridDataSource source = new TicketDataSource(session, Tiket.class);
> @SuppressWarnings("unused")
> @Property
> private Tiket currentTicket;
> @Property
> @Persist
> private TiketStatus noviStatus;
> @Property
> private SelectModel tiketSelectModel;
> @Inject
> SelectModelFactory selectModelFactory;
> @Inject
> private Session hibernate;
> @Inject
> private GenericDao genericDao;
>
> void setupRender() {
> criteriaTwo = null;
> criteria = null;
> }
>
> private final class TicketDataSource extends HibernateGridDataSource {
>
> private TicketDataSource(Session session, @SuppressWarnings("rawtypes") Class entityType) {
> super(session, entityType);
> }
>
> @Override
> public int getAvailableRows() {
> return criteria.getSearchPattern() == null ? 0 : super.getAvailableRows();
> }
>
> @Override
> protected void applyAdditionalConstraints(Criteria crit) {
> crit.add(Restrictions.ilike("ticketSerial", criteria.getSearchPattern())).add(Restrictions.ilike("ticketDate", criteriaTwo.getSearchPattern()));
> }
> }
>
> void onValidateFromDelete() {
> // Unfortunately, this method is never called because Checkbox doesn't bubble up VALIDATE. It's a shame because
> // this would be the perfect place to validate whether deleting is OK, or to put an entry in deleteCopyByRowNum.
> // Please vote for https://issues.apache.org/jira/browse/TAP5-2075 .
> }
> // The Loop component will automatically call this for every row as it is rendered.
>
> public boolean isDelete() {
> return false;
> }
>
> // The Loop component will automatically call this for every row on submit.
> public void setDelete(boolean delete) {
> }
>
> @OnEvent(value = EventConstants.SUCCESS)
> Object searchTickets() {
> return request.isXHR() ? result.getBody() : null;
> }
>
> Object onAction() {
>
> return request.isXHR() ? result.getBody() : null;
>
> }
>
> public ValueEncoder<TiketStatus> getTiketStatusEncoder() {
> return new ValueEncoder<TiketStatus>() {
> @Override
> public String toClient(TiketStatus value) {
> // return the given object's ID
> return String.valueOf(value);
> }
>
> @Override
> public TiketStatus toValue(String id) {
> return TiketStatus.valueOf(id);
> // return (Tiket) genericDao.getById(Tiket.class, Long.parseLong(id));
> }
> };
> }
>
> @CommitAfter
> Object onSaveThemAll() {
> for (int i = 0; i < source.getAvailableRows(); i++) {
> currentTicket.setTicketStatus(noviStatus);
> hibernate.merge(currentTicket);
>
>
> }
> return request.isXHR() ? result.getBody() : null;
>
> }
>
> }
>
>
>
> "
>
>
>
>
>
>
> Buscar
>
>
>
>
>
> Resultados
>
>
>
>
> or cancel
>
>
>
>
>
>
>
>
>
>
>
>
> ${message:no-result}
>
>
>
>
>
>
>
>
>
>
> Save"
>
>
> Now, I want to update when checked checkbox each row of a grid with new Status. I have tried with a method onSaveThemAll, but it doesn't work, since I have no idea how to check if checkbox is checked and how to update each row(ticket) with a new state. Any help is appreciated.
>
>
> P.S. I have provided an image for better understanding what I want to achieve here.
>
> http://postimg.org/image/lnlwb7fkb/
>