You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Néstor Boscán <ne...@tcs.com.ve> on 2005/08/14 18:40:15 UTC

How to use with values stored in the request or page context

Hi

How can I use <html:multibox /> or <html:checkbox /> with values that are
stored in the request or page context?. I would like to do something like
<html:multibox value="<%= request.getAttribute (\"value\") %>"/> without
using the <% %> tags. Is there a way to use the JSTL Expression Language or
tell the <html:multibox /> tag to get the value from an attributo?.

Regards,

Néstor Boscán



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


Re: How to use with values stored in the request or page context

Posted by Laurie Harper <la...@holoweb.net>.
Néstor Boscán wrote:
> How can I use <html:multibox /> or <html:checkbox /> with values that are
> stored in the request or page context?. I would like to do something like
> <html:multibox value="<%= request.getAttribute (\"value\") %>"/> without
> using the <% %> tags. Is there a way to use the JSTL Expression Language or
> tell the <html:multibox /> tag to get the value from an attributo?.

<html:multibox value="${requestScope['value']}"/>

-- 
Laurie Harper
Open Source advocate, Java geek: http://www.holoweb.net/laurie
Founder, Zotech Software: http://www.zotechsoftware.com/


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


Re: How to use with values stored in the request or page context

Posted by Laurie Harper <la...@holoweb.net>.
Wendy Smoak wrote:
> From: "Néstor Boscán" <ne...@tcs.com.ve>
>> How can I use <html:multibox /> or <html:checkbox /> with values that are
>> stored in the request or page context?. I would like to do something like
>> <html:multibox value="<%= request.getAttribute (\"value\") %>"/> without
>> using the <% %> tags. Is there a way to use the JSTL Expression 
>> Language or
>> tell the <html:multibox /> tag to get the value from an attributo?.
> 
> You can... but the typical way to handle this is to put those values 
> into your form bean.  Do this in the Action, then forward to the JSP and 
> let the framework render the correct values in the HTML form elements.
> 
> If you use the 'value' attribute directly in the tags, you lose the 
> ability to re-display the user's incorrect input if the form fails 
> validation.

LOL, I just knew if I didn't say something to that effect you'd jump in 
Wendy ;-) Sorry, I should have mentioned the (non-obvious) reason I didn't: 
in the specific case where you're populating the 'value' attribute from a 
request parameter, you don't loose anything. The user's input *is* what 
you're redisplaying.

The caveat with that is, of course, if you redirect back to the original 
page (rather than forwarding, as by default) you'd loose the request data. 
Storing it into a form bean, and putting that bean in session scope, is the 
solution in that case.

L.
-- 
Laurie Harper
Open Source advocate, Java geek: http://www.holoweb.net/laurie
Founder, Zotech Software: http://www.zotechsoftware.com/


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


RE: How to use with values stored in the request or page context

Posted by Néstor Boscán <ne...@tcs.com.ve>.
Thanks Wendy

Regards,

Néstor Boscán 

-----Mensaje original-----
De: Wendy Smoak [mailto:java@wendysmoak.com] 
Enviado el: Sunday, August 14, 2005 6:08 PM
Para: Struts Users Mailing List
Asunto: Re: How to use <html:multibox /> with values stored in the request
or page context

From: "Néstor Boscán" <ne...@tcs.com.ve>

> The problem is that in the form bean you only set the values of the 
> <html:multibox /> or <html:checkbox /> that are selected, not all of them.
> So to draw all of them you need to take the values from somewhere 
> else, tipically an object that is in request or session context.

True. :)  Here's an example from one of my projects.  'accountMap' is a Map
of key/value pairs representing cost centers in the accounting system and
their descriptions.  This renders a checkbox for each cost center, and the
framework automatically "checks" the appropriate boxes depending on the
contents of the form bean's "accounts" property (which I think is a String[]
).

<c:forEach items="${accountMap}" var="item" >
   <html-el:multibox property="accounts" value="${item.key}"/>
   <c:out value="${item.key}"/> -
   <c:out value="${item.value.costCenterDesc}"/>
</c:forEach>

--
Wendy Smoak 



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




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


Re: How to use with values stored in the request or page context

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Néstor Boscán" <ne...@tcs.com.ve>

> The problem is that in the form bean you only set the values of the
> <html:multibox /> or <html:checkbox /> that are selected, not all of them.
> So to draw all of them you need to take the values from somewhere else,
> tipically an object that is in request or session context.

True. :)  Here's an example from one of my projects.  'accountMap' is a Map 
of key/value pairs representing cost centers in the accounting system and 
their descriptions.  This renders a checkbox for each cost center, and the 
framework automatically "checks" the appropriate boxes depending on the 
contents of the form bean's "accounts" property (which I think is a 
String[] ).

<c:forEach items="${accountMap}" var="item" >
   <html-el:multibox property="accounts" value="${item.key}"/>
   <c:out value="${item.key}"/> -
   <c:out value="${item.value.costCenterDesc}"/>
</c:forEach>

-- 
Wendy Smoak 



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


RE: How to use with values stored in the request or page context

Posted by Néstor Boscán <ne...@tcs.com.ve>.
Hi Wendy

Thanks for the reply.

The problem is that in the form bean you only set the values of the
<html:multibox /> or <html:checkbox /> that are selected, not all of them.
So to draw all of them you need to take the values from somewhere else,
tipically an object that is in request or session context.

Regards,

Néstor Boscán 

-----Mensaje original-----
De: Wendy Smoak [mailto:java@wendysmoak.com] 
Enviado el: Sunday, August 14, 2005 4:37 PM
Para: Struts Users Mailing List
Asunto: Re: How to use <html:multibox /> with values stored in the request
or page context

From: "Néstor Boscán" <ne...@tcs.com.ve>

> How can I use <html:multibox /> or <html:checkbox /> with values that 
> are stored in the request or page context?. I would like to do 
> something like <html:multibox value="<%= request.getAttribute 
> (\"value\") %>"/> without using the <% %> tags. Is there a way to use 
> the JSTL Expression Language or tell the <html:multibox /> tag to get 
> the value from an attributo?.

You can... but the typical way to handle this is to put those values into
your form bean.  Do this in the Action, then forward to the JSP and let the
framework render the correct values in the HTML form elements.

If you use the 'value' attribute directly in the tags, you lose the ability
to re-display the user's incorrect input if the form fails validation.

--
Wendy Smoak 



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




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


Re: How to use with values stored in the request or page context

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Néstor Boscán" <ne...@tcs.com.ve>

> How can I use <html:multibox /> or <html:checkbox /> with values that are
> stored in the request or page context?. I would like to do something like
> <html:multibox value="<%= request.getAttribute (\"value\") %>"/> without
> using the <% %> tags. Is there a way to use the JSTL Expression Language 
> or
> tell the <html:multibox /> tag to get the value from an attributo?.

You can... but the typical way to handle this is to put those values into 
your form bean.  Do this in the Action, then forward to the JSP and let the 
framework render the correct values in the HTML form elements.

If you use the 'value' attribute directly in the tags, you lose the ability 
to re-display the user's incorrect input if the form fails validation.

-- 
Wendy Smoak 



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