You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Bastian Voigt <po...@bastian-voigt.de> on 2007/04/17 19:04:01 UTC

Using Read-only properties in forms

Another question regarding tapestry programming style.
Imagine I have a read-only property of some object which I need to include in 
a hidden field in a form so that the value is still there after posting the 
form. Since tapestry does not support read-only properties in forms, I need a 
second read-write property which takes care of storing the value after post.

What I have done (inside a component class) looks like this:

// my read only property which I want to include in the form
@Parameter()
public abstract Object getReadOnlyValue();

// the property used for the form hidden field
public Object getHiddenFormValue() {return getReadOnlyValue();}
public void setHiddenFormValue(Object o) {setSomeOtherProperty(o);}

// the property where tapestry can store the hidden field value 
// when submitting the form
public abstract Object getSomeOtherProperty();
public abstract void setSomeOtherProperty(Object o);

// my form submit listener
public void listener()
{
	Object o = getSomeOtherProperty(); // allright, here is my value again
}


OK, it works, but IMO it is quite confusing and does not look so nice...
Question: Are there better solutions for this problem?

-- 
Bastian Voigt
Neumünstersche Straße 4
20251 Hamburg
telefon 040/67957171
mobil   0179/4826359

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


Re: Using Read-only properties in forms

Posted by jake123 <ja...@gmail.com>.
Hi Bastian,
you mean something like this :

  <tr jwcid="@For" source="ognl:myObjectList" value="ognl:myObject"
element="tr">
    <td><input jwcid="@Hidden" value="ognl:myObject.myId" id="myId" /> </td>
    <td></td>
    <td></td>
  </tr>

Jacob

-- 
View this message in context: http://www.nabble.com/Using-Read-only-properties-in-forms-tf3593738.html#a10045713
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: Using Read-only properties in forms

Posted by Bastian Voigt <po...@bastian-voigt.de>.
Jacob,
thanks for your quick reply! I have also used this pageBeginRender 
approch in some of my components. Unfortunately, pageBeginRender is not 
always the right place to read properties. In the example from my 
initial post I used a @For loop to render a block which includes a form. 
The source iterator of the for loop comes from a database and is read 
only when the page is being rendered, so it is not available in 
pageBeginRender.

Regards
Bastian

jake123 schrieb:
> Have you tried:
>
> in html:
>
> <input jwcid="@Hidden" value="ognl:myId" id="myId" />
>
> in java: 
>
> public abstract class MyPage extends BasePage implements
> PageBeginRenderListener {
>
>   public abstract Long getMyId();
>   public abstract void setMyId(Long id);
>
>   public void pageBeginRender(PageEvent event) {
>
>     MyObject myObject = getMyService().getMyObject();
>
>     /* set the hidden value */
>     setMyId(myObject.getMyId);
>
>   }
>
> }
>   


Re: Using Read-only properties in forms

Posted by jake123 <ja...@gmail.com>.
Have you tried:

in html:

<input jwcid="@Hidden" value="ognl:myId" id="myId" />

in java: 

public abstract class MyPage extends BasePage implements
PageBeginRenderListener {

  public abstract Long getMyId();
  public abstract void setMyId(Long id);

  public void pageBeginRender(PageEvent event) {

    MyObject myObject = getMyService().getMyObject();

    /* set the hidden value */
    setMyId(myObject.getMyId);

  }

}

Hope it helps,
Jacob


Bastian Voigt wrote:
> 
> Another question regarding tapestry programming style.
> Imagine I have a read-only property of some object which I need to include
> in 
> a hidden field in a form so that the value is still there after posting
> the 
> form. Since tapestry does not support read-only properties in forms, I
> need a 
> second read-write property which takes care of storing the value after
> post.
> 
> What I have done (inside a component class) looks like this:
> 
> // my read only property which I want to include in the form
> @Parameter()
> public abstract Object getReadOnlyValue();
> 
> // the property used for the form hidden field
> public Object getHiddenFormValue() {return getReadOnlyValue();}
> public void setHiddenFormValue(Object o) {setSomeOtherProperty(o);}
> 
> // the property where tapestry can store the hidden field value 
> // when submitting the form
> public abstract Object getSomeOtherProperty();
> public abstract void setSomeOtherProperty(Object o);
> 
> // my form submit listener
> public void listener()
> {
> 	Object o = getSomeOtherProperty(); // allright, here is my value again
> }
> 
> 
> OK, it works, but IMO it is quite confusing and does not look so nice...
> Question: Are there better solutions for this problem?
> 
> -- 
> Bastian Voigt
> Neumünstersche Straße 4
> 20251 Hamburg
> telefon 040/67957171
> mobil   0179/4826359
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-Read-only-properties-in-forms-tf3593738.html#a10042257
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