I am trying to comment on status that is retrieved from the database. Whenever I am submitting the comment for specific status I am getting the exception.I have used <ui:repeat> to repeat the commandButtons. I don't know if the commandButton can be put inside <ui:repeat> or not. It would be really helpful if somebody could point out my mistake.Actually what is happening is that whenever I am trying to insert data into the database using '<h:inputText>' other commandButtons created due to using '<ui:repeat>' is possibly getting fired. I have inputText and commandButton inside the ui:repeat tag. So, some of inputText are supposed to be empty because I am selecting one inputText and clicking the corresponding commandButton
Your most immediate problem isn't JSF. You're violating the database constraint that the "comment" column cannot have a null value when you persist it out.
As far as ui:repeat goes, yes, commandButtons can be used in ui:repeats, but I strongly recommend that when you construct 2-dimensional (table-like) objects on a JSF view that you use a dataTable, not ui:repeat. Usually when you have a table full of rows with action buttons (and/or commandLinks), the entire table is encased within a single form, however, not form-per-row.
An IDE is no substitute for an Intelligent Developer.
Joined: Sep 20, 2012
I am having the exact same problem when I am using dataTable instead of ui:repeat. The problem is that multiple commandLink are possibly getting fired. If I am using dataTable ,suppose there is an inputText and a commandLink inside the datatable and it is repeated four times. So whenever I click the first commandLink associated with the inputText , I get exception four times,comment cannot be null. So I am assuming the commandLink is fired four times. But if I click on the fourth commandLink everything is working fine, the comment field is getting inserted in the database.
The "$" EL designator is for data access, not data reference. You'll almost never use it in JSF, since the "#" referencing designator is a superset of that function.
The update() method should not take a parameter. Instead, have the update() method invoke the DataModel object's "getCurrentRow()" method to obtain the model row, which can then be queried to get its statusId value (or, for that matter, any other value on the table row).
The more "program-like" your View Definition is, the more likely you're not doing it JSF-style. That means that you not only end up fighting JSF instead of being helped by it, but also you're violating the Model/View/Controller contract. Which means that people cannot tell automatically where things are done, they have to "treasure hunt" through multiple resources. Plus, the tighter coupling between Model and View makes for less flexible, less maintainable, less reusable components.
Joined: Sep 20, 2012
Could you please give me an example on how to use the DataModel for obtaining the statusId, Actually I am new to JSF so I don't how the dataModel works
A lot of people back a dataTable with a raw array or collection, but that's a convenience feature of limited utility. And, as far as it goes, I believe that current JSF implementations will simply construct an anonymous DataModel and wrap the raw data in it.
The reason for using the DataModel instead of a raw collection is that the DataModel maintains the context needed for the JSF UI to track rows and thus allow the underlying row collection model to be ui-independent. When you fire an action control on a row in a dataTable, the DataModel knows which row it was without you having to explicitly tell it. DataModels, BTW do not work on request-scope objects, because they track across multiple request/response cycles.
Using a DataModel is very easy. Simply construct a DataModel of your choosing, based on the wrapped data. For example, an ArrayList object would be wrapped by a ListDataModel. You can initialize like so:
Or, you can construct and wrap separately:
You then present the dataModel as the backing property for the dataTable object. The actual "dataList" object doesn't need its own set/get accessors, since only the wrapped data is actually referenced in the JSF View.
An action method can determine which row was selected when the action was fired using either the "getRowData()" or "getRowNumber()" DataModel methods. Actually, the "getRowData()" method is just a shorthand for "dataModel.getWrappedData().get(dataModel.getRowNumber())".
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com