If you are going to store the error somewhere, maybe consider using the
TablePhaseListener as a model. It is storing "selection state" for each
row. You might be able to use a model like this to store "error state"
for a row.
Just an idea...
Steven Bell wrote:
> Thanks for the help Dan. That's what I was afraid of. I don't
> actually store the error anywhere, and the only indication is that
> there is a faces message present in the context for the client id. I
> guess I'll just have to store it somewhere.
>
> It seems it would be a nice feature for input components to be able to
> render invalid if a matching error exists. I'm guessing it wouldn't
> be a difficult thing as the message component renders with what must
> be similar logic (just guessing). Maybe I'll put together an RFE for
> this later.
>
> On Jan 8, 2008 6:43 PM, Dan Labrecque <Dan.Labrecque_at_sun.com
> <mailto:Dan.Labrecque_at_sun.com>> wrote:
>
> Use the same value expression you would normally assign via your
> JSP page (e.g., "#{someBean.someMethod}").
>
>
> Steven Bell wrote:
>> Getting the component and setting the ValueExpression looks like
>> it will work just fine, I just don't know what to put in the
>> 'expression' String.
>>
>> Basically what I would have is this I'm just not sure what would
>> go in that second string. I'm guessing I'd have to indicate in
>> some way what row this would apply to.
>>
>> UIComponent component = viewRoot.findComponent(uiField);
>> if(component != null && component instanceof UIInput){
>> setValueComponent(component, "valid", "?");
>> }
>> }
>>
>> On Jan 8, 2008 9:44 AM, Dan Labrecque <Dan.Labrecque_at_sun.com
>> <mailto:Dan.Labrecque_at_sun.com>> wrote:
>>
>> To set unique component values in a table, you must use a JSF
>> value
>> expression. (Only one component is used, but value
>> expressions allow you
>> to change each value per row.) Although "valid" is not a tag
>> attribute,
>> you can still set a value expression for it providing you have a
>> component "binding". Once you have the component instance,
>> you can use
>> the following code to create a value expression dynamically
>> via Java
>> (i.e., your backing bean).
>>
>> import javax.el.ValueExpression;
>> import javax.faces.context.FacesContext;
>> import javax.faces.component.UIComponent;
>> ...
>>
>> /**
>> * Helper method to set value expression property.
>> *
>> * @param component The UIComponent to set a value
>> expression for.
>> * @param name The name of the value expression property.
>> * @param expression The expresion for the value expression.
>> */
>> public static void setValueExpression(UIComponent
>> component, String
>> name,
>> String expression) {
>> if (expression == null) {
>> return;
>> }
>> FacesContext context = FacesContext.getCurrentInstance();
>> component.setValueExpression(name, createValueExpression(
>> context, expression, Object.class));
>> }
>>
>> public static ValueExpression createValueExpression(
>> FacesContext context, String expr, Class value) {
>> return context.getApplication().getExpressionFactory().
>> createValueExpression(context.getELContext(),
>> expr, value);
>> }
>>
>> That said, you might want to file a bug/RFE against textField
>> to help
>> make this easier. Highlighting invalid textField values was a
>> feature
>> recently added to Woodstock -- tables may have been overlooked?
>>
>> Dan
>>
>> Steven Bell wrote:
>> > Hi,
>> >
>> > I have a table used to enter line detail information. It's
>> basically
>> > a table with several columns, each one has a textField.
>> When the form
>> > is submitted I need to display and validation errors. At
>> one point in
>> > a backing bean I know that I have an error for a specific
>> field on a
>> > specific row. I add a FacesMessage to the context and I
>> can show the
>> > message in a messageGroup or message with the for attribute set
>> > easily, but I cannot figure out how to set the textFields valid
>> > property to false, so that it renders as in error (yellow
>> background).
>> >
>> > About the only think I could think to try was to get the
>> component out
>> > of the FacesContext and set valid to false, but there is
>> only one
>> > textField for the column at that point, and setting it's valid
>> > property seems to have no effect.
>> >
>> > Any ideas?
>> >
>> > --
>> > Regards,
>> >
>> > Steven Bell
>>
>> ---------------------------------------------------------------------
>>
>> To unsubscribe, e-mail:
>> users-unsubscribe_at_woodstock.dev.java.net
>> <mailto:users-unsubscribe_at_woodstock.dev.java.net>
>> For additional commands, e-mail:
>> users-help_at_woodstock.dev.java.net
>> <mailto:users-help_at_woodstock.dev.java.net>
>>
>>
>>
>>
>> --
>> Regards,
>>
>> Steven Bell
>
>
>
>
> --
> Regards,
>
> Steven Bell