You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by David Van Stone <dv...@head.cfa.harvard.edu> on 2006/08/01 17:49:51 UTC
Validating Multiple Components in DataTable
I have a row in a data table which has a few input fields which I want to
validate together. I know the technique of binding the items then using a
hidden input field that is linked to a validator method. As so:
<h:dataTable .. value="#{outerBB.itemBB}" var="item"
rendered="#{outerBB.hasItems}">>
<h:inputText id="value1" value="#{item.value1}"
binding="#{item.value1Input}">
<h:inputText id="value2" value="#{item.value2}"
binding="#{item.value2Input}">
<h:inputHidden id="datacheck" validator="#{item.validateFields}"
value="dummy"/>
</h:dataTable>
(There is just logging so far in the validateFields() method.)
However, I don't get very far when the page appears for the first time (with
no rows in the table):
javax.faces.el.PropertyNotFoundException: Base is null: item
at
org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(ValueBindingImpl.java:460)
at
org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java:248)
at
org.apache.myfaces.application.ApplicationImpl.createComponent(ApplicationImpl.java:449)
at
javax.faces.webapp.UIComponentTag.createComponentInstance(UIComponentTag.java:709)
at javax.faces.webapp.UIComponentTag.findComponent(UIComponentTag.java:596)
...
If I remove the 'binding="#..."' code, the application calls validateFields
fine.
* Can one set up bindings to elements in a dataTable?
I think I'm missing something, since the data table shouldn't be rendered
and has no items to render. What is it trying to bind at that point?
Thanks for any help,
-David-
--
View this message in context: http://www.nabble.com/Validating-Multiple-Components-in-DataTable-tf2034458.html#a5597324
Sent from the MyFaces - Users forum at Nabble.com.
Re: Validating Multiple Components in DataTable
Posted by Andrew Robinson <an...@gmail.com>.
Data table requires its children to be columns or facets.
<h:dataTable .. value="#{outerBB.itemBB}" var="item"
rendered="#{outerBB.hasItems}">>
<t:column>
<h:inputText id="value1" value="#{item.value1}"
...
On 8/1/06, David Van Stone <dv...@head.cfa.harvard.edu> wrote:
>
> I have a row in a data table which has a few input fields which I want to
> validate together. I know the technique of binding the items then using a
> hidden input field that is linked to a validator method. As so:
>
> <h:dataTable .. value="#{outerBB.itemBB}" var="item"
> rendered="#{outerBB.hasItems}">>
>
> <h:inputText id="value1" value="#{item.value1}"
> binding="#{item.value1Input}">
> <h:inputText id="value2" value="#{item.value2}"
> binding="#{item.value2Input}">
> <h:inputHidden id="datacheck" validator="#{item.validateFields}"
> value="dummy"/>
>
> </h:dataTable>
>
> (There is just logging so far in the validateFields() method.)
>
> However, I don't get very far when the page appears for the first time (with
> no rows in the table):
>
> javax.faces.el.PropertyNotFoundException: Base is null: item
> at
> org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(ValueBindingImpl.java:460)
> at
> org.apache.myfaces.el.ValueBindingImpl.setValue(ValueBindingImpl.java:248)
> at
> org.apache.myfaces.application.ApplicationImpl.createComponent(ApplicationImpl.java:449)
> at
> javax.faces.webapp.UIComponentTag.createComponentInstance(UIComponentTag.java:709)
> at javax.faces.webapp.UIComponentTag.findComponent(UIComponentTag.java:596)
> ...
>
> If I remove the 'binding="#..."' code, the application calls validateFields
> fine.
>
> * Can one set up bindings to elements in a dataTable?
>
> I think I'm missing something, since the data table shouldn't be rendered
> and has no items to render. What is it trying to bind at that point?
>
> Thanks for any help,
>
> -David-
> --
> View this message in context: http://www.nabble.com/Validating-Multiple-Components-in-DataTable-tf2034458.html#a5597324
> Sent from the MyFaces - Users forum at Nabble.com.
>
>
Re: Validating Multiple Components in DataTable
Posted by Mike Kienenberger <mk...@gmail.com>.
On 8/1/06, David Van Stone <dv...@head.cfa.harvard.edu> wrote:
> I have a row in a data table which has a few input fields which I want to
> validate together. I know the technique of binding the items then using a
> hidden input field that is linked to a validator method. As so:
Depending on what you're doing, you might want to look at the
validateCompareTo component in the sandbox. It's pretty smart about
dealing with the various states two components might be in while
comparing the two. However, it only compares two fields at a time.
You could use the same code to handle more fields, though.
It's hard to say how well this would work inside of a UIData due to
the rowState issues.
Re: Validating Multiple Components in DataTable
Posted by Mike Kienenberger <mk...@gmail.com>.
On 8/2/06, David Van Stone <dv...@head.cfa.harvard.edu> wrote:
> >> I needed to add the class (representing a row) as a managed bean in
> >> faces-config.xml with scope of "none":
> The managed bean is not stored anywhere but is created by the developer as
> needed. (I.e., another class creates/destroys it.)
>
> However, as I'll be posting soon, this only makes the initial error during
> JSP compilation go away. MyFaces appears to make the binding on a seperate
> copy of the class and not bindings on each row.
Ok. That makes more sense to me. Yes, adding this wouldn't really
solve your issue. Your item variable should be stuck into the context
by the datatable itself without anything on your part.
Not sure if it helps, but you need to make sure the data table is set
to the specific row you're working with at the time you're doing your
validation. I would guess that is the case, but you might want to
check on that.
UIData.setRowIndex(row) to set it. If it's already set to -1, that
means the data table isn't pointing at any particular row, which is
normally the case.
Re: Validating Multiple Components in DataTable
Posted by David Van Stone <dv...@head.cfa.harvard.edu>.
>> I needed to add the class (representing a row) as a managed bean in
>> faces-config.xml with scope of "none":
>>
>> <managed-bean>
>> <managed-bean-name>item</managed-bean-name>
>>
>> <managed-bean-class>whatever.the.class.is.called</managed-bean-class>
>> <managed-bean-scope>none</managed-bean-scope>
>> </managed-bean>
>>
>> Without this, you get the "Base is null" error.
>
>I've never heard of that before. What's it supposed to do for you?
The managed bean is not stored anywhere but is created by the developer as
needed. (I.e., another class creates/destroys it.)
However, as I'll be posting soon, this only makes the initial error during
JSP compilation go away. MyFaces appears to make the binding on a seperate
copy of the class and not bindings on each row.
Thanks also for your suggestion on using <s:validateCompareTo/>. If I get
completely stuck I might go that route. (The validation is more complicated
than a simple comparitor, but I might get some ideas there.)
-David-
--
View this message in context: http://www.nabble.com/Validating-Multiple-Components-in-DataTable-tf2034458.html#a5618896
Sent from the MyFaces - Users forum at Nabble.com.
Re: Validating Multiple Components in DataTable
Posted by Mike Kienenberger <mk...@gmail.com>.
On 8/2/06, David Van Stone <dv...@head.cfa.harvard.edu> wrote:
> I made a new test JSF application to try to recreate the problem, in order to
> publish on this forum. Instead, I got to carefully review all the pieces and
> in the process solved it.
>
> I needed to add the class (representing a row) as a managed bean in
> faces-config.xml with scope of "none":
>
> <managed-bean>
> <managed-bean-name>item</managed-bean-name>
> <managed-bean-class>whatever.the.class.is.called</managed-bean-class>
> <managed-bean-scope>none</managed-bean-scope>
> </managed-bean>
>
> Without this, you get the "Base is null" error.
I've never heard of that before. What's it supposed to do for you?
Re: Validating Multiple Components in DataTable
Posted by David Van Stone <dv...@head.cfa.harvard.edu>.
I made a new test JSF application to try to recreate the problem, in order to
publish on this forum. Instead, I got to carefully review all the pieces and
in the process solved it.
I needed to add the class (representing a row) as a managed bean in
faces-config.xml with scope of "none":
<managed-bean>
<managed-bean-name>item</managed-bean-name>
<managed-bean-class>whatever.the.class.is.called</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
</managed-bean>
Without this, you get the "Base is null" error.
Thanks for the responses!
-David-
--
View this message in context: http://www.nabble.com/Validating-Multiple-Components-in-DataTable-tf2034458.html#a5616734
Sent from the MyFaces - Users forum at Nabble.com.