use of org.komunumo.data.db.tables.records.FaqRecord in project komunumo-server by komunumo.
the class FaqDialog method createForm.
@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<FaqRecord> binder) {
final var question = new TextField("Question");
question.setRequiredIndicatorVisible(true);
question.setValueChangeMode(EAGER);
final var answer = new RichTextEditor();
answer.setRequiredIndicatorVisible(true);
formLayout.add(question, new CustomLabel("Answer"), answer);
binder.forField(question).withValidator(new StringLengthValidator("Please enter the question (max. 255 chars)", 1, 255)).bind(FaqRecord::getQuestion, FaqRecord::setQuestion);
binder.forField(answer.asHtml()).withValidator(new StringLengthValidator("Please enter the question (max. 255 chars)", 1, 10_000)).bind(FaqRecord::getAnswer, FaqRecord::setAnswer);
}
use of org.komunumo.data.db.tables.records.FaqRecord in project komunumo-server by komunumo.
the class FaqView method downloadEntries.
private void downloadEntries() {
final var resource = new StreamResource("faq.csv", () -> {
final var stringWriter = new StringWriter();
final var csvWriter = new CSVWriter(stringWriter);
csvWriter.writeNext(new String[] { "ID", "Question", "Answer" });
grid.getGenericDataView().getItems().map(faqRecord -> new String[] { faqRecord.getId().toString(), faqRecord.getQuestion(), faqRecord.getAnswer() }).forEach(csvWriter::writeNext);
return new ByteArrayInputStream(stringWriter.toString().getBytes(UTF_8));
});
final StreamRegistration registration = VaadinSession.getCurrent().getResourceRegistry().registerResource(resource);
UI.getCurrent().getPage().setLocation(registration.getResourceUri());
}
Aggregations