Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6067493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:36:49+00:00 2026-05-23T09:36:49+00:00

I have a POJO named FlashCard which has a field named links which is

  • 0

I have a POJO named “FlashCard” which has a field named “links” which is collection (set) of Link objects. When I submit a FORM to my Action all the POJO fields are populated with values from the form except the collection of “links”. I have no idea why this isn’t getting populated.

Any advice on how to resolve this problem or how to better troubleshoot it would be much appreciated.

Also, my POJO’s collection is a Set. Does it matter (or complicate things) that I’m using a Set and not a List?

I’m including a simplified version of my code below.

Here’s my POJO:

public class FlashCard  implements java.io.Serializable {

 private int flashCardId;
 private String question;
 private String answer;
 private Set<Link> links = new HashSet<Link>(0);

public FlashCard() {
}

public FlashCard(String question, String answer) {
    this.question = question;
    this.answer = answer;
}
public FlashCard(String question, String answer, Set<Link> links) {
   this.question = question;
   this.answer = answer;
   this.links = links;
}

public int getFlashCardId() {
    return this.flashCardId;
}

public void setFlashCardId(int flashCardId) {
    this.flashCardId = flashCardId;
}
public String getQuestion() {
    return this.question;
}

public void setQuestion(String question) {
    this.question = question;
}
public String getAnswer() {
    return this.answer;
}

public void setAnswer(String answer) {
    this.answer = answer;
}
public Set<Link> getLinks() {
    return this.links;
}

public void setLinks(Set<Link> links) {
    this.links = links;
}
}

Here’s the POJO for the Link object:

public class Link  implements java.io.Serializable {
 private int linkId;
 private String url;
 private Set<FlashCard> flashcards = new HashSet<FlashCard>(0);

public Link() {
}
public Link(String url) {
    this.url = url;
}

public Link(String url, Set<FlashCard> flashcards) {
   this.url = url;
   this.flashcards = flashcards;
}

public int getLinkId() {
    return this.linkId;
}

public void setLinkId(int linkId) {
    this.linkId = linkId;
}
public String getUrl() {
    return this.url;
}

public void setUrl(String url) {
    this.url = url;
}
public Set<FlashCard> getFlashcards() {
    return this.flashcards;
}

public void setFlashcards(Set<FlashCard> flashcards) {
    this.flashcards = flashcards;
}
}

Here’s the relevant part of the Action

public class FlashCardAction extends FlashCardsAppBaseAction implements ModelDriven<FlashCard>, Preparable, SessionAware {

static Logger logger = Logger.getLogger(FlashCardAction.class);

FlashCard flashCard = new FlashCard();

Map <String,Object> httpSession;

Session session;
FlashCardPersister fcPersister;

public Map<String, Object> getHttpSession() {
    return httpSession;
}

public FlashCard getFlashCard() {
    return this.flashCard;
}

public void setFlashCard(FlashCard flashCard) {
    this.flashCard = flashCard;
}

public void validate() {
    logger.debug("Entering validate()");

    if ( flashCard.getQuestion().length() == 0 ){
        addFieldError("flashCard.question", getText("error.flashcard.question"));
    }

    if ( flashCard.getAnswer().length() == 0 ) {
        addFieldError("flashCard.answer", getText("error.flashcard.answer"));
    }       
}

public String saveOrUpdate() {
    logger.debug("Entering saveOrUpdate()");

    // assume we'll fail
    boolean result = false;

    // are we creating a New Flash Card or Updating and existing one
    // for now, let's assume we are creating a New Flash Card
    boolean newFlashCard = true;

    // if this is an Update of an existing Flash CArd then we'll have a Flash Card Id other than 0 
    if (this.flashCard.getFlashCardId() != 0) {
        newFlashCard = false;
    }

    try {
        result = fcPersister.saveOrUpdateFlashCard(this.flashCard, session);

        // did we save a new FlashCard successfully?
        if (result == true && newFlashCard) {
            logger.debug("Flash Card created successfully");

            this.addActionMessage(getText("actionmessage.flashcard.created"));
        }
        // did we update an existing Flash Card successfully?
        else if (result == true && newFlashCard == false) {
            logger.debug("Flash Card updated successfully");

            this.addActionMessage(getText("actionmessage.flashcard.updated"));                  
        } 
        // such a failure
        else {
            logger.error("unable to create or update FlashCard");
            return "error";
        }
        return "success";

    } catch (Exception e) {
        logger.error("Exception in createFlashCard():", e);

        return "error";
    }
}


@Override
public FlashCard getModel() {
    return this.flashCard;
}
@Override
public void setSession(Map<String, Object> httpSession) {
    this.httpSession = httpSession;

}
@Override
public void prepare() throws Exception {
    logger.debug("Entering prepare()");

    // get a handle to a Hibernate session
    session = getHibernateSession();

    // get a handle to the FlashCard persistance utility class 
    fcPersister = new FlashCardPersister();
}

}

And lastly here’s the JSP

<%@page import="com.opensymphony.xwork2.ActionContext"%>
<%@page import="com.opensymphony.xwork2.ActionSupport"%>

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sjr" uri="/struts-jquery-richtext-tags"%>

<h3><s:text name="label.flashcard.title"/></h3>

<s:actionerror theme="jquery" />
<s:actionmessage theme="jquery"/>
<s:fielderror theme="jquery"/>

<s:form action="saveOrUpdate" method="post">
    <s:hidden name="flashCard.flashCardId" />
    <s:textfield name="flashCard.question" key="label.flashcard.question" size="66" />
    <sjr:tinymce 
        id="flashCard.answer" 
        name="flashCard.answer" 
        key="label.flashcard.answer"
        rows="20" 
        cols="50" 
        editorTheme="simple"
    />
    <s:textfield name="flashCard.links.url" key="label.flashcard.link" size="66" />
    <tr>
        <td>
            <s:submit label="label.flashcard.submit" align="center" theme="simple" />
        </td>
        <td>
            <s:submit key="label.flashcard.cancel" name="redirectAction:list" theme="simple"  />
        </td>
    </tr>
</s:form>

<%((ActionSupport)ActionContext.getContext().getActionInvocation().getAction()).clearErrorsAndMessages();%>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:36:50+00:00Added an answer on May 23, 2026 at 9:36 am

    First of all I don’t think you can use Set here, because Sets are unordered and you can’t get an item from a set by an index or key like List and Map. The only way is to iterate through the set and get the items.
    Second assuming you’re using a collection other than set, in:

    <s:textfield name="flashCard.links.url" key="label.flashcard.link" size="66"/>
    

    You try to set the value of the text field to url field of links which is a collection and doesn’t have such a field. So you need to get the specific item from the collection you’re editing and pass the value. Like:

    <s:textfield name="flashCard.links[0].url" key="label.flashcard.link" size="66"/>
    

    But since you can’t get the specific item you are editing I suggest you create a link field in your Action and set the updated link to it. Then you can perform a logic to relace the updated link with obsolete one in you flashcards. Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this scenario where you have transfer objects (POJO's with just getters/setters) which are
I have a POJO which has gender value of customers as Boolean. I haveto
I've got a simple pojo named Parent which contains a collection of object Child.
I'm a newbie to Hibernate. I have an Item POJO which contains a Set<String>
I have a simple request scoped entity / pojo which has a Enum and
I have a DSL Java object, i.e. a POJO which returns this in setters
Suppose I have a POJO User ,which I add some static method to do
I have a mapped POJO which I need to persist. In that POJO I
Using @XStreamOmitField in my POJO seems to have no effect whatsoever. the annotated field
I have a POJO named sport with properties sportID, sportName, number of players. Using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.