RE: Validating Multiple Components in DataTable
. Graeme. From: David Delbecq [mailto:[EMAIL PROTECTED] Sent: Fri 20/07/2007 10:18 PM To: MyFaces Discussion Subject: Re: Validating Multiple Components in DataTable Quick suggestion: tr:table id=tblx value=#{bean.collection} binding=#{bean.coreTable} var=entry tr:column tr:inputText value=#{entry.prop1} id=prop1 my:NotNullIfOtherNotNull others=prop2,prop3,prop4/ /tr:inputText /tr:column tr:column tr:inputText value=#{entry.prop2} id=prop2 as for the content of the cutsom my:NotNullIfOtherNotNull, i suggest you look at code of validateEqual in tomahawk, that check 2 component value are same. You can do similar thing with null. That way, non need to limit your check to the use of a UIData. En l'instant précis du 20/07/07 12:56, Graeme Steyn s'exprimait en ces termes: Hi, I have a tr:table component that is displaying rows from an ArrayLIst containing instances of class X. I would like to introduce a validator that checks that if information is entered for any property, then all properties must be populated for that row. ANy rows that have no data entered or all data entered are thus valid. At present I have the arrangement provided below, but I appear to be getting the instances of X from the original collection, rather than the table components local values. Thus when the view is first displayed, I can enter data in row 1 cell 1 and press next to invoke a POST back and the validation. Using the debugger, I find that the first iteration through the loop returns an instance of X, but without the posted back data (everything is null). I do not appear to be getting at the local converted value. Any help would be greatly appreciated. Thank you, Regards, Graeme. PS. I came across a related query located at http://mail-archives.apache.org/mod_mbox/myfaces-users/200608.mbox/[EMAIL PROTECTED] I am trying to avoid binding as the user will be able to add and delete rows within my datatable, so I was hoping to keep things flexible. public class X { private String prop1; private String prop2; private String prop3; getters/setters...etc } class BackingBean { Collection X collection = new ArrayList X (); etc } tr:message for=validateRows / tr:table id=tblx value=#{bean.collection} binding=#{bean.coreTable} var=entry tr:column tr:inputText value=#{entry.prop1} / /tr:column tr:column tr:inputText value=#{entry.prop2} / /tr:column : : etc /tr:table tr:inputHidden id=validateRows value=dummy validator=#{bean.validateRows} / = Will only catch the first invlaid instance in the table - the validation message appears at the table level rather than per row. public void validateEntriesComplete(FacesContext facesContext, UIComponent uIComponent, Object object) throws ValidatorException { UIXCollection uixCollection = (UIXCollection) coreTable; int oldRowIndex = uixCollection.getRowIndex(); for (int rowNum = 0, numRows = uixCollection.getRowCount(); rowNum numRows; rowNum++) { uixCollection.setRowIndex(rowNum); X instancex = (X) uixCollection.getRowData(); if (!instancex.isAllPropertiesSet() instancex.isAnyPropertySet()) { FacesMessage message = Messages.getMessage( Constants.LOCALIZATION_RESOURCE, IncompleteRecord, null); message.setSeverity(FacesMessage.SEVERITY_ERROR); throw new ValidatorException(message); } } uixCollection.setRowIndex(oldRowIndex); } -- http://www.noooxml.org/ winmail.dat
Validating Multiple Components in DataTable
Hi, I have a tr:table component that is displaying rows from an ArrayLIst containing instances of class X. I would like to introduce a validator that checks that if information is entered for any property, then all properties must be populated for that row. ANy rows that have no data entered or all data entered are thus valid. At present I have the arrangement provided below, but I appear to be getting the instances of X from the original collection, rather than the table components local values. Thus when the view is first displayed, I can enter data in row 1 cell 1 and press next to invoke a POST back and the validation. Using the debugger, I find that the first iteration through the loop returns an instance of X, but without the posted back data (everything is null). I do not appear to be getting at the local converted value. Any help would be greatly appreciated. Thank you, Regards, Graeme. PS. I came across a related query located at http://mail-archives.apache.org/mod_mbox/myfaces-users/200608.mbox/%3c55 [EMAIL PROTECTED] I am trying to avoid binding as the user will be able to add and delete rows within my datatable, so I was hoping to keep things flexible. public class X { private String prop1; private String prop2; private String prop3; getters/setters...etc } class BackingBean { Collection X collection = new ArrayList X (); etc } tr:message for=validateRows / tr:table id=tblx value=#{bean.collection} binding=#{bean.coreTable} var=entry tr:column tr:inputText value=#{entry.prop1} / /tr:column tr:column tr:inputText value=#{entry.prop2} / /tr:column : : etc /tr:table tr:inputHidden id=validateRows value=dummy validator=#{bean.validateRows} / = Will only catch the first invlaid instance in the table - the validation message appears at the table level rather than per row. public void validateEntriesComplete(FacesContext facesContext, UIComponent uIComponent, Object object) throws ValidatorException { UIXCollection uixCollection = (UIXCollection) coreTable; int oldRowIndex = uixCollection.getRowIndex(); for (int rowNum = 0, numRows = uixCollection.getRowCount(); rowNum numRows; rowNum++) { uixCollection.setRowIndex(rowNum); X instancex = (X) uixCollection.getRowData(); if (!instancex.isAllPropertiesSet() instancex.isAnyPropertySet()) { FacesMessage message = Messages.getMessage( Constants.LOCALIZATION_RESOURCE, IncompleteRecord, null); message.setSeverity(FacesMessage.SEVERITY_ERROR); throw new ValidatorException(message); } } uixCollection.setRowIndex(oldRowIndex); }
Re: Validating Multiple Components in DataTable
Quick suggestion: tr:table id=tblx value=#{bean.collection} binding=#{bean.coreTable} var=entry tr:column tr:inputText value=#{entry.prop1} id=prop1 my:NotNullIfOtherNotNull others=prop2,prop3,prop4/ /tr:inputText /tr:column tr:column tr:inputText value=#{entry.prop2} id=prop2 as for the content of the cutsom my:NotNullIfOtherNotNull, i suggest you look at code of validateEqual in tomahawk, that check 2 component value are same. You can do similar thing with null. That way, non need to limit your check to the use of a UIData. En l'instant précis du 20/07/07 12:56, Graeme Steyn s'exprimait en ces termes: Hi, I have a tr:table component that is displaying rows from an ArrayLIst containing instances of class X. I would like to introduce a validator that checks that if information is entered for any property, then all properties must be populated for that row. ANy rows that have no data entered or all data entered are thus valid. At present I have the arrangement provided below, but I appear to be getting the instances of X from the original collection, rather than the table components local values. Thus when the view is first displayed, I can enter data in row 1 cell 1 and press next to invoke a POST back and the validation. Using the debugger, I find that the first iteration through the loop returns an instance of X, but without the posted back data (everything is null). I do not appear to be getting at the local converted value. Any help would be greatly appreciated. Thank you, Regards, Graeme. PS. I came across a related query located at http://mail-archives.apache.org/mod_mbox/myfaces-users/200608.mbox/[EMAIL PROTECTED] I am trying to avoid binding as the user will be able to add and delete rows within my datatable, so I was hoping to keep things flexible. public class X { private String prop1; private String prop2; private String prop3; getters/setters...etc } class BackingBean { Collection X collection = new ArrayList X (); etc } tr:message for=validateRows / tr:table id=tblx value=#{bean.collection} binding=#{bean.coreTable} var=entry tr:column tr:inputText value=#{entry.prop1} / /tr:column tr:column tr:inputText value=#{entry.prop2} / /tr:column : : etc /tr:table tr:inputHidden id=validateRows value=dummy validator=#{bean.validateRows} / = Will only catch the first invlaid instance in the table - the validation message appears at the table level rather than per row. public void validateEntriesComplete(FacesContext facesContext, UIComponent uIComponent, Object object) throws ValidatorException { UIXCollection uixCollection = (UIXCollection) coreTable; int oldRowIndex = uixCollection.getRowIndex(); for (int rowNum = 0, numRows = uixCollection.getRowCount(); rowNum numRows; rowNum++) { uixCollection.setRowIndex(rowNum); X instancex = (X) uixCollection.getRowData(); if (!instancex.isAllPropertiesSet() instancex.isAnyPropertySet()) { FacesMessage message = Messages.getMessage( Constants.LOCALIZATION_RESOURCE, IncompleteRecord, null); message.setSeverity(FacesMessage.SEVERITY_ERROR); throw new ValidatorException(message); } } uixCollection.setRowIndex(oldRowIndex); } -- http://www.noooxml.org/
[Trinidad] Validating Multiple Components in DataTable
Sorry, forgot to include Trinidad in the subject. From: Graeme Steyn Sent: Fri 20/07/2007 8:56 PM To: 'MyFaces Discussion' Subject: Validating Multiple Components in DataTable Hi, I have a tr:table component that is displaying rows from an ArrayLIst containing instances of class X. I would like to introduce a validator that checks that if information is entered for any property, then all properties must be populated for that row. ANy rows that have no data entered or all data entered are thus valid. At present I have the arrangement provided below, but I appear to be getting the instances of X from the original collection, rather than the table components local values. Thus when the view is first displayed, I can enter data in row 1 cell 1 and press next to invoke a POST back and the validation. Using the debugger, I find that the first iteration through the loop returns an instance of X, but without the posted back data (everything is null). I do not appear to be getting at the local converted value. Any help would be greatly appreciated. Thank you, Regards, Graeme. PS. I came across a related query located at http://mail-archives.apache.org/mod_mbox/myfaces-users/200608.mbox/[EMAIL PROTECTED] I am trying to avoid binding as the user will be able to add and delete rows within my datatable, so I was hoping to keep things flexible. public class X { private String prop1; private String prop2; private String prop3; getters/setters...etc } class BackingBean { Collection X collection = new ArrayList X (); etc } tr:message for=validateRows / tr:table id=tblx value=#{bean.collection} binding=#{bean.coreTable} var=entry tr:column tr:inputText value=#{entry.prop1} / /tr:column tr:column tr:inputText value=#{entry.prop2} / /tr:column : : etc /tr:table tr:inputHidden id=validateRows value=dummy validator=#{bean.validateRows} / = Will only catch the first invlaid instance in the table - the validation message appears at the table level rather than per row. public void validateEntriesComplete(FacesContext facesContext, UIComponent uIComponent, Object object) throws ValidatorException { UIXCollection uixCollection = (UIXCollection) coreTable; int oldRowIndex = uixCollection.getRowIndex(); for (int rowNum = 0, numRows = uixCollection.getRowCount(); rowNum numRows; rowNum++) { uixCollection.setRowIndex(rowNum); X instancex = (X) uixCollection.getRowData(); if (!instancex.isAllPropertiesSet() instancex.isAnyPropertySet()) { FacesMessage message = Messages.getMessage( Constants.LOCALIZATION_RESOURCE, IncompleteRecord, null); message.setSeverity(FacesMessage.SEVERITY_ERROR); throw new ValidatorException(message); } } uixCollection.setRowIndex(oldRowIndex); }
Re: Validating Multiple Components in DataTable
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-nameitem/managed-bean-name managed-bean-classwhatever.the.class.is.called/managed-bean-class managed-bean-scopenone/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.
Re: Validating Multiple Components in DataTable
On 8/2/06, David Van Stone [EMAIL PROTECTED] 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-nameitem/managed-bean-name managed-bean-classwhatever.the.class.is.called/managed-bean-class managed-bean-scopenone/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
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-nameitem/managed-bean-name managed-bean-classwhatever.the.class.is.called/managed-bean-class managed-bean-scopenone/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
On 8/2/06, David Van Stone [EMAIL PROTECTED] 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.
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
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 [EMAIL PROTECTED] 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
On 8/1/06, David Van Stone [EMAIL PROTECTED] 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.