You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by robnangle <ro...@gmail.com> on 2011/03/07 12:27:50 UTC
Saving from an editable grid
Hi all jus seen topics on problems with editable graids and im having a
problem, the problem is not in getting the editable grid but in saving the
data entered into the field.
My Code:
tml:
Player points:
${player.points}
java:
@Property
private Player player;
@Property
private String player_id;
@Property
private String points;
@Component
private Form update;
public String onSuccess() throws Exception {
// create db creates connection with the database
createDb();
String statement = "UPDATE squad SET weekly_points =? where player_id=?";
prep = conn.prepareStatement(statement);
prep.setString(1, points);
prep.setString(2, player_id);
prep.executeUpdate();
return "index";
}
The problem is points and player_id are null. Any idea's?
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-from-an-editable-grid-tp3412259p3412259.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
Re: Saving from an editable grid
Posted by robnangle <ro...@gmail.com>.
tml source:
t:grid source="results1"/>
t:grid t:source="players1" t:row="player"
t:include="player_id,name,county,points">
p:pointsCell>
Player points:
${player.points}
/p:pointsCell>
/t:grid>
<br/
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-from-an-editable-grid-tp3412259p3412265.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
Re: Saving from an editable grid
Posted by robnangle <ro...@gmail.com>.
Got it sorted lads, cheers..
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-from-an-editable-grid-tp3412259p3415237.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
Re: Saving from an editable grid
Posted by ael <al...@dash.com.ph>.
Using tapestry-Hibernate with DAO plus Grid is much easier to implement than
JDBC.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-from-an-editable-grid-tp3412259p3414800.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
Re: Saving from an editable grid
Posted by robnangle <ro...@gmail.com>.
It now updates the very first plaers points but since then the player_id and
points values are stuck on the first one I entered. Where do I clear the
player data? Or where do I put in the loop for multiple entries?
Cheers
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-from-an-editable-grid-tp3412259p3413745.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
Re: Saving from an editable grid
Posted by robnangle <ro...@gmail.com>.
My two classes now look like:
public class PlayerEncoder implements ValueEncoder, ValueEncoderFactory {
private Connection conn;
private PreparedStatement prep;
@Property
private Player temp1;
private List players;
public void createDb() throws Exception {
Handler handler = new Handler();
conn = handler.getConnection();
prep = handler.getPreparedStatement();
}
public String toClient(Player player) {
if (player != null) {
return player.getPlayer_id();
}
else {
return null;
}
}
public Player toValue(String clientValue) {
if (clientValue != null && clientValue.trim().length() > 0) {
// use id to get the Person instance from the database and
return it
try {
createDb();
String statement = "select * from squad where player_id=?";
prep = conn.prepareStatement(statement);
ResultSet rs = (ResultSet) prep.executeQuery();
while(rs.next()) {
temp1 = new Player();
temp1.setPlayer_id(rs.getString("player_id"));
players.add(temp1);
}
conn.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return temp1;
}
else {
return new Player();
}
}
public ValueEncoder create(Class Player) {
// TODO Auto-generated method stub
return this;
}
And:
@Property
private PlayerEncoder encoder;
public static void contributeValueEncoderSource(MappedConfiguration
configuration) {
configuration.addInstance(Player.class, PlayerEncoder.class);
}
I also put the t:encoder="encoder" in the tml file..
I assume im still missing something? The same problem persists..?
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-from-an-editable-grid-tp3412259p3412847.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
Re: Saving from an editable grid
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 07 Mar 2011 12:10:55 -0300, robnangle <ro...@gmail.com> wrote:
> So what your saying is to use the id to select the correct person from
> the database?
Yes.
> Ant then in the other class, how do I use the encoder?
>
> @Property
> private PlayerEncoder encoder;
>
> void onPrepare() {
> encoder = new PlayerEncoder();
> }
Pass your encoder to the encoder parameter of Grid.
You can automatically associate your PlayerEncoder with the Player class
in your AppModule so every time a ValueEncoder is needed for Player
instances it's needed (including the Select component):
public static void contributeValueEncoderSource(MappedConfiguration<Class,
ValueEncoderFactory> configuration) {
configuration.addInstance(Player.class, PlayerEncoderFactory.class);
}
You'll need to make your ValueEncoder also implement ValueEncoderFactory
and add this method:
public ValueEncoder create(Class type) {
return this;
}
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Saving from an editable grid
Posted by robnangle <ro...@gmail.com>.
So what your saying is to use the id to select the correct person from the
database?
Ant then in the other class, how do I use the encoder?
@Property
private PlayerEncoder encoder;
void onPrepare() {
encoder = new PlayerEncoder();
}
Anything else to put in?
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-from-an-editable-grid-tp3412259p3412577.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
Re: Saving from an editable grid
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 07 Mar 2011 11:29:16 -0300, robnangle <ro...@gmail.com> wrote:
> Is there any simple examples of value encoders out there? I seem to be
> only finding quite complex ones.
In your case, it would be something like this:
public class PersonValueEncoder implements ValueEncoder<Person> {
public String toClient(Person person) {
if (person != null) {
return person.getId();
}
else {
return null;
}
}
public Person toValue(String clientValue) {
if (clientValue != null && clientValue.trim().length() > 0) {
// use id to get the Person instance from the database and return it
}
else {
return new Person();
}
}
}
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Saving from an editable grid
Posted by robnangle <ro...@gmail.com>.
Is there any simple examples of value encoders out there? I seem to be only
finding quite complex ones.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-from-an-editable-grid-tp3412259p3412513.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
Re: Saving from an editable grid
Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Have you tried adding a Hidden component with the player id? Or, better
yet, registering a ValueEncoder for your Player class?
On Mon, 07 Mar 2011 08:27:50 -0300, robnangle <ro...@gmail.com> wrote:
> Hi all jus seen topics on problems with editable graids and im having a
> problem, the problem is not in getting the editable grid but in saving
> the
> data entered into the field.
>
> My Code:
>
> tml:
>
>
>
>
>
>
> Player points:
> ${player.points}
>
>
>
>
>
>
> java:
>
> @Property
> private Player player;
> @Property
> private String player_id;
> @Property
> private String points;
> @Component
> private Form update;
>
> public String onSuccess() throws Exception {
> // create db creates connection with the database
> createDb();
> String statement = "UPDATE squad SET weekly_points =? where
> player_id=?";
> prep = conn.prepareStatement(statement);
> prep.setString(1, points);
> prep.setString(2, player_id);
> prep.executeUpdate();
> return "index";
> }
>
>
> The problem is points and player_id are null. Any idea's?
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Saving-from-an-editable-grid-tp3412259p3412259.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
>
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
Coordenador e professor da Especialização em Engenharia de Software com
Ênfase em Java da Faculdade Pitágoras
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org