From adffaces-user-return-2675-apmail-incubator-adffaces-user-archive=incubator.apache.org@incubator.apache.org Mon Apr 09 17:03:54 2007
Return-Path:
Delivered-To: apmail-incubator-adffaces-user-archive@locus.apache.org
Received: (qmail 69546 invoked from network); 9 Apr 2007 17:03:54 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2)
by minotaur.apache.org with SMTP; 9 Apr 2007 17:03:54 -0000
Received: (qmail 82160 invoked by uid 500); 9 Apr 2007 17:03:59 -0000
Delivered-To: apmail-incubator-adffaces-user-archive@incubator.apache.org
Received: (qmail 82146 invoked by uid 500); 9 Apr 2007 17:03:59 -0000
Mailing-List: contact adffaces-user-help@incubator.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: adffaces-user@incubator.apache.org
Delivered-To: mailing list adffaces-user@incubator.apache.org
Received: (qmail 82137 invoked by uid 99); 9 Apr 2007 17:03:59 -0000
Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Apr 2007 10:03:59 -0700
X-ASF-Spam-Status: No, hits=0.0 required=10.0
tests=
X-Spam-Check-By: apache.org
Received-SPF: pass (herse.apache.org: local policy)
Received: from [192.234.253.30] (HELO nemours.org) (192.234.253.30)
by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Apr 2007 10:03:52 -0700
Received: from nemapp38.nemours.org ([172.19.10.55]) by nemours.org with Microsoft SMTPSVC(5.0.2195.6713);
Mon, 9 Apr 2007 13:04:54 -0400
Received: from 10.20.11.90 by nemapp38.nemours.org with ESMTP (SMTP
Relay); Mon, 09 Apr 2007 13:03:45 -0400
X-Server-Uuid: 35EBC2B0-EA10-409F-9923-04DFACBAF8D2
Received: from jaxmsx02.nemours.org ([10.20.9.25]) by
nemmsx01.nemours.org with Microsoft SMTPSVC(5.0.2195.6713); Mon, 9 Apr
2007 13:03:13 -0400
Content-class: urn:content-classes:message
MIME-Version: 1.0
X-MimeOLE: Produced By Microsoft Exchange V6.5
Subject: RE: Keeping selectOneChoice selection
Date: Mon, 9 Apr 2007 13:03:12 -0400
Message-ID: <5B930A45C354E84395A194D500589ED80DBE48@jaxmsx02.nemours.org>
In-Reply-To: <37858.194.65.31.9.1176138026.squirrel@www.opensoft.pt>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: Keeping selectOneChoice selection
Thread-Index: Acd6yIcEYbliuneDTuqVpS0gqyEgbgAADJQg
From: "William Hoover"
To: adffaces-user@incubator.apache.org
X-OriginalArrivalTime: 09 Apr 2007 17:03:13.0077 (UTC)
FILETIME=[F54B9E50:01C77AC8]
X-WSS-ID: 6A04AE7B1NS50962-01-01
Content-Type: text/plain;
charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
X-Brightmail-Tracker: AAAAAwAAA+0AAAPsAAAD7g==
X-Language-Identified: TRUE
X-Virus-Checked: Checked by ClamAV on apache.org
Francisco,
Sure... Can you send the jsf code and the html rendered on the client =
page?
-----Original Message-----
From: Francisco Passos [mailto:francisco.passos@opensoft.pt]
Sent: Monday, April 09, 2007 1:00 PM
To: adffaces-user@incubator.apache.org
Subject: RE: Keeping selectOneChoice selection
Thank you for your hints.
I will bear this in mind when I come to this situation - which will be
soon enough.
However, back to this this particular scenario where no table is =
involved,
do you know of any way I manage to solve this problem?
> Francisco,
>
> I have found that there is a fundamental problem with how
> UINamingContainers are processed when row indexes are inserted into =
the
> ids of EditableValueHolders within the container rows.
>
> Understanding The Problem:
> As you may already know, tables have only columns referenced in the =
page
> so it can handle an almost infinite number of rows. Well, because you =
have
> only specified an id for a component within the table column the =
component
> inserts a row index reference in the holders id (via getClientRowKey() =
in
> a table) for each row. This ensures that each iteration of that row =
has a
> unique id. The problem with this is that in some cases this breaks
> automatic setting of bean values (if they are value bound to an
> EditableValueHolder within a row). Another issue is that =
"selectOneChoice"
> components in particular do not have a mechanism in place to ensure =
that a
> submitted value that gets set on the component is one of the values =
within
> the internal "SelectItemList" so virtually any value can get set on =
it. If
> the submitted value is not in the list it adds a blank entry in the =
drop
> down menu- what? I have also noticed that selectOneChoice component =
does
> not handle value conversion like regular input text components do.
> Semi-primitive values such as Integers, Booleans, etc. are not =
converted
> automatically like they are for regular input text components. I had =
some
> of the same issues with the "detailStamp" so I created an extended =
table
> component that allows only one toggled "detailStamp" at a time and
> overrides the "getClientRowKey()" excluding row indexes for components
> within the "detailStamp". This solution works very well, but still =
does
> not address EditableValueHolders within the rows themselves. It seems =
to
> me that we need to reevaluate the usage of inserting row indexes into =
ids!
>
> Possible Solutions:
> The first thing I would check is that you have the =
valuePassThru=3D"true" to
> ensure that its not trying to use the index as the passed value (not =
sure
> why anyone would want to be restricted to just an index). If want to
> ensure that your value is never set to a value that does not exist in =
the
> options you can use a value change listener:
>
>
> /**
> * Verifies that an editable value holder event components value is a
> valid
> * option. If it is not it sets it back to the old value.
> *
> * @see #getEditableValueHolderValue(EditableValueHolder)
> * @param event
> */
> public final void verifyValueOption(ValueChangeEvent event) {
> try {
> if (event.getComponent() instanceof EditableValueHolder) {
> EditableValueHolder valueHolder =3D (EditableValueHolder) event
> .getComponent();
> if (!isValidSelectOption(event.getComponent(), =
event.getNewValue())) {
> // invalid option- regress to old value
> valueHolder.setValue(event.getOldValue());
> valueHolder.setSubmittedValue(event.getOldValue());
> }
> }
> } catch (Throwable e) {
> log.warn("Unable to verify select value. " + e.getMessage()
> + " cause: " + e.getCause());
> }
> }
>
> /**
> * Determines if the specified value is a valid selection option in =
the
> * specified select component.
> *
> * @param component
> * @param value
> * @return is the specified value a valid select option
> */
> public static final boolean isValidSelectOption(UIComponent =
component,
> Object value) {
> try {
> List items =3D SelectItemSupport.getSelectItems(
> component, SelectItemSupport.getConverter(component));
> for (SelectItem item : items) {
> if (item.getValue() !=3D null && item.getValue().equals(value)) {
> return true;
> }
> }
> } catch (Exception e) {
> _LOG.warning("Unable to determine if the specified value: " + value
> + " is valid for the select component: " + component);
> }
> return false;
> }
>
>
>
> Probably not the most elegant solution, but nonetheless an effective =
one
> is to manage the submitted row index problems yourself. If nothing =
else
> this will provide you with a debugging tool to determine if the row =
index
> references are preventing your values from getting set:
> /**
> *
> * Gets a parameter value from the request scope by an editale value
> holder
> * components id. This method will set/return the holders submitted =
value
> * from the request.
> *
> *
> * The holders client id is checked against a possible matching id
> request
> * parameter. The client id of the holder and the request parameter
> matching
> * the hodler id may have their own row indexing (such is the case =
with a
> * select menu).
> *
> * - The client id against the request parameter
> * - The client id w/o row index against the request parameter
> * - The client id against the request parameter w/o row index
> *
> *
> *
> * @param context
> * @param holder
> * @return the parameter value
> */
> @SuppressWarnings("unchecked")
> public static final Object getRequestParameterByHolderId(
> FacesContext context, EditableValueHolder holder) {
> if (log.isDebugEnabled())
> log.debug("getRequestParameterForNamingContainer(" + context + ','
> + holder + ")");
> if (holder !=3D null && holder instanceof UIComponent) {
> String clientId =3D ((UIComponent) holder).getClientId(context);
> String clientIdWithOutRowIds =3D removeRowIdReferences(clientId);
> String id =3D ((UIComponent) holder).getId();
> Map map =3D context.getExternalContext()
> .getRequestParameterMap();
> if (map !=3D null && map.entrySet() !=3D null) {
> for (Map.Entry entry : map.entrySet()) {
> if (entry.getKey().indexOf(id) >=3D 0) {
> if (entry.getKey().equalsIgnoreCase(clientId)
> || entry.getKey().equalsIgnoreCase(
> clientIdWithOutRowIds)
> || removeRowIdReferences(
> entry.getKey()).equalsIgnoreCase(
> clientId)) {
> try {
> setConvertedAndValidatedValue(context,
> holder, entry.getValue());
> } catch (Exception e) {
> log.error("Unable to capture the converted "
> + "value for component(" + holder
> + ") value: " + entry.getValue(), e);
> }
> return holder.getSubmittedValue();
> }
> }
> }
> }
> }
> return null;
> }
>
> /**
> * Removes any row id references that may exist within the specified
> client
> * id
> *
> * @param clientId
> * @return the client id
> */
> public static final String removeRowIdReferences(String clientId) {
> if (log.isDebugEnabled())
> log.debug("removeRowIdReferences(" + clientId + ')');
> if (clientId !=3D null) {
> String[] ids =3D clientId.split(String
> .valueOf(NamingContainer.SEPARATOR_CHAR));
> for (String id : ids) {
> try {
> Integer.parseInt(id);
> } catch (Exception e) {
> continue;
> }
> clientId =3D clientId.replace(NamingContainer.SEPARATOR_CHAR + id
> + NamingContainer.SEPARATOR_CHAR, String
> .valueOf(NamingContainer.SEPARATOR_CHAR));
> }
> }
> return clientId;
> }
>
> /**
> * Invokes the internal converter/validators(s) for an editable value
> holder
> * and returns the converted value
> *
> * @param context
> * @param holder
> * @param value
> * @return the converted value
> * @throws ValidatorException
> * @throws EvaluationException
> * @throws MethodNotFoundException
> */
> public static final Object setConvertedAndValidatedValue(FacesContext
> context,
> EditableValueHolder holder, Object value)
> throws ValidatorException, EvaluationException,
> MethodNotFoundException {
> if (holder !=3D null) {
> if (holder.getConverter() !=3D null) {
> value =3D holder.getConverter().getAsObject(context,
> (UIComponent) holder,
> value !=3D null ? value.toString() : null);
> }
> if (holder instanceof UIComponent) {
> if (holder.getValidators() !=3D null) {
> for (Validator v : holder.getValidators()) {
> v.validate(context, (UIComponent) holder, value);
> }
> }
> }
> if (holder.getValidator() !=3D null) {
> holder.getValidator().invoke(context, new Object[] { value });
> }
> holder.setSubmittedValue(value);
> return value;
> }
> return null;
> }
>
> -----Original Message-----
> From: Francisco Passos [mailto:francisco.passos@opensoft.pt]
> Sent: Monday, April 09, 2007 11:17 AM
> To: William Hoover
> Subject: RE: Keeping selectOneChoice selection
>
>
> No, it is in a facet for a panelPage.
>
> In it, I have a panelGroupLayout, then a panelHorizontalLayout and =
finally
> in it the panelPage.
>
> If you feel it's best, I can attach the code or paste it in the mail =
body.
>
> Either way, if the selectOneChoice were in a table (something I will
> surely need), what would the solution be?
>
> Thank you,
>
> Francisco
>
>
>
>> Francisco,
>>
>> Is your selectOneChoice in a table?
>>
>> -----Original Message-----
>> From: Francisco Passos [mailto:francisco.passos@opensoft.pt]
>> Sent: Monday, April 09, 2007 10:55 AM
>> To: adffaces-user@incubator.apache.org
>> Subject: Keeping selectOneChoice selection
>>
>>
>> Hello there.
>>
>> I'm new to JSF and Trinidad, so please bear with my simplistic =
doubts.
>>
>> I'm struggling to keep a selectOneChoice selection upon a postback =
using
>> a
>> request-scoped bean.
>>
>> At first I couldn't even maintain the values in the list, but I found
>> that
>> placing a h:inputHidden on the page and declaring its value to be
>> #{myBean.valueList}, they could be kept. Furthermore I've tested the
>> seme
>> using pageFlow and it worked.
>>
>> However, I cannot keep the selected value in the dropdown list, it =
just
>> resets.
>>
>> What is the correct way to do this simple task without using session
>> beans?
>>
>> Thank you for your time and attention,
>>
>> Francisco Passos
>>
>>
>>
>
>
> Francisco Passos
> Opensoft - Solu=E7=F5es Inform=E1ticas, Lda
> Telem=F3vel: +351 91 238 52 76
> Escrit=F3rio: +351 21 380 44 10
> Email: francisco.passos@opensoft.pt
>
>
>
Francisco Passos
Opensoft - Solu=E7=F5es Inform=E1ticas, Lda
Telem=F3vel: +351 91 238 52 76
Escrit=F3rio: +351 21 380 44 10
Email: francisco.passos@opensoft.pt