JSF How to dynamic add new row to datatable - jsf

I am currently doing an online test system, I want allow admin to create a test and add in few question. I was thinking using datatable add in coloumn with textarea? how can i add new row? or is there any other suggestion to implement add new more questions.

Since you mentioned "admin", I think you probably mean you want to allow only users with certain rights to be able to add new question.
There are indeed more than one way to do it. It really depends on your requirements.
One example is you can add a [New Question...] h:commandButton in your page for users to navigate to another page for data entry. You may want to check whether the current user has the rights to navigate to the data entry page in the backing bean.
Then in the data entry page you have all your h:inputText, h:inputTextArea etc for users to enter their data/question. In this data entry page you can use a [Save] h:commandButton to submit the entered values, and then insert the submitted data in your backing bean.
If you preferred to use the add new row to datatable approach, BalusC has a very good write up in his blogspot http://balusc.blogspot.com/2006/06/using-datatables.html

Related

Advice in edit form design for JSF

I have a complex Bean object that I want to update. Because it is too much complex, it can't be edited in the DataTable (inplace editing). Let's say that my page have this structure:
-> Input Form
-> DataTable for Listing
So I save the object using the Input Form and it appears inside the DataTable. This part is easy. Now, I need to edit the object inside the DataTable. Since the object is too much complex, it is not viable to edit in-place. So I must pick the row data and put it in a form to be able to sumbit it.
My problem is, I haven't come to a way of editing the data that I would like.
I've done it in multiple ways.
I've created a page only for the edit. I call the page passing the object's ID in the URL.
I copied the Input Form inside a Dialog. While this is great for editing, using a dialog had led me into problems (complex validations patterns, dialogs inside dialogs, etc).
I put the row data back into the Input Form and use Primefaces-Extensions spotlight component to ensure that the user will only work within the form. I've added a button to cancel edition also.
I didn't like any of them, although the third is the best of them, to me. But I'm also out of ideas of how to design data editing. Do you guys have some edit designs that you would like to share?
Thanks in advance.

passing value while using view scope in jsf

I have a table with few rows and one of the columns consists a button,now when i click on the edit button it takes me to a new JSF page.The details in the edit page are not getting populated.I am using view scope for my Managed Bean.I have gone through some of the posts and understood that view scope will be lost once the user leaves from that page.
I have gone through various other posts which suggested me to pass value to another bean and then get it into new jsf or by using f:viewparam. I wanted to know how i could achieve this functionality:
I want this flow to be achieved using view scoped managed bean JSF1-->on click of edit button in table-->View Scoped Managed Bean-->JSF2(details need to be populated but shows null values)
In the edit details page the value is shown null.
Could you let me know how I can achieve this functionality.Thanks.

Saving a view in JSF

Im having a question regarding retrieving the view state of a JSF page.
I have an application in which the user is able to search for persons in a
list and when the user press "show" button the same JSF page will be filled
with a list of the various persons.
Now when I choose one of the persons , another JSF page will show up with more
in-depth and detailed information about that person. Now in that page there is a
"cancel/abort" button displayed. What I want to accomplish is that when I press
that specific "cancel/abort" button the page should be redirected and navigate
back to the JSF page with the list as it was shown, so in some way the "view state"
should be stored (I assume only) but I dont know how it could be done...
I just wanted to check if anyone has been able to solve this kind of issue
in some manner.. ? (The JSF search page as mentioned above is declared as a viewscoped as
an additional information)
Thanks for all help..
You could make the bean #SessionScoped. That means that only one instance will be created by browser session, so when you get back you get the last state.
Of course, session scoped means that when you get back to the view even if it is not a "back" navigation, that info will still be there.

A component for dynamic multiple group entries

I have come across a situation where in a form a customer needs to enter address. A customer can have more than one address and further the address field contains more than one text fields,combo boxes etc. A customer can dynamically add more address and remove any address entry. Eg: there is one add button on form, which when clicked will display all address fields as a group. if the user wants to add more address then he/she can again click the add button, so that a new entry for the address fields will be displayed. Also each corresponding new entry will have a delete button so that if the user wants to delete the entry then he/she can. Finally all the address entries should get mapped to a backing bean.
eg: in backing bean one has " private List address" and Address class further has street,pincode,state,city etc.
Is there any jsf ui component that can help out in the above scenario. In short, a user can enter more than one address dynamically and then a list of address gets mapped to the corresponding entry in backing bean..
Please guys, contribute for this, i am sure that this kind of component will make development way simpler.
The component should have the facility of describing our own sub group items. here in the above case it was address, but in different cases one might require it to be something else like mobile number, websites,email address etc. The component should be fully customizable ie. from group entries to mapping it.
Please developers, develop this kind of component and tell me from where and how can i start to be a part of it. If we all come together we can develop this wonderful component which will make development lot easier.
Ok, here's a a few ideas for you based on your narrative:
Make a form of <h:inputText> components bound to properties (Strings?) on your Backing Bean.
Make up a Class which describes a User's Address - UserAddress()?
Create a <h:commandButton> whose actionListener calls a method on the same backing bean, which creates a UserAddress() object from the values of the Strings on the backing bean, and then add it to a List of type List<UserAddress> on your Backing Bean.
Most JSF components are geared up to accept Lists of objects, so you'll be in a good position to then use such a component to loop over your List<UserAddress> to put all the user addresses on the screen.
There are plenty of component libraries out there to choose from. One which immediately comes to mind from the currently popular PrimeFaces library is the editable DataTable.
Good luck.

Make editable rows in Datatable

I have list of rows displayed on the screen. These rows are iterated using the JSF datatable component. Now my requirement is to edit any particular row which user clicked.
Is there any way to make the fields editable while user clicking the row. Then user will fill the details and save it.
Any suggestions would be appreciated.
Creating editable data tables is very easy with jsf. Here is a good tutorial on this. But "making it editable when user clicks on it" is not supported out of the box. And this is where JSF shines, you just need to find for a JSF component (open source or commercial) compatible with your JSF (1.x or 2.x) version and start using it.
My first suggestion for you is to check and see if PrimeFaces provides this kind of component. Here is the component you are looking for.

Resources