How to inject string to javascript in template

2011-04-08 Thread Anton Mezerny
Hi,

I need to implement component based on javascript library. To make this
component reusable I have to inject some string values inside the script
tag in the component template (like some JSON object or html element id).
I have tried with expressions, like ${jsonPropertyValue} and it works, but
there are some errors in template in my IDE (I'm using IDEA).
Is there a better way to inject values from component properties inside the
script tag?

Thanks in advance.
Anton


How to cast object to some type

2010-12-12 Thread Anton Mezerny
Hi all,
I'am trying to call some methods like here:

${element.contents.name}

Where 'contents' is represented as Object, but in my component I know exact
type of this field. When I try to render name field I get exception.
One possible solution is to write a public method in my component which
makes cast and returns object of exact type, like here:

 public MyType castToMyType(Object o){
 MyType m = (MyType)o;
 return m;
 }

And call this method from template:

 ${castToMyType(element.contents).name}


Is there better approach to do this?
Thanks in advance.
Anton


Re: How to cast object to some type

2010-12-12 Thread Anton Mezerny
Thank you, Thiago

2010/12/12 Thiago H. de Paula Figueiredo thiag...@gmail.com

 On Sun, 12 Dec 2010 07:55:04 -0200, Anton Mezerny anton.meze...@gmail.com
 wrote:

  Hi all,


 Hi!


  I'am trying to call some methods like here:
 ${element.contents.name}


  Where 'contents' is represented as Object, but in my component I know
 exact type of this field.


 Tapestry (more specifically, the prop binding) *doesn't* use reflection
 while rendering to check if the object returned by
 getElement().getContents() has a getName() method. It does that when
 building the page instance. If getElement().getContents() is a method that
 returns Object, the prop binding treats it as an Object.


  When I try to render name field I get exception.
 One possible solution is to write a public method in my component which
 makes cast and returns object of exact type, like here:

  public MyType castToMyType(Object o){
MyType m = (MyType)o;
return m;
 }

  And call this method from template:

  ${castToMyType(element.contents).name}

 Is there better approach to do this?


 Yes:

 String getContentName() {
MyType type = (MyType) getElement().getContents();
return type.getName();
 }

 Then use ${contentName} instead of ${castToMyType(element.contents).name}.

 Summary: do logic and processing in the class, not in the template.

 --
 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-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org




How to render label for dynamically rendered radiogroup?

2010-12-12 Thread Anton Mezerny
Hi all,
I'm trying to render dynamic RadioGroup like here:

 t:radiogroup t:id=radioGroup

  value=value
   label=prop:context.availableLabel
   encoder=valueEncoderForFeature
   validate=prop:selectValidator

t:loop source=context.availableItemList value=oneItem
   t:radio label=literal:oneItem.name value=oneItem
 /
 /t:loop

/t:radiogroup

Now labels are not rendered at all. Component renders only radiobuttons
without any text lables.
I can't add t:tabel tag because I have no defined Radio component in my
component class (it could be several radiobuttons inside one RadioGroup).
I tried also use plain html, like
label
for=${currentFeature.id}-feature-label${currentFeature.name}/label
input id=${currentFeature.id}-feature-label t:type=radio
label=literal:currentFeature.name value=currentFeature /
but tapestry rewrites input id, so label is rendered but not work as a label
(click on it does'nt work)

How can I achieve a normal label behavior in my case?
Thanks in advance.
Anton


Re: How to render label for dynamically rendered radiogroup?

2010-12-12 Thread Anton Mezerny
Maybe I can write another component called for example RadioField and
construct it with Radio and Label components as aggregation fields.
Is there any other approach?

2010/12/12 Anton Mezerny anton.meze...@gmail.com

 Hi all,
 I'm trying to render dynamic RadioGroup like here:

 t:radiogroup t:id=radioGroup

   value=value
   label=prop:context.availableLabel
   encoder=valueEncoderForFeature
   validate=prop:selectValidator

 t:loop source=context.availableItemList value=oneItem
   t:radio label=literal:oneItem.name
 value=oneItem /
 /t:loop

 /t:radiogroup

 Now labels are not rendered at all. Component renders only radiobuttons
 without any text lables.
 I can't add t:tabel tag because I have no defined Radio component in my
 component class (it could be several radiobuttons inside one RadioGroup).
 I tried also use plain html, like
 label
 for=${currentFeature.id}-feature-label${currentFeature.name}/label
 input id=${currentFeature.id}-feature-label t:type=radio
 label=literal:currentFeature.name value=currentFeature /
 but tapestry rewrites input id, so label is rendered but not work as a
 label (click on it does'nt work)

 How can I achieve a normal label behavior in my case?
 Thanks in advance.
 Anton



Re: How to render label for dynamically rendered radiogroup?

2010-12-12 Thread Anton Mezerny
Thanks Bryan.
 I thought, that if I specify t:id attribute, than I must have according
object in my java class with the same name. For example: t:id=myBean
andprivate MyType myBean;but as I see it is not necessary.
Anton

2010/12/12 Bryan Lewis jbryanle...@gmail.com

 I use a RadioGroup with a Loop frequently.  I think you only need to change
 the way you specify the label.
 Here's an example from my code:

 t:radiogroup value=item.territory
  t:loop source=model.territories value=territory
t:radio t:id=territory value=territory label=prop:territory.name
 /
t:label for=territory class=radiolabel/
  /t:loop
 /t:radiogroup



 On Sun, Dec 12, 2010 at 8:18 AM, Anton Mezerny anton.meze...@gmail.com
 wrote:

  Hi all,
  I'm trying to render dynamic RadioGroup like here:
 
   t:radiogroup t:id=radioGroup
  
   value=value
 label=prop:context.availableLabel
 encoder=valueEncoderForFeature
 validate=prop:selectValidator
  
  t:loop source=context.availableItemList value=oneItem
 t:radio label=literal:oneItem.name
  value=oneItem
   /
   /t:loop
  
  /t:radiogroup
  
  Now labels are not rendered at all. Component renders only radiobuttons
  without any text lables.
  I can't add t:tabel tag because I have no defined Radio component in my
  component class (it could be several radiobuttons inside one RadioGroup).
  I tried also use plain html, like
  label
  for=${currentFeature.id}-feature-label${currentFeature.name}/label
  input id=${currentFeature.id}-feature-label t:type=radio
  label=literal:currentFeature.name value=currentFeature /
  but tapestry rewrites input id, so label is rendered but not work as a
  label
  (click on it does'nt work)
 
  How can I achieve a normal label behavior in my case?
  Thanks in advance.
  Anton
 



Re: Some questions about Tapestry components source code

2010-11-08 Thread Anton Mezerny

 This is an example of providing a default value for a component parameter.
 One way is using the value attribute of @Parameter. Another one is to write
 a method named defaultparameter name. In this particular case, it's a
 default value for the beanBlockSource parameter.


Didn't understand how it works. Does Tapestry make assignment from
defaultBeanBlockSource to beanBlockSource field (which is annotated with
@Parameter) if it is empty? There is no any usages of defaultBeanBlockSource
or getDefaultBeanBlockSource in component code. This implicit logic is very
unusual for me.

Also I have some question about debugging in Tapestry - as usual all fields
in components and pages are null, but there are some conduits, that
corresponds to ordinary fields. Can I use this conduits to get actual values
of my fields? In IDEA I can't find in conduit anything, that corresponds to
my actual fields.  Is there any ability to use normal debug in Tapestry,
maybe some configuration parameter?

2010/11/7 Thiago H. de Paula Figueiredo thiag...@gmail.com

 On Sun, 07 Nov 2010 16:29:15 -0200, Anton Mezerny anton.meze...@gmail.com
 wrote:

  Hi all,


 Hi!


  I've spent some time diving into the tapestry's sources (particulary
 BeanEditor and all code which is linked to it).


 I learned a lot from reading Tapestry sources. They're very well written
 and architected, use a lot of design patterns and some parts are just
 awesome. :)


  I found some interesting things, that I can't explain:
 1)in PropertyEditor.java there is some code, but it is not used anywhere
 (I
 did't find any usages). Am I missing something?
@Inject
@Core
private BeanBlockSource defaultBeanBlockSource;


BeanBlockSource defaultBeanBlockSource()
{
return defaultBeanBlockSource;
}


 Good question! I didn't get this the same time I saw it. :P
 This is an example of providing a default value for a component parameter.
 One way is using the value attribute of @Parameter. Another one is to write
 a method named defaultparameter name. In this particular case, it's a
 default value for the beanBlockSource parameter.


  2)Why form component doesn't have informal parameters support? There is no
 according annotation above the class definition (hovewer it works well with
 informal parameters, except IDE errors)


 I think there's a JIRA asking for Form to support informal parameters. If
 there isn't, please post one.


  3)There is one inconvenience in the loop component - it has a parameter
 called 'value' which clashes with different html elements attributes of the
 same
 name,  for example I can't write this simple construction because I can't
 specify a value attribute of 'option' tag, so I need to nest option tag
 inside loop component:

 option t:type=loop source=myList
 value=myValue${myValue.label}/option


 I agree this is inconvenient, but renaming the parameter would break
 backward compatibility pretty hard.
 I love invisible instrumentation and I use it almost all the time, but you
 can also use the other syntax:

 t:loop t:type=loop source=myList t:value=myValue
option value=${myValue.value}${myValue.label}/option
 /t:loop


  As I understand, it's now impossible to change name of the current loop
 value parameter, due to backward compatibility reason, but maybe it is
 possible to define it deprecated and provide also new parameter named, for
 example 'currentValue' or 'var' with the same functionality.


 This wouldn't work, as informal parameters are attributes whose name don't
 match a parameter name. We would need to remove the value parameter. Another
 option is to create another component.

 --
 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-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org




Some questions about Tapestry components source code

2010-11-07 Thread Anton Mezerny
Hi all,
I've spent some time diving into the tapestry's sources (particulary
BeanEditor and all code which is linked to it).
I use Tapestry 5.2.2.

I found some interesting things, that I can't explain:
1)in PropertyEditor.java there is some code, but it is not used anywhere (I
did't find any usages). Am I missing something?
@Inject
@Core
private BeanBlockSource defaultBeanBlockSource;


BeanBlockSource defaultBeanBlockSource()
{
return defaultBeanBlockSource;
}
2)Why form component doesn't have informal parameters support? There is no
according annotation above the class definition (hovewer it works well with
informal parameters, except IDE errors)
3)There is one inconvenience in the loop component - it has a parameter called
'value' which clashes with different html elements attributes of the same
name,
 for example I can't write this simple construction because I can't specify
a value attribute of 'option' tag, so I need to nest option tag inside loop
component:

option t:type=loop source=myList
value=myValue${myValue.label}/option

Even if I specify current value of the loop like t:value=myValue and
client value as just value=myValue.id, then client value (value=myValue.id)
is not rendered. Of course, it does not matter much, but creates some
inconvenience.

As I understand, it's now impossible to change name of the current loop
value parameter, due to backward compatibility reason, but maybe it is
possible to define it deprecated and provide also new parameter named, for
example
'currentValue' or 'var' with the same functionality.

Thanks a lot. It's just my thoughts about how to make great framework even
better.

Anton


Re: Objects session persistance and validation

2010-10-28 Thread Anton Mezerny
Resolved the issue - now it works fine:
I extracted validation to the separate method with
@OnEvent(value=EventContants.VALIDATE, component=submitForm)
Also switched to 5.2.1.

@OnEvent(value = EventConstants.VALIDATE, component = registerForm)
void validate(){
detectErrors();
}

@OnEvent(value = EventConstants.SUCCESS, component = registerForm)
Object saveCustomerAndUser() {

user.setPassword(generateHash(user.getPassword()));
customer.addUser(user);
customerService.save(customer);

// redirect with a message parameter
return Index.class;

}

private void detectErrors() {

if (!verifyPassword.equals(user.getPassword())) {
registerForm.recordError(messages.get(error.verify.password));
}
if (userService.getUserByLogin(user.getLogin()) != null) {

registerForm.recordError(messages.get(error.user.already.exists));
}
if
(customerService.getCustomerByBusinessName(customer.getBusinessName()) !=
null) {

registerForm.recordError(messages.get(error.customer.already.exists));
}
}

Anton

2010/10/25 Anton Mezerny anton.meze...@gmail.com

 I am using 5.1.0.7. Also I figured how to reproduce such a behavior - if i
 fill all fields with proper values, but set not equal passwords - all data
 is lost, but if I set invalid email and proper passwords - everything works
 fine.

 P.S. There is one error in previous code - in recordErrors() method shoud
 be:

 registerForm.recordError(messages.get(error.verify.password));
 instead of
 registerForm.recordError(verifyPassword,
 messages.get(error.verify.password));

 2010/10/25 Mark Shead mark.sh...@xeric.net

 Once it is submitted you may want to set the user back to null, that way
 you
 can start fresh when the page is submitted.

 The required,email and email,required things sounds odd. I'm going to see
 if
 I can reproduce that.  What version of tapestry are you using?

 Mark

 On Mon, Oct 25, 2010 at 2:17 PM, Anton Mezerny anton.meze...@gmail.com
 wrote:

  Ok, when i changed order from validation=required,email to
  validation=email,required email validation starts to work properly.
 Looks
  like some magic :). However, I get sometimes user data lost. I can't
  reproduce this bug with 100% probability, but it occurs sometimes. I
 tried
  also to change @Persist(PersistenceConstants.FLASH) to default @Persist.
  But
  it gives me behavior I don't want - it renders user data even if I
 refresh
  the page (I want to show blank form in that case). So FLASH persistance
 is
  what I want, but sometimes data are lost.
 
  My code now looks like this:
 
 
 ---Registration.java-
  public class Registration {
 
 @Property
 @Persist(PersistenceConstants.FLASH)
 private User user;
 
 @Property
 @Persist(PersistenceConstants.FLASH)
  private Customer customer;
 
 @Property
 private String verifyPassword;
 
 @Inject
  private CustomerService customerService;
 
 @Inject
 private UserService userService;
 
 @Component
 private Form registerForm;
 
 @Inject
 private Messages messages;
 
  @OnEvent(value = EventConstants.SUCCESS, component = registerForm)
 Object validateAndSave() {
 
 if (errorsDetected()){
 return null;
 }
 user.setPassword(generateHash(user.getPassword()));
 customer.addUser(user);
 customerService.save(customer);
 
 // redirect with a message parameter
 return Index.class;
 
 }
 
 private boolean errorsDetected(){
 boolean errorDetected = false;
  if (!verifyPassword.equals(user.getPassword())) {
  registerForm.recordError(verifyPassword,
  messages.get(error.verify.password));
  errorDetected = true;
  }
 
 if (userService.getUserByLogin(user.getLogin()) != null) {
 
  registerForm.recordError(messages.get(error.user.already.exists));
  errorDetected = true;
 }
 
 if
  (customerService.getCustomerByBusinessName(customer.getBusinessName())
 !=
  null) {
 
  registerForm.recordError(messages.get(error.customer.already.exists));
 errorDetected = true;
 }
 return errorDetected;
  }
  }
 
 
 
 -Registration.tml
  html t:type=layout title=Customer registration
   t:sidebarTitle=Current Time
   t:pageTitle=Register
   xmlns:t=http://tapestry.apache.org/schema/tapestry_5_1_0.xsd;
   xmlns:p=tapestry:parameter
 
  fieldset id=register
 form class=full-form t:id=registerForm
 t:errors/
 
 fieldset
 legendCustomer registration (company or private
  person)/legend
 
  t:beaneditor object=customer exclude=literal:id,users
  p:businessName
 t:label for=businessName

tynamo-security (shiro) exception

2010-10-25 Thread Anton Mezerny
Hi all,
I am playing with hotel booking application and trying to use some examples
from it in my project. Now I have a problem in login page - when I try to
login, I got
shiro's cipher exception, like here:
https://issues.apache.org/jira/browse/SHIRO-183
Is it fixed now? How can I upgrade to fixed version of
shiro/tynamo-security?
Thanks in advance.
Anton


Re: Objects session persistance and validation

2010-10-25 Thread Anton Mezerny
Required validation works on client side, so I have not tested it on server.
I can say, that when my custom validation causes error (password and
password verification don't match), then I have 2 error messages on
registration page (if email is also not valid) - email error and password
verification error.

Anton

2010/10/25 Mark mark-li...@xeric.net

 Do all the other validations perform as expected other than email? Does the
 required validation on email work correctly and give you an error when
 you
 try to submit. Also do you have any types of constraints on the email field
 in the database? Is it possible that what you are entering in the email
 fields is passing the email validation, but getting rejected by the
 database?

 I don't remember what Tapestry uses to determine whether or not something
 is
 a valid email address, but I do know that the actual spec for email
 addresses is a lot more permissive than you'd think.

 Mark

 On Mon, Oct 25, 2010 at 6:35 AM, Anton Mezerny anton.meze...@gmail.com
 wrote:

  So, I removed initializeNewUser() from Registration.java and added
 @Inject
  annotation to User.java and Customer.java (I also made user and customer
  separate, not nested one into another and I nest user into customer just
  before saving to DB). Now page renders well, but when I try to save user
  and
  customer (and email is invalid) - email validation does not occurs - I
 just
  have email = null in my customer.email field (even if i set some
 incorrect
  value, for exapmle 'test_email'). There is no redirect to the
 registration
  page with error message - program continues execution and tries to save
  data
  to DB.
 
  2010/10/23 Mark W. Shead mwsh...@gmail.com
 
   I don't think you want to use flash persistence for this.  Try just
   using @Persist. It looks like you are creating a new user every time
   the page renders.
  
   Mark
  
   On Sat, Oct 23, 2010 at 3:08 PM, Jim O'Callaghan 
 jc1000...@yahoo.co.uk
   wrote:
I'm not sure if this is relevant to your current problem, but to tell
Tapestry which constructor to use for the bean editor, you should
   annotate
the default (no args) constructor with @Inject - this will allow the
  BEF
   to
create the relevant entity if none if present.  Hope this helps.
   
Regards,
Jim.
   
-Original Message-
From: Anton Mezerny [mailto:anton.meze...@gmail.com]
Sent: 23 October 2010 17:02
To: Tapestry users
Subject: Objects session persistance and validation
   
Hi all,
I'm trying to write simple registration form using beaneditor
  component.
If I fullfill all reqired fields in the form and submit it -
 everything
works fine, but if server validation occurs (for example passwords
  don't
match), then all data is lost and Registration page renders with
   validation
errors, but without user data (input values).
I think the reason for this behaviour is the initializeNewUser()
  method,
wich rewrites all data if user field is null. But if I delete this
  method
from code, tapestry throws exception - User can't be instantiated
   (tapestry
tries to use constructor with most parameters, which has custom
  objects,
   not
only String, Integer, etc). So how can resolve this problem?
Thanks in advance.
   
 My code (some code is token from Tapestry5 Hotel Booking example):
   
  
 
 -Registration.java:-
---
   
public class Registration {
   
   @Property
   @Persist(PersistenceConstants.FLASH)
   private User user;
   
   @OnEvent(value = EventConstants.PREPARE, component =
 registerForm)
   private void initializeNewUser() {
   if (this.user == null) {
   this.user = new User();
   this.user.setCustomer(new Customer());
   } else {
   if (this.user.getCustomer() == null) {
   this.user.setCustomer(new Customer());
   }
   }
   }
   
   
   @Property
   private String verifyPassword;
   
   @Inject
   private UserService userService;
   
   @Component
   private Form registerForm;
   
   @Inject
   private Messages messages;
   
   public Object onSubmitFromRegisterForm() {
   
   if (!verifyPassword.equals(user.getPassword())) {
   
registerForm.recordError(messages.get(error.verify.password));
   
   return null;
   }
   
   if (userService.getUserByLogin(user.getLogin()) != null) {
   
registerForm.recordError(messages.get(error.user.already.exists));
   
   return null;
   }
   
   userService.save(user);
   
   return Index.class;
   
   }
}
   
   
--Registration.tml
   
   
html t:type=layout title=Customer registration
 t:sidebarTitle=Current Time
 t:pageTitle=Register

Re: tynamo-security (shiro) exception

2010-10-25 Thread Anton Mezerny
Checked out new version of Hotel booking application. There is no
tynamo-security dependency in pom.xml at all. Am I doing something wrong?
Anton

2010/10/25 Christophe Cordenier christophe.corden...@gmail.com

 Hi

 Yes it's fixed, i have update the pom.xml to use tynamo 0.3.0-SNAPSHOT

 2010/10/25 Anton Mezerny anton.meze...@gmail.com

  Hi all,
  I am playing with hotel booking application and trying to use some
 examples
  from it in my project. Now I have a problem in login page - when I try to
  login, I got
  shiro's cipher exception, like here:
  https://issues.apache.org/jira/browse/SHIRO-183
  Is it fixed now? How can I upgrade to fixed version of
  shiro/tynamo-security?
  Thanks in advance.
  Anton
 



 --
 Regards,
 Christophe Cordenier.

 Committer on Apache Tapestry 5
 Co-creator of wooki @wookicentral.com



Re: Objects session persistance and validation

2010-10-25 Thread Anton Mezerny
 for=address/
t:textfield t:id=address value=user.address
validate=required/
/p:address


p:email
t:label for=email/
t:textfield t:id=email value=user.email
validate=required/
/p:email


p:nickname
t:label for=nickname/
t:textfield t:id=nickname value=user.nickname
validate=required/
/p:nickname


p:login
t:label for=login/
t:textfield t:id=login value=user.login
validate=required/
/p:login


p:password
t:label for=password/
t:passwordfield t:id=password value=user.password
validate=required/
/p:password

p:verifyPassword
t:label for=verifyPassword/
t:passwordfield t:id=verifyPassword
value=verifyPassword validate=required/
/p:verifyPassword

/t:beaneditor

/fieldset


div class=form-submit
input type=submit value=Register/
/div
div class=memberAlready a member?
t:pagelink page=LoginLogin now!/t:pagelink
/div
/form
/fieldset
/html

2010/10/25 Mark mark-li...@xeric.net

 So if there is another problem the email validation will show you an error,
 but not if the email validation is the only issue?  That seems very odd.
  You might try switching the order from validation=required,email to
 validation=email,required just to see what happens.

 Mark

 On Mon, Oct 25, 2010 at 10:24 AM, Anton Mezerny anton.meze...@gmail.com
 wrote:

  Required validation works on client side, so I have not tested it on
  server.
  I can say, that when my custom validation causes error (password and
  password verification don't match), then I have 2 error messages on
  registration page (if email is also not valid) - email error and password
  verification error.
 
  Anton
 
  2010/10/25 Mark mark-li...@xeric.net
 
   Do all the other validations perform as expected other than email? Does
  the
   required validation on email work correctly and give you an error
 when
   you
   try to submit. Also do you have any types of constraints on the email
  field
   in the database? Is it possible that what you are entering in the email
   fields is passing the email validation, but getting rejected by the
   database?
  
   I don't remember what Tapestry uses to determine whether or not
 something
   is
   a valid email address, but I do know that the actual spec for email
   addresses is a lot more permissive than you'd think.
  
   Mark
  
   On Mon, Oct 25, 2010 at 6:35 AM, Anton Mezerny 
 anton.meze...@gmail.com
   wrote:
  
So, I removed initializeNewUser() from Registration.java and added
   @Inject
annotation to User.java and Customer.java (I also made user and
  customer
separate, not nested one into another and I nest user into customer
  just
before saving to DB). Now page renders well, but when I try to save
  user
and
customer (and email is invalid) - email validation does not occurs -
 I
   just
have email = null in my customer.email field (even if i set some
   incorrect
value, for exapmle 'test_email'). There is no redirect to the
   registration
page with error message - program continues execution and tries to
 save
data
to DB.
   
2010/10/23 Mark W. Shead mwsh...@gmail.com
   
 I don't think you want to use flash persistence for this.  Try just
 using @Persist. It looks like you are creating a new user every
 time
 the page renders.

 Mark

 On Sat, Oct 23, 2010 at 3:08 PM, Jim O'Callaghan 
   jc1000...@yahoo.co.uk
 wrote:
  I'm not sure if this is relevant to your current problem, but to
  tell
  Tapestry which constructor to use for the bean editor, you should
 annotate
  the default (no args) constructor with @Inject - this will allow
  the
BEF
 to
  create the relevant entity if none if present.  Hope this helps.
 
  Regards,
  Jim.
 
  -Original Message-
  From: Anton Mezerny [mailto:anton.meze...@gmail.com]
  Sent: 23 October 2010 17:02
  To: Tapestry users
  Subject: Objects session persistance and validation
 
  Hi all,
  I'm trying to write simple registration form using beaneditor
component.
  If I fullfill all reqired fields in the form and submit it -
   everything
  works fine, but if server validation occurs (for example
 passwords
don't
  match), then all data is lost and Registration page renders with
 validation
  errors, but without user data (input values).
  I think the reason for this behaviour is the initializeNewUser()
method,
  wich rewrites all data if user field is null. But if I delete
 this
method
  from code, tapestry

Re: tynamo-security (shiro) exception

2010-10-25 Thread Anton Mezerny
Checked out Tynamo 0.3.0-Snapshot and exception is gone. Thank you.

2010/10/25 Katia Aresti katiaare...@gmail.com

 Its normal, you have to checkout Tynamo branch ;)


 2010/10/25 Anton Mezerny anton.meze...@gmail.com

  Checked out new version of Hotel booking application. There is no
  tynamo-security dependency in pom.xml at all. Am I doing something wrong?
  Anton
 
  2010/10/25 Christophe Cordenier christophe.corden...@gmail.com
 
   Hi
  
   Yes it's fixed, i have update the pom.xml to use tynamo 0.3.0-SNAPSHOT
  
   2010/10/25 Anton Mezerny anton.meze...@gmail.com
  
Hi all,
I am playing with hotel booking application and trying to use some
   examples
from it in my project. Now I have a problem in login page - when I
 try
  to
login, I got
shiro's cipher exception, like here:
https://issues.apache.org/jira/browse/SHIRO-183
Is it fixed now? How can I upgrade to fixed version of
shiro/tynamo-security?
Thanks in advance.
Anton
   
  
  
  
   --
   Regards,
   Christophe Cordenier.
  
   Committer on Apache Tapestry 5
   Co-creator of wooki @wookicentral.com
  
 



Re: Objects session persistance and validation

2010-10-25 Thread Anton Mezerny
I am using 5.1.0.7. Also I figured how to reproduce such a behavior - if i
fill all fields with proper values, but set not equal passwords - all data
is lost, but if I set invalid email and proper passwords - everything works
fine.

P.S. There is one error in previous code - in recordErrors() method shoud
be:

registerForm.recordError(messages.get(error.verify.password));
instead of
registerForm.recordError(verifyPassword,
messages.get(error.verify.password));

2010/10/25 Mark Shead mark.sh...@xeric.net

 Once it is submitted you may want to set the user back to null, that way
 you
 can start fresh when the page is submitted.

 The required,email and email,required things sounds odd. I'm going to see
 if
 I can reproduce that.  What version of tapestry are you using?

 Mark

 On Mon, Oct 25, 2010 at 2:17 PM, Anton Mezerny anton.meze...@gmail.com
 wrote:

  Ok, when i changed order from validation=required,email to
  validation=email,required email validation starts to work properly.
 Looks
  like some magic :). However, I get sometimes user data lost. I can't
  reproduce this bug with 100% probability, but it occurs sometimes. I
 tried
  also to change @Persist(PersistenceConstants.FLASH) to default @Persist.
  But
  it gives me behavior I don't want - it renders user data even if I
 refresh
  the page (I want to show blank form in that case). So FLASH persistance
 is
  what I want, but sometimes data are lost.
 
  My code now looks like this:
 
 
 ---Registration.java-
  public class Registration {
 
 @Property
 @Persist(PersistenceConstants.FLASH)
 private User user;
 
 @Property
 @Persist(PersistenceConstants.FLASH)
  private Customer customer;
 
 @Property
 private String verifyPassword;
 
 @Inject
  private CustomerService customerService;
 
 @Inject
 private UserService userService;
 
 @Component
 private Form registerForm;
 
 @Inject
 private Messages messages;
 
  @OnEvent(value = EventConstants.SUCCESS, component = registerForm)
 Object validateAndSave() {
 
 if (errorsDetected()){
 return null;
 }
 user.setPassword(generateHash(user.getPassword()));
 customer.addUser(user);
 customerService.save(customer);
 
 // redirect with a message parameter
 return Index.class;
 
 }
 
 private boolean errorsDetected(){
 boolean errorDetected = false;
  if (!verifyPassword.equals(user.getPassword())) {
  registerForm.recordError(verifyPassword,
  messages.get(error.verify.password));
  errorDetected = true;
  }
 
 if (userService.getUserByLogin(user.getLogin()) != null) {
 
  registerForm.recordError(messages.get(error.user.already.exists));
  errorDetected = true;
 }
 
 if
  (customerService.getCustomerByBusinessName(customer.getBusinessName()) !=
  null) {
 
  registerForm.recordError(messages.get(error.customer.already.exists));
 errorDetected = true;
 }
 return errorDetected;
  }
  }
 
 
 
 -Registration.tml
  html t:type=layout title=Customer registration
   t:sidebarTitle=Current Time
   t:pageTitle=Register
   xmlns:t=http://tapestry.apache.org/schema/tapestry_5_1_0.xsd;
   xmlns:p=tapestry:parameter
 
  fieldset id=register
 form class=full-form t:id=registerForm
 t:errors/
 
 fieldset
 legendCustomer registration (company or private
  person)/legend
 
  t:beaneditor object=customer exclude=literal:id,users
  p:businessName
 t:label for=businessName/
 t:textfield t:id=businessName
  value=customer.businessName validate=required/
  /p:businessName
 p:contactPhone
 t:label for=customer_contactPhone/
 t:textfield t:id=customer_contactPhone
  value=customer.contactPhone validate=required/
  /p:contactPhone
 p:contactPerson
 t:label for=contactPerson/
 t:textfield t:id=contactPerson
  value=customer.contactPerson validate=required/
  /p:contactPerson
 p:businessAddress
 t:label for=businessAddress/
 t:textfield t:id=businessAddress
  value=customer.businessAddress validate=required/
  /p:businessAddress
 p:email
 t:label for=customer_email/
 t:textfield t:id=customer_email
  value=customer.email validate=email,required/
  /p:email
 /t:beaneditor
 /fieldset
 
 fieldset
 legendPersonal registration/legend
 t:beaneditor object=user exclude=literal:id,roles

Strange beaneditor behaviour

2010-09-28 Thread Anton Mezerny
Hi!

I have 2 classes:
public static class Parent{
private String name;
private String description;
private Child child;

//getters and setters
}

   public static class Child{
private String childName;
private String childDescr;
//getters and setters
}

Everything renders fine, when I have the Parent object with the Child object
nested in it, and I try to render this combination like here:
t:form
t:beaneditor object=parent add=child
t:parameter name=child

t:beaneditor object=parent.child/

/t:parameter
/t:beaneditor
/t:form

But if I change Parent class to:

 public static class Parent{
private String name;
private String description;
private Object child; //changed to Object instead of Child
//getters and setters
}

my nested child object doesn't renders on the page. There is no any
exception - just child's fields disappear.

Is it normal behaviour, or a bug? And if normal, why can't beaneditor
resolve class type and render child object like in first example above?


Re: Strange beaneditor behaviour

2010-09-28 Thread Anton Mezerny
Thank you, Howard, now it's clear.
But I have one more question - instead beaneditor, I tried to nest
beandisplay component into the parent beaneditor and despite all it works
fine even if it gets Object, not Child. Why in this case it works in a
different way?


2010/9/28 Howard Lewis Ship hls...@gmail.com

 Normal behavior.  Tapestry builds a model (the BeanModel) to identify
 the properties to edit. It does this based on the type of the
 property, which is statically determined.  The original type of the
 parent.child expression was Child.  When you changed the child
 property to be type Object, Tapestry built a model for Object, which
 as no properties.

 You can, alternatively, use the BeanModelSource to build a model
 object from Child.class, and pass that directly to the BeanEditor via
 its model parameter.


 On Tue, Sep 28, 2010 at 1:30 PM, Anton Mezerny anton.meze...@gmail.com
 wrote:
  Hi!
 
  I have 2 classes:
  public static class Parent{
 private String name;
 private String description;
 private Child child;
 
 //getters and setters
 }
 
public static class Child{
 private String childName;
 private String childDescr;
 //getters and setters
 }
 
  Everything renders fine, when I have the Parent object with the Child
 object
  nested in it, and I try to render this combination like here:
  t:form
  t:beaneditor object=parent add=child
 t:parameter name=child
 
 t:beaneditor object=parent.child/
 
 /t:parameter
  /t:beaneditor
  /t:form
 
  But if I change Parent class to:
 
   public static class Parent{
 private String name;
 private String description;
 private Object child; //changed to Object instead of Child
  //getters and setters
  }
 
  my nested child object doesn't renders on the page. There is no any
  exception - just child's fields disappear.
 
  Is it normal behaviour, or a bug? And if normal, why can't beaneditor
  resolve class type and render child object like in first example above?
 



 --
 Howard M. Lewis Ship

 Creator of Apache Tapestry

 The source for Tapestry training, mentoring and support. Contact me to
 learn how I can get you up and productive in Tapestry fast!

 (971) 678-5210
 http://howardlewisship.com

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




Re: Dynamic form

2010-09-18 Thread Anton Mezerny
Igor, I am now trying to write something like in your book, but first of all
I don't want to define blocks in one tml page, and a number or blocks in
java-class. I try to get component instance dynamically using method
 componentSource.getComponent(String)
but I have an exception on this method.

org.apache.tapestry5.internal.services.RenderQueueException
Render queue error in BeginRender[Step:dynamicformfield.delegate]: Failure
reading parameter 'to' of component Step:dynamicformfield.delegate: Unable
to resolve 'textfield' to a known page name. Available page names: (blank),
About, Contact, ExceptionReport, Index, PropertyDisplayBlocks,
PropertyEditBlocks, ServiceStatus, Step.

I can't understand why Tapestry looks for pages and not components. So for
example if I change method to componentSource.getPage(About); everything
renders fine - I get a number of About pages rendered inside my form. (About
is one of pages defined in my application)


2010/9/18 Markus Feindler markus.feind...@gmx.de

 Why would you need a submit notifier? I checked out your book and  it works
 fine without one.

  What you need is a combination of Loop, Delegate, and SubmitNotifier
 components and a couple of blocks inside your template. Check this out:


 http://code.google.com/p/tapestrybook/source/browse/trunk/tapestry-dynamic-forms/src/main/webapp/ViewReport.tml

 http://code.google.com/p/tapestrybook/source/browse/trunk/tapestry-dynamic-forms/src/main/java/de/t5book/pages/ViewReport.java

 On Sat, Sep 18, 2010 at 12:03 AM, Антон Мезерныйanton.meze...@gmail.com
 wrote:



 And what is the best way to create such a dynamic form? Using Delegate
 component or modifying beaneditform? Or maybe there is better approach?

 I tried to write it using Delegate and I have a problem - I can't get
 component instance from ComponentSource - Exception:

 org.apache.tapestry5.internal.services.RenderQueueException
 Render queue error in BeginRender[Step:dynamicformfield.delegate]:
 Failure
 reading parameter 'to' of component Step:dynamicformfield.delegate:
 Unable
 to resolve 'textfield' to a known page name. Available page names:
 (blank),
 About, Contact, ExceptionReport, Index, PropertyDisplayBlocks,
 PropertyEditBlocks, ServiceStatus, Step.

 Why is it looking for a page, not component?

 2010/9/17 Thiago H. de Paula Figueiredothiag...@gmail.com



 On Thu, 16 Sep 2010 19:09:05 -0300, Антон Мезерный
 anton.meze...@gmail.com  wrote:

  Hello,




 Hi!


  I am trying to make a dynamic form component, something like


 beaneditform,


 but based not on bean field type, but on some property in database.



 I strongly advise you to read the BeanEditor sources and do something
 similar or, better yet, contribute viewing and edition blocks. The end
 of
 this page shows you how to add blocks:
 http://tapestry.apache.org/tapestry5.1/guide/beaneditform.html. Besides
 that, create one of more DataTypeAnalyzer and contribute them to the
 DataTypeAnalyzer service. See

 http://tapestry.1045711.n5.nabble.com/Custom-Edit-Block-td2427355.htmlfor
 a little more detail.


  Another words I want to create something like


 t:${componentNameFromDB} ...



 Short answer: you can't. Tapestry pages and components have stricly


 static


 structure.
 Long answer: you can use blocks (t:block) and the Delegate component
 to
 render blocks or components dynamically.


  I tried to use delegate component, but as I understood, I should define


 all my components (inputs and other) inside one tml-page in block tags


 and




 Not necessarily in a single page.


  create block instances in java code. Can I do that with separate


 components for every element in the form?



 Yes.


  What is the best way to achieve it?




 ComponentSource will help you to grab page instances.

 --
 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-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




Re: Dynamic form

2010-09-18 Thread Anton Mezerny
Looking on ComponentSource code I understood, that it gets only components,
that are already defined within some page. Is there any way to get component
instance by its name even if this component is not used in any other page?

2010/9/18 Anton Mezerny anton.meze...@gmail.com

 Igor, I am now trying to write something like in your book, but first of
 all I don't want to define blocks in one tml page, and a number or blocks in
 java-class. I try to get component instance dynamically using method
  componentSource.getComponent(String)
 but I have an exception on this method.


 org.apache.tapestry5.internal.services.RenderQueueException
 Render queue error in BeginRender[Step:dynamicformfield.delegate]: Failure
 reading parameter 'to' of component Step:dynamicformfield.delegate: Unable
 to resolve 'textfield' to a known page name. Available page names: (blank),
 About, Contact, ExceptionReport, Index, PropertyDisplayBlocks,
 PropertyEditBlocks, ServiceStatus, Step.

 I can't understand why Tapestry looks for pages and not components. So for
 example if I change method to componentSource.getPage(About); everything
 renders fine - I get a number of About pages rendered inside my form. (About
 is one of pages defined in my application)


 2010/9/18 Markus Feindler markus.feind...@gmx.de

 Why would you need a submit notifier? I checked out your book and  it works
 fine without one.

  What you need is a combination of Loop, Delegate, and SubmitNotifier
 components and a couple of blocks inside your template. Check this out:


 http://code.google.com/p/tapestrybook/source/browse/trunk/tapestry-dynamic-forms/src/main/webapp/ViewReport.tml

 http://code.google.com/p/tapestrybook/source/browse/trunk/tapestry-dynamic-forms/src/main/java/de/t5book/pages/ViewReport.java

 On Sat, Sep 18, 2010 at 12:03 AM, Антон Мезерныйanton.meze...@gmail.com
 wrote:



 And what is the best way to create such a dynamic form? Using Delegate
 component or modifying beaneditform? Or maybe there is better approach?

 I tried to write it using Delegate and I have a problem - I can't get
 component instance from ComponentSource - Exception:

 org.apache.tapestry5.internal.services.RenderQueueException
 Render queue error in BeginRender[Step:dynamicformfield.delegate]:
 Failure
 reading parameter 'to' of component Step:dynamicformfield.delegate:
 Unable
 to resolve 'textfield' to a known page name. Available page names:
 (blank),
 About, Contact, ExceptionReport, Index, PropertyDisplayBlocks,
 PropertyEditBlocks, ServiceStatus, Step.

 Why is it looking for a page, not component?

 2010/9/17 Thiago H. de Paula Figueiredothiag...@gmail.com



 On Thu, 16 Sep 2010 19:09:05 -0300, Антон Мезерный
 anton.meze...@gmail.com  wrote:

  Hello,




 Hi!


  I am trying to make a dynamic form component, something like


 beaneditform,


 but based not on bean field type, but on some property in database.



 I strongly advise you to read the BeanEditor sources and do something
 similar or, better yet, contribute viewing and edition blocks. The end
 of
 this page shows you how to add blocks:
 http://tapestry.apache.org/tapestry5.1/guide/beaneditform.html.
 Besides
 that, create one of more DataTypeAnalyzer and contribute them to the
 DataTypeAnalyzer service. See

 http://tapestry.1045711.n5.nabble.com/Custom-Edit-Block-td2427355.htmlfor
 a little more detail.


  Another words I want to create something like


 t:${componentNameFromDB} ...



 Short answer: you can't. Tapestry pages and components have stricly


 static


 structure.
 Long answer: you can use blocks (t:block) and the Delegate component
 to
 render blocks or components dynamically.


  I tried to use delegate component, but as I understood, I should
 define


 all my components (inputs and other) inside one tml-page in block tags


 and




 Not necessarily in a single page.


  create block instances in java code. Can I do that with separate


 components for every element in the form?



 Yes.


  What is the best way to achieve it?




 ComponentSource will help you to grab page instances.

 --
 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-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