You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Max Grigoriev <da...@mail.ru> on 2003/09/30 18:52:24 UTC

Checkbox question

Hello tapestry-user,

I've got  list of CategoryType, and Organization which can contain one
or more CategoryType.

Organization class :
...
 public List getCategoryTypes() {
    return categoryTypes;
  }

  public void setCategoryTypes(List categoryTypes) {
    this.categoryTypes = categoryTypes;
  }
...


Page template:
----------------------------------------------------------------------
<tr jwcid="@Foreach"
    source="ognl:bean.categoryTypes"
    value="ognl:bean.currentType" element="tr">
  <td width="100%">
    <input type="checkbox" jwcid="@Checkbox"
           selected="ognl:bean.organization.categoryTypes.contains(bean.currentType)"/>&nbsp;
     <span jwcid="@Insert" value="ognl:bean.currentType.name"/>
  </td>
</tr>
-----------------------------------------------------------------------

Is it possible to make standart Checkbox unselected, when no CategoryType in
Organization. And when user selects CategoryType, then this type is
added in Organization category list ?

Thank's

-- 
Best regards,
 Max                          mailto:darkit@mail.ru


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


Re[2]: Checkbox question

Posted by Max Grigoriev <da...@mail.ru>.
Hello Paul,

Thank's

Tuesday, September 30, 2003, 10:24:35 PM, you wrote:

PF> You cannot use contains(...) for the selected attribute since
PF> it requires a valid JavaBean mutator.
PF> Try this:

PF> Page template:

PF> <tr jwcid="@Foreach" source="ognl:bean.categoryTypes"
PF> value="ognl:bean.currentType" element="tr">
PF> 	<td width="100%"><input type="checkbox" jwcid="@Checkbox"
PF> selected="ognl:selectedCategoryType"/>&nbsp;<span jwcid="@Insert"
PF> value="ognl:bean.currentType.name"/></td>
PF> </tr>

PF> in Page class:

PF> public boolean getSelectedCategoryType() {
PF> 	return
PF> getBean().getOrganization().getCategoryTypes().contains(getBean().getCurrentType());
PF> }

PF> public void setSelectedCategoryType(boolean selected) {
PF> 	if (selected) {
PF> 		getBean().getOrganization().getCategoryTypes().add(getBean().getCurrentType());
PF> 	} else {
PF> 		getBean().getOrganization().getCategoryTypes().remove(getBean().getCurrentType());
PF> 	}
PF> }

PF> For better performance, you should consider using a set
PF> rather than a list to avoid the O(N) cost of contains(Object) and
PF> remove(Object) on a list.
PF> - or, alternatively, investigate using ArrayList.get(int) and
PF> ArrayList.remove(int) and add an index attribute to your Foreach.

PF> Hope this helps,



-- 
Best regards,
 Max                            mailto:darkit@mail.ru


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


Re: Checkbox question

Posted by Paul Ferraro <pm...@columbia.edu>.
You cannot use contains(...) for the selected attribute since it requires a valid JavaBean mutator.
Try this:

Page template:

<tr jwcid="@Foreach" source="ognl:bean.categoryTypes" value="ognl:bean.currentType" element="tr">
	<td width="100%"><input type="checkbox" jwcid="@Checkbox" selected="ognl:selectedCategoryType"/>&nbsp;<span jwcid="@Insert" value="ognl:bean.currentType.name"/></td>
</tr>

in Page class:

public boolean getSelectedCategoryType() {
	return getBean().getOrganization().getCategoryTypes().contains(getBean().getCurrentType());
}

public void setSelectedCategoryType(boolean selected) {
	if (selected) {
		getBean().getOrganization().getCategoryTypes().add(getBean().getCurrentType());
	} else {
		getBean().getOrganization().getCategoryTypes().remove(getBean().getCurrentType());
	}
}

For better performance, you should consider using a set rather than a list to avoid the O(N) cost of contains(Object) and remove(Object) on a list.
- or, alternatively, investigate using ArrayList.get(int) and ArrayList.remove(int) and add an index attribute to your Foreach.

Hope this helps,

Paul Ferraro

On Tuesday 30 September 2003 09:52, Max Grigoriev wrote:
> Hello tapestry-user,
>
> I've got  list of CategoryType, and Organization which can contain one
> or more CategoryType.
>
> Organization class :
> ...
>  public List getCategoryTypes() {
>     return categoryTypes;
>   }
>
>   public void setCategoryTypes(List categoryTypes) {
>     this.categoryTypes = categoryTypes;
>   }
> ...
>
>
> Page template:
> ----------------------------------------------------------------------
> <tr jwcid="@Foreach"
>     source="ognl:bean.categoryTypes"
>     value="ognl:bean.currentType" element="tr">
>   <td width="100%">
>     <input type="checkbox" jwcid="@Checkbox"
>           
> selected="ognl:bean.organization.categoryTypes.contains(bean.currentType)"/
>>&nbsp; <span jwcid="@Insert" value="ognl:bean.currentType.name"/>
>   </td>
> </tr>
> -----------------------------------------------------------------------
>
> Is it possible to make standart Checkbox unselected, when no CategoryType
> in Organization. And when user selects CategoryType, then this type is
> added in Organization category list ?
>
> Thank's


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