I'm working with JSF 2.2 with Primefaces 4.0 and I need to create a questionnaire with a dynamic amount of questions. This questions are radio type questions with 4 options each and I'm wondering the best (or easiest) way to do this. As far my research goes one way of doing this is using DynaForm from Primefaces extensions (The current way I'm trying to do it). Another possible way of doing this is by creating a List<Question> where
Public class Question{
//Something like this
private String question;
private List<String> options;
and calling it in a similar way as BalusC does it in his answer on dynamic adding radio and InputText in jsf. However, in my opinion, Datatable does not seems like a good solution for a SelectOneRadio type of input (Question plus all 4 options) As it does for inputText like on his original answer.
So which one is the best (easiest/simpler) way of doing this, and if it's like BalusC how should the valueChangeListener of the selectOneRadio be implemented so the String question and the selected answer of that question can be obtained for each question in the questionnaire, following (or Redefining if necessary) the provided Question class.
Related
I am currently trying to create a p:menubar which has one dynamically created submenu, but all the other submenus should be normally declared in the xhtml. Sadly I couldn't find any information on how to do so, as it seems that you always have to create a MenuModel and use that as the model for a complete p:menubar.
When just using two separate menubars it is possible to have multiple submenus open at the same time, which leads to them overlapping. And also the spacing is wrong then.
EDIT: I can't use JSTL, so the solution with c:forEach is not possible.
It has to be dynamic because the items are loaded from the database on each request.
EDIT 2: I could use JSTL, but I still don't really grasp how this could best be accomplished. I wan't to have a menubar with some submenus being normal static ones, but one submenu is built dynamically in the code (for every request, nothing with ajax). This dynamic submenu however has multiple child submenus which have their own children in turn, so in theory I would have to somehow iterate recursively over all children.
I am using Primefaces 8.0 and JSF 2.2
Thank you Kukeltje for answering my questions, I now ended up using c:forEach like in the linked post.
This is such a fundamental MVC question I have a feeling the answer is already on SO and I just can't find it. Please forgive me if it's a dupe.
I am reimplementing a big legacy JSP/servlet app in JSF2/Spring3/Facelets. I think in general we want to leave the presentation formatting to the .xhtml and use the backing bean to make the data suitable for display. This makes for a nice separation of concerns even though I believe both are part of the View. However, the legacy app has an attractive table that contains headings on the left and HTML formatted stuff on the right, like links that pop up a dialog (only one row has this). I decided to put all the content in objects that a datatable iterates through and it worked but I found myself putting sort of ugly HTML (for links and such) in the backing bean, and putting ugly conditions in the datatable (e.g. if this is row 0, then use this CSS class). This works but it doesn't feel right. I've very tightly coupled the backing bean to the presentation, but I can't think of a simple way to get around it. Does anyone have any guidelines around how to handle this? Thanks in advance.
This looks like a valid usecase for a JSF Component. A very good guidance is this book: http://jsfatwork.irian.at/book_de/custom_component.html (Free available online)
I use sorting in primefaces datatable and it's does not work with paginator. Where I made a mistake?
<p:column headerText="Year" sortBy="#{questionnaireListBean.getQuestionnaireData(questionnaire, 'YEAR')}">
#{questionnaireListBean.getQuestionnaireData(questionnaire, 'YEAR')}
</p:column>
And view scoped bean with init data in #PostConstruct method:
public String getQuestionnaireData(Questionnaire questionnaire, String column) {
return questionnairesData.get(questionnaire).get(column);
}
So the true title of your question is : "Sorting and pagination not working together in lazy loading datatable, primefaces", that's more of a precise description of your problem.
As for the issue, it apprears that you should expect the problem. In this link, the question was "Is there any datatable JSF component than can perform lazy load pagination, and filtering and sorting on server side. If I need to implement my own solution thanks to the teams that made client side sorting and filtering, they are useless", to which the answer came "No, there isn't. Because the component library cannot know what will be the persistence mechanism.". Of course that dated from 2010...
Taking a look into Primefaces user guide 3.5, it apprears that sorting/paginator/lazy loading can cohabit, but that's more elaborte then just adding sortBy to your columns.
In fact, checking page 144 of the guide, you can see that you need to :
have a LazyDataModel object in your bean ;
Override the load method of this object ;
Bind the value of your datatable to this model.
Doing this, you might have sorting along with lazy loading. Haven't tried it, but this seems to adress your issue.
Best of luck.
We are using JSF and I was looking for a component to implement a list that:
can be re-ordered (buttons/drag and drop/whatever)
elements can be added and deleted
elements can be edited
To be more explicit something like PrimeFaces OrderList where elements can be edited. inplace editing would be nice but not a requirement. Before implementing something that already exists I wanted to ask if I missed something and the component already exists.
You could take a look at Richfaces and IceFaces in addition to PrimeFaces. They all provide advanced components that might offer almost all the features you need.
I have another Richfaces question which may seem rather weird. I am developing a web-based application, using Richfaces for a front-end, that allows users to create templates for certain documents. For example: the user is presented with a rich:editor component, which, perhaps, has certain text already typed in, but it also has an input for a date, or specific text. The date can be entered in rich:calendar, the text can be entered in rich:inplaceInput, but the main idea is to be able to place those components INSIDE the rich:editor. I was trying to find an example where it's used and couldn't. So, my question is: is it even possible? Can you place RichFaces components (and, maybe, Seam components) into rich:editor? If not, is there a something similar out there that allows the user to do this? Can Seam do that? The reason I'm asking about Seam is because it appears to have some template-friendly logic and can work along with JSF and Richfaces.
Thanks for your help
Essentially your asking if you can add HTML elements to a textarea tag, and have them work. Unfortunately, no you can't.
What I've done in the past for such things has been to either weave boilerplate text, with inplaceInput, and free form text areas, or to simply provide the needed fields above/beside/below the editor.