Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form field labelKey displaying as ?????? #19

Open
wseemann opened this issue Oct 23, 2021 · 0 comments
Open

Form field labelKey displaying as ?????? #19

wseemann opened this issue Oct 23, 2021 · 0 comments

Comments

@wseemann
Copy link

Hello, I followed the example in your getting started section to create my own form. I made an event class with the following fields:

  package com.wseemann.fisticuffs.models;
  
  public class Event {
      private Integer id;
      private String eventName;
      private Integer eventLength;
    //....

I then created Event.properties:

event-id=Event ID
event-eventName=Event Name
event-eventLength=Event Length (in days)

However when I load my page the form labels are all shown as "??????". Any ideas what I'm doing wrong?

Finally, my JSP page:

<%@page contentType="text/html; charset=UTF-8" %>
<%@page pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<fmt:bundle basename="com.wseemann.fisticuffs.models.Event">
<html>
<body>
<h1>Formio Getting Started</h1>
 
<c:set var="fields" value="${eventForm.fields}"/>
<form action="<c:url value="/"/>" method="post">
   <div>
       <label><fmt:message key="${fields.eventName.labelKey}"/>
           <input type="text" name="${fields.eventName.name}" value="${fields.eventName.value}"/>
       </label>
   </div>
   <div>
       <label><fmt:message key="${fields.eventLength.labelKey}"/>
           <input type="text" name="${fields.eventLength.name}" value="${fields.eventLength.value}"/>
       </label>
   </div>
   <button name="submit" type="submit">Submit</button>
</form>
</body>
</html>
</fmt:bundle>

And controller:

@WebServlet("/")
public class PersonController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    private static final FormMapping<Event> eventForm =
            Forms.automatic(Event.class, "event").build();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");

        Event event = new Event();
        FormData<Event> formData = new FormData<Event>(event, ValidationResult.empty);
        FormMapping<Event> filledForm = eventForm.fill(formData);

        request.setAttribute("eventForm", filledForm);
        request.getRequestDispatcher("/WEB-INF/jsp/index.jsp").forward(request, response);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant