Re: tapestry select model

2011-09-21 Thread Jonathan Barker
I'll preface this by saying that I've been following a "recipe" that's "just
worked" for years, so I haven't had to make one work from scratch in ages.

However

Your ValueEncoder will throw NPE's.  Have a look at the
HibernateEntityValueEncoder in the tapestry-hibernate module - it uses a
null-safe implementation.


JB


On Wed, Sep 21, 2011 at 12:40 AM, csckid  wrote:

> Now I have add an encoder
> 
>:
> encoder="wholeSaleMemberEncoder" />
> 
>  
>
>
> public class WholeSaleMemberEncoder implements
> ValueEncoder, ValueEncoderFactory {
>
>@Inject
>private WholeSaleMemberDao wholeSaleMemberDao;
>@Inject
>private DatabaseDao databaseDao;
>
>public String toClient(WholeSaleMember value) {
>// return the given object's ID
>return String.valueOf(value.getId());
>}
>
>public WholeSaleMember toValue(String id) {
>
>// find the color object of the given ID in the database
>return (WholeSaleMember) databaseDao.load(Long.parseLong(id),
> WholeSaleMember.class);
>}
>
>public ValueEncoder create(Class
> type) {
>// TODO Auto-generated method stub
>return this;
> }
> }
>
>
>
> public class CreateWMemberTruck {
>
>
>@Inject
>private WholeSaleMemberDao wholeSaleMemberDao;
>@Property
> private WholeSaleMemberEncoder wholeSaleMemberEncoder;
> @Property
>private SelectModel memberSelectModel;
>@Property
>@Inject
>private SelectModelFactory selectModelFactory;
>
>@Property
>private WholeSaleMember membersName;
>
>
>void setupRender() {
> // invoke my service to find all colors, e.g. in the database
> List members =
> wholeSaleMemberDao.getWholeSaleMembers();
>
> // create a SelectModel from my list of colors
> memberSelectModel = selectModelFactory.create(members,
> "fName");
>}
>
>void onSuccess() {
>
>System.out.println("\n\n\n"+membersName.getId()+"\n\n\n\n");
>
>}
> }
>
> Now t:select is not populated, that page gives an exception
> org.apache.tapestry5.internal.services.RenderQueueException
> Render queue error in
> BeforeRenderTemplate[wholesalemember/CreateWMemberTruck:members]:
> org.apache.tapestry5.ioc.internal.util.TapestryException
>
> #
>
> activeComponents
>
>* wholesalemember/CreateWMemberTruck (class
> com.kids.crm.pages.wholesalemember.CreateWMemberTruck)
>* wholesalemember/CreateWMemberTruck:layout (class
> com.kids.crm.components.Layout)
>
> classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml, line 4
>   1   2 t:sidebarTitle="Browse Wood"
>  3 xmlns:t="
> http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
>  4 xmlns:p="tapestry:parameter">
>  5 
>
>   8 :
>  9  model="MemberSelectModel" encoder="wholeSaleMemberEncoder" />
>* wholesalemember/CreateWMemberTruck:form (class
> org.apache.tapestry5.corelib.components.Form)
>
> classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml, line 5
>  1   2 t:sidebarTitle="Browse Wood"
>  3 xmlns:t="
> http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
>  4 xmlns:p="tapestry:parameter">
>  5 
>
>   8 :
>  9  model="MemberSelectModel" encoder="wholeSaleMemberEncoder" />
>   10
> * wholesalemember/CreateWMemberTruck:members (class
> org.apache.tapestry5.corelib.components.Select)
>
> classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml, line 9
>   4 xmlns:p="tapestry:parameter">
>  5 
>
>   8 :
>  9  model="MemberSelectModel" encoder="wholeSaleMemberEncoder" />
>   10
>   11
>  12
>  13
>  14 page="wholesalemember/CreateWholeSaleMember">Create
> W.Sale Member
>
> location
>classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml,
> line 9
>
> # java.lang.NullPointerException
>
> Hide uninteresting stack frames Stack trace
>
>*
>
> org.apache.tapestry5.internal.util.SelectModelRenderer.option(SelectModelRenderer.java:51)
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/tapestry-select-model-tp4823674p4825110.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


-- 
Jonathan Barker
ITStrategic


Re: tapestry select model

2011-09-20 Thread csckid
Now I have add an encoder

:


  


public class WholeSaleMemberEncoder implements
ValueEncoder, ValueEncoderFactory { 

@Inject
private WholeSaleMemberDao wholeSaleMemberDao;
@Inject
private DatabaseDao databaseDao;

public String toClient(WholeSaleMember value) {
// return the given object's ID
return String.valueOf(value.getId()); 
}

public WholeSaleMember toValue(String id) { 

// find the color object of the given ID in the database
return (WholeSaleMember) databaseDao.load(Long.parseLong(id),
WholeSaleMember.class);
}

public ValueEncoder create(Class 
type) {
// TODO Auto-generated method stub
return this;
}
} 



public class CreateWMemberTruck {


@Inject
private WholeSaleMemberDao wholeSaleMemberDao;
@Property
private WholeSaleMemberEncoder wholeSaleMemberEncoder;
@Property
private SelectModel memberSelectModel;
@Property
@Inject
private SelectModelFactory selectModelFactory;

@Property
private WholeSaleMember membersName;


void setupRender() {
// invoke my service to find all colors, e.g. in the database
List members =
wholeSaleMemberDao.getWholeSaleMembers();

// create a SelectModel from my list of colors
memberSelectModel = selectModelFactory.create(members, "fName");
}

void onSuccess() {

System.out.println("\n\n\n"+membersName.getId()+"\n\n\n\n");

}
}

Now t:select is not populated, that page gives an exception
org.apache.tapestry5.internal.services.RenderQueueException
Render queue error in
BeforeRenderTemplate[wholesalemember/CreateWMemberTruck:members]:
org.apache.tapestry5.ioc.internal.util.TapestryException

#

activeComponents

* wholesalemember/CreateWMemberTruck (class
com.kids.crm.pages.wholesalemember.CreateWMemberTruck)
* wholesalemember/CreateWMemberTruck:layout (class
com.kids.crm.components.Layout)
 
classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml, line 4
  1 http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
  4 xmlns:p="tapestry:parameter">
  5 

  8 :
  9 
* wholesalemember/CreateWMemberTruck:form (class
org.apache.tapestry5.corelib.components.Form)
 
classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml, line 5
  1 http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
  4 xmlns:p="tapestry:parameter">
  5 
 
  8 :
  9 
  10
* wholesalemember/CreateWMemberTruck:members (class
org.apache.tapestry5.corelib.components.Select)
 
classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml, line 9
  4 xmlns:p="tapestry:parameter">
  5 
 
  8 :
  9 
  10
  11
  12
  13
  14Create
W.Sale Member

location
classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml,
line 9

# java.lang.NullPointerException

Hide uninteresting stack frames Stack trace

*
org.apache.tapestry5.internal.util.SelectModelRenderer.option(SelectModelRenderer.java:51)
 


--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/tapestry-select-model-tp4823674p4825110.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: tapestry select model

2011-09-20 Thread Jonathan Barker
>From the javadoc for SelectModelFactory... (
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/services/SelectModelFactory.html
)

 "The returned model creates for every object in the list a selectable
option and relies on existing
ValueEncoder
for
the object type."

So, you need to contribute a ValueEncoder for your WholeSaleMember.

I believe that the tapestry-hibernate module does that automatically for
Hibernate entities, but since you are using Spring, you would need to do it
on your own.



On Tue, Sep 20, 2011 at 10:57 PM, csckid  wrote:

> Select component is populated. But I wasn't able to fetch the id variable
> of
> the selected object.
> *CreateWMemberTruck.tml *
> 
>   :
> />
>
>  
>
> *CreateWMemberTruck.java *
>
> public class CreateWMemberTruck {
>
>
>@Inject
>private WholeSaleMemberDao wholeSaleMemberDao;
>
>@Property
>private SelectModel memberSelectModel;
>@Property
>@Inject
>private SelectModelFactory selectModelFactory;
>
>@Property
>private WholeSaleMember membersName;
>
>
>void setupRender() {
>
>List members =
> wholeSaleMemberDao.getWholeSaleMembers();
>
>
>memberSelectModel = selectModelFactory.create(members, "fName");
>}
>
>void onSuccess() {
>
>System.out.println("\n\n\n"+
> membersName.getId()+"\n\n\n\n");
>
>}
> }
>
>  When I click on submit it says. I thought I will be able to call
> membersName.getId()
> *Exception*
> org.apache.tapestry5.ioc.internal.OperationException
> "Could not find a coercion from type java.lang.String to type
> com.kids.crm.db.WholeSaleMember."
> #
>
> location
>classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml,
> line 5
>1   2   t:sidebarTitle="Browse Wood"
>3   xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
>4   xmlns:p="tapestry:parameter">
>5   
>6   :
>7   
>8   :
>9model="MemberSelectModel"
> />
>10  
> trace
>
>* Triggering event 'action' on
> wholesalemember/CreateWMemberTruck:form
>
> # org.apache.tapestry5.runtime.ComponentEventException
> Could not find a coercion from type java.lang.String to type
> com.kids.crm.db.WholeSaleMember.
>
>
> *WholeSaleMember.java *
> @Entity
> @Table(name = "whole_sale_member")
> public class WholeSaleMember {
>private Long id;
>private String fName;
>private String lName;
>private String cellNumber;
>private String officePhoneNumber;
>private String address;
>private TruckWoodPrice truckWoodPrice;
>private Date created;
>private Date updated;
> ..getters and setters
> }
>
> *WholeSaleMemberDaoImpl .java*
> @Service("wholeSaleMemberDao")
> @Transactional
> public class WholeSaleMemberDaoImpl extends HibernateDaoSupport implements
> WholeSaleMemberDao{
>public ArrayList getWholeSaleMembers() {
>return (ArrayList) getHibernateTemplate().find("from
> WholeSaleMember");
>}
> }
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/tapestry-select-model-tp4823674p4824898.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


-- 
Jonathan Barker
ITStrategic


Re: tapestry select model

2011-09-20 Thread csckid
Select component is populated. But I wasn't able to fetch the id variable of
the selected object.
*CreateWMemberTruck.tml *

   :


  

*CreateWMemberTruck.java *

public class CreateWMemberTruck {


@Inject
private WholeSaleMemberDao wholeSaleMemberDao;

@Property
private SelectModel memberSelectModel;
@Property
@Inject
private SelectModelFactory selectModelFactory;

@Property
private WholeSaleMember membersName;


void setupRender() {

List members =
wholeSaleMemberDao.getWholeSaleMembers();


memberSelectModel = selectModelFactory.create(members, "fName");
}

void onSuccess() {

System.out.println("\n\n\n"+ membersName.getId()+"\n\n\n\n");

}
}

 When I click on submit it says. I thought I will be able to call
membersName.getId()
*Exception*
org.apache.tapestry5.ioc.internal.OperationException
"Could not find a coercion from type java.lang.String to type
com.kids.crm.db.WholeSaleMember."
#

location
classpath:com/kids/crm/pages/wholesalemember/CreateWMemberTruck.tml,
line 5
1   http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
4   xmlns:p="tapestry:parameter">
5   
6   :
7   
8   :
9   
10  
trace

* Triggering event 'action' on
wholesalemember/CreateWMemberTruck:form

# org.apache.tapestry5.runtime.ComponentEventException
Could not find a coercion from type java.lang.String to type
com.kids.crm.db.WholeSaleMember.


*WholeSaleMember.java *
@Entity
@Table(name = "whole_sale_member")
public class WholeSaleMember {
private Long id;
private String fName;
private String lName;
private String cellNumber;
private String officePhoneNumber;
private String address;
private TruckWoodPrice truckWoodPrice;
private Date created;
private Date updated;
..getters and setters
}

*WholeSaleMemberDaoImpl .java*
@Service("wholeSaleMemberDao")
@Transactional
public class WholeSaleMemberDaoImpl extends HibernateDaoSupport implements
WholeSaleMemberDao{
public ArrayList getWholeSaleMembers() {
return (ArrayList) getHibernateTemplate().find("from 
WholeSaleMember");
}
}

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/tapestry-select-model-tp4823674p4824898.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: tapestry select model

2011-09-20 Thread Josh Canfield
This is pretty light on details. You may need to provide some code
that demonstrates the problem.


On Tue, Sep 20, 2011 at 12:17 PM, csckid  wrote:
> I am developing a page that will load value of combobox from a database
> table. The table is loaded fine. But when I clicked on submit, I can't
> access the data that is selected in the combobox.
>
>  When I click on submit it says. I though I will be able to call
> membersName.getId()
>
>
>
>
> --
> View this message in context: 
> http://tapestry.1045711.n5.nabble.com/tapestry-select-model-tp4823674p4823674.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

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