users@woodstock.java.net

Re: Setting textField valid=false in table.

From: Steven Bell <bell.steven_at_gmail.com>
Date: Tue, 8 Jan 2008 13:36:04 -0800

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> 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
> For additional commands, e-mail: users-help_at_woodstock.dev.java.net
>
>


-- 
Regards,
Steven Bell