You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by nkv1 <ni...@gmail.com> on 2012/09/25 00:31:52 UTC

Palette with GenericValueEncoder, GenericMultipleSelectModel

/I am trying to make a palette with using http://chenillekit.codehaus.org/
generics with database entity objects.
This i my page template/
<t:layout t:pageTitle="${message:title}"
          xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
          xmlns:tx="tapestry-library:tapx">
  <section>
    <header>
      
Detalji o studentu

    </header>
    <article >
      <t:if test="about">
        <t:beandisplay object="about"/>
      </t:if>
      <t:if negate="true" test="about">
        Entitet ${about} does not exist.
        <br/>
        <br/>
      </t:if>
    </article>
    <header>
      
Lista Grupa

    </header>
    <t:zone t:id="lista">
      <t:form t:id="form">
          <t:Palette t:model="grupaModels"
t:selected="paletteSelectedValues" t:encoder="grupaEncoder"/>
        <t:submit t:id="submit" value="message:update"/>
      </t:form>
    </t:zone>
    <footer>
      <t:pagelink page="PageAddStudent">
        ${message:back}
      </t:pagelink>
    </footer>
  </section>
</t:layout>

/And this is my page class/

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projekat.pages;

import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.chenillekit.tapestry.core.encoders.GenericValueEncoder;
import org.chenillekit.tapestry.core.models.GenericMultipleSelectModel;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import projekat.entities.Grupa;
import projekat.entities.Korisnik;
import projekat.entities.Student;
import projekat.services.ProtectedPage;

@ProtectedPage
public class PageDetailStudent {

  /**
   * Student
   */
  @Persist
  @Property
  private Student about;
  /**
   * Groups
   */
  @Persist
  @Property
  private Grupa isIn;
  /**
   * List of Groups
   */
  @Persist
  private List<Grupa> isInList;
  /**
   * database session
   */
  @Inject
  private Session hibernate;
  /**
   * zone
   */
  @InjectComponent
  private Zone lista;
  /**
   * user
   */
  @SessionState
  @Property
  private Korisnik asoKorisnik;
  /**
   * userexistance
   */
  @Property
  private boolean asoKorisnikExists;
  //editing start
 
/**http://chenillekit.codehaus.org/chenillekit-tapestry/apidocs/org/chenillekit/tapestry/core/encoders/GenericValueEncoder.html*/
  @Persist
  private GenericValueEncoder<Grupa> grupaEncoder = new
GenericValueEncoder<Grupa>(isInList, null, null);
 
/**http://chenillekit.codehaus.org/chenillekit-tapestry/apidocs/org/chenillekit/tapestry/core/models/GenericMultipleSelectModel.html*/
  @Persist
  private GenericMultipleSelectModel<Grupa> grupaModels = new
GenericMultipleSelectModel<Grupa>(isInList, null, null, null, null);
  /**
   * list of selected values from palette
   */
  @Property
  @Persist
  private List<Grupa> paletteSelectedValues;

  void setupRender() {

    if (paletteSelectedValues == null) {
      paletteSelectedValues = new ArrayList<Grupa>();
    }
  }
  //editing end

  /**
   * on page activation get student from database
   * with id
   */
  void onActivate(long kljuc) {
    this.about = (Student)
hibernate.createCriteria(Student.class).add(Restrictions.eq("kljuc",
kljuc)).uniqueResult();
  }

  /**
   * list all groups from database
   *
   * @return
   */
  public List<Grupa> getIsInList() {
    return (List<Grupa>) hibernate.createCriteria(Grupa.class).list();
  }

  /**
   * add selected groups to student and saves to database
   *
   * @return
   */
  public Object onActionFromSubmit() {
    about.getGrupaList().addAll(paletteSelectedValues);
    hibernate.persist(about);
    return lista;
  }
}

/So my main problem with what to fill null values on class page/



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Palette-with-GenericValueEncoder-GenericMultipleSelectModel-tp5716473.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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