You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Waldo Mendoza <wm...@umsa.bo> on 2005/02/03 20:27:18 UTC

TextField value parameter Bug?

Hello, to all

I decided to implement my next application in Tapestry, and of course i am 
learning Tapestry(it´s a great framework), so i have found a problem maybe 
it´s mine, but i´ll try to explain:

I have a domain object:

public class Teacher {
  private Integer age;
  // ... getters and setters
  // ... other properties
}

I want to edit an object of the Student class, with this Page class
..
public abstract class EditTeacher extends BasePage implements
		PageRenderListener {

	public abstract Teacher getTeacher();

	public abstract void setTeacher(Teacher teacher);

	public abstract Category getCategory();

	public abstract CategoryPropertySelectionModel 
getCategoryPropertySelectionModel();

	public abstract void setCategoryPropertySelectionModel(
			CategoryPropertySelectionModel cm);

	public void pageBeginRender(PageEvent arg0) {
		if (getTeacher() == null) {
			setTeacher(new Teacher());
		}
		TeacherManager manager = ((Global) getGlobal()).getManager();
		setCategoryPropertySelectionModel(new 
CategoryPropertySelectionModel(
				manager.listCategories()));
	}

	public void saveTeacher(IRequestCycle cycle) {
		TeacherManager teacherManager = ((Global) getGlobal
()).getManager();
		getTeacher().setCategory(getCategory());
		teacherManager.saveTeacher(getTeacher());
		cycle.activate("TeacherList");
	}

        public String getAge() {
		return getTeacher().getAge().toString();
	}

	public void setAge(String a) {
		getTeacher().setAge(Integer.valueOf(a));
	}
}

This is my page expecification:

<page-specification class="bo.test.web.page.EditTeacher">
    <property-specification name="teacher" type="bo.test.model.Teacher"/>
    <property-specification name="category" type="bo.test.model.Category" 
persistent="yes"/>
    <property-specification name="categoryPropertySelectionModel" 
type="bo.test.web.page.CategoryPropertySelectionModel" persistent="yes"/>
</page-specification>

And this my template:

<html>
<head><title>Edit Teacher</title></head>
<body>
<form jwcid="@Form" listener="ognl:listeners.saveTeacher">
<input jwcid="@Hidden" value="ognl:teacher.id" type="hidden"/>
<table >
	<tr>
		<td>Name:</td>
		<td><input jwcid="@TextField" value="ognl:teacher.name" 
type="text"/></td>
	</tr>
	<tr>
		<td>Lastname:</td>
		<td><input jwcid="@TextField" value="ognl:teacher.lastname" 
type="text"/></td>
	</tr>
    	<tr>
		<td>Age:</td>
<!--line 17 in my code--> <td><input jwcid="@TextField" value="ognl:age" 
<type="text"/></td>
	</tr>
        <tr>
		<td>Category:</td>
		<td><input jwcid="@PropertySelection" 
model="ognl:categoryPropertySelectionModel" value="ognl:category" 
type="text"/></td>
	</tr>
<!... more properties -->
 </table>
<input type="submit" value="Save Teacher"/>
</form>
</body>
</html>

When i want to edit a Teacher everything goes well, but when i try to add a 
new Teacher, with this code in my ListTeachers Page:

	public void addTeacher( IRequestCycle cycle ) {
		EditTeacher nextPage = (EditTeacher)cycle.getPage
("EditTeacher");
		nextPage.setTeacher(new Teacher());
		cycle.activate(nextPage);
	}

This exception comes:

org.apache.tapestry.BindingException 
Unable to resolve expression 'age' for 
bo.test.web.page.EditTeacher$Enhance_3@1e9c82e[EditTeacher]. 
binding: ExpressionBinding[EditTeacher age] 
location: context:/EditTeacher.html, line 17 
   
ognl.OgnlException 
age 

But when i change my data type of Teacher class to String(the age property), 
and i replace the line 17 of the template to:

<input jwcid="@TextField" value="ognl:teacher.age" <type="text"/>

and delete de getAge() and setAge(..) of my class EditTeacher, everythings is 
good adding or editing an object.

So maybe this is an issue of the parameter value of TextField.

I saw in the component reference documentation that the component Hidden 
accepts a value parameter of type Object? Why not TextField?

Sorry if i miss something, maybe that´s why i am still a newbie, and i don´t 
understand everything of the Page life cycle, because the enhance class that 
tapestry create at runtime eliminate the getters and setters for my 
property "age" those are not abstract.

Thanks a lot, and sorry for the large message.

Greetings from Bolivia.
Waldo Mendoza
wmendoza@umsa.bo


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


Re: TextField value parameter Bug?

Posted by Waldo Mendoza <wm...@umsa.bo>.
Sorry, i didn`t see all the stack trace, you are right, a 
java.lang.NullPointerException comes, my Teacher class has a field declared 
as private and did no initialization, i forgot that instance fields default 
value are Null, sorry that was my mistake.

Thanks for the information, my next step is to learn validators in Tapestry, 
thats why i choose Tapestry for my application, one can save a lot of time 
coding boring things like accessors, and the components(and Tapestry) make 
their work(a very good job) updating the properties. 

In some years implementing applications in PHP, and try other frameworks like 
struts or webwork, i think that for large web applications, the best for me is 
Tapestry. Although we have to see what happens with portlets.



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


Re: TextField value parameter Bug?

Posted by Bryan Lewis <br...@maine.rr.com>.
Perhaps the age property of a newly inserted Teacher is null?  Is there a
NullPointerException further down the stack trace?  You might try checking
for null in getAge() before doing the toString().

Or better, let your getter and setter work with age in its natural Integer
form, and bind a NumberValidator to the TextField.  It will convert the
string input to an Integer for you.


----- Original Message ----- 
From: "Waldo Mendoza" <wm...@umsa.bo>
To: <ta...@jakarta.apache.org>
Sent: Thursday, February 03, 2005 2:27 PM
Subject: TextField value parameter Bug?


> Hello, to all
>
> I decided to implement my next application in Tapestry, and of course i am
> learning Tapestry(it´s a great framework), so i have found a problem maybe
> it´s mine, but i´ll try to explain:
>
> I have a domain object:
>
> public class Teacher {
>   private Integer age;
>   // ... getters and setters
>   // ... other properties
> }
>
> I want to edit an object of the Student class, with this Page class
> ..
> public abstract class EditTeacher extends BasePage implements
> PageRenderListener {
>
> public abstract Teacher getTeacher();
>
> public abstract void setTeacher(Teacher teacher);
>
> public abstract Category getCategory();
>
> public abstract CategoryPropertySelectionModel
> getCategoryPropertySelectionModel();
>
> public abstract void setCategoryPropertySelectionModel(
> CategoryPropertySelectionModel cm);
>
> public void pageBeginRender(PageEvent arg0) {
> if (getTeacher() == null) {
> setTeacher(new Teacher());
> }
> TeacherManager manager = ((Global) getGlobal()).getManager();
> setCategoryPropertySelectionModel(new
> CategoryPropertySelectionModel(
> manager.listCategories()));
> }
>
> public void saveTeacher(IRequestCycle cycle) {
> TeacherManager teacherManager = ((Global) getGlobal
> ()).getManager();
> getTeacher().setCategory(getCategory());
> teacherManager.saveTeacher(getTeacher());
> cycle.activate("TeacherList");
> }
>
>         public String getAge() {
> return getTeacher().getAge().toString();
> }
>
> public void setAge(String a) {
> getTeacher().setAge(Integer.valueOf(a));
> }
> }
>
> This is my page expecification:
>
> <page-specification class="bo.test.web.page.EditTeacher">
>     <property-specification name="teacher" type="bo.test.model.Teacher"/>
>     <property-specification name="category" type="bo.test.model.Category"
> persistent="yes"/>
>     <property-specification name="categoryPropertySelectionModel"
> type="bo.test.web.page.CategoryPropertySelectionModel" persistent="yes"/>
> </page-specification>
>
> And this my template:
>
> <html>
> <head><title>Edit Teacher</title></head>
> <body>
> <form jwcid="@Form" listener="ognl:listeners.saveTeacher">
> <input jwcid="@Hidden" value="ognl:teacher.id" type="hidden"/>
> <table >
> <tr>
> <td>Name:</td>
> <td><input jwcid="@TextField" value="ognl:teacher.name"
> type="text"/></td>
> </tr>
> <tr>
> <td>Lastname:</td>
> <td><input jwcid="@TextField" value="ognl:teacher.lastname"
> type="text"/></td>
> </tr>
>     <tr>
> <td>Age:</td>
> <!--line 17 in my code--> <td><input jwcid="@TextField" value="ognl:age"
> <type="text"/></td>
> </tr>
>         <tr>
> <td>Category:</td>
> <td><input jwcid="@PropertySelection"
> model="ognl:categoryPropertySelectionModel" value="ognl:category"
> type="text"/></td>
> </tr>
> <!... more properties -->
>  </table>
> <input type="submit" value="Save Teacher"/>
> </form>
> </body>
> </html>
>
> When i want to edit a Teacher everything goes well, but when i try to add
a
> new Teacher, with this code in my ListTeachers Page:
>
> public void addTeacher( IRequestCycle cycle ) {
> EditTeacher nextPage = (EditTeacher)cycle.getPage
> ("EditTeacher");
> nextPage.setTeacher(new Teacher());
> cycle.activate(nextPage);
> }
>
> This exception comes:
>
> org.apache.tapestry.BindingException
> Unable to resolve expression 'age' for
> bo.test.web.page.EditTeacher$Enhance_3@1e9c82e[EditTeacher].
> binding: ExpressionBinding[EditTeacher age]
> location: context:/EditTeacher.html, line 17
>
> ognl.OgnlException
> age
>
> But when i change my data type of Teacher class to String(the age
property),
> and i replace the line 17 of the template to:
>
> <input jwcid="@TextField" value="ognl:teacher.age" <type="text"/>
>
> and delete de getAge() and setAge(..) of my class EditTeacher, everythings
is
> good adding or editing an object.
>
> So maybe this is an issue of the parameter value of TextField.
>
> I saw in the component reference documentation that the component Hidden
> accepts a value parameter of type Object? Why not TextField?
>
> Sorry if i miss something, maybe that´s why i am still a newbie, and i
don´t
> understand everything of the Page life cycle, because the enhance class
that
> tapestry create at runtime eliminate the getters and setters for my
> property "age" those are not abstract.
>
> Thanks a lot, and sorry for the large message.
>
> Greetings from Bolivia.
> Waldo Mendoza
> wmendoza@umsa.bo
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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