Updated

A federal judge on Wednesday ruled that a Virginia man must remain in jail until trial on a charge that he tried to aid a terrorist group in Iraq, while his public defender argued that he was "entrapped" by undercover FBI agents over "bravado and talk."

Magistrate Judge Lawrence R. Leonard said Lionel Williams, 26, of Suffolk, Virginia, poses too much of a danger to society.

Williams allegedly swore allegiance to the Islamic State group in Iraq on Facebook. After undercover FBI agents approached him as people aligned with the group, Williams gave $250 to help them buy weapons, according to court documents.

Williams also owned an AK-47 assault rifle and allegedly told undercover agents that he wanted to commit a local "martyrdom operation" before his arrest in late December.

The judge said that even without his AK-47, which the FBI confiscated, Williams could pose a threat "as we've seen in Berlin and Nice" where terrorists struck pedestrians with trucks.

In trying to free Williams before trial, federal public defender Keith Kimball argued that prosecutors have a weak case. He said Williams' discussions about the Islamic State group were simply political speech and religious rhetoric that are constitutionally protected.

"There's a lot of noise here," Kimball added, "but when you get down to it, all we have here is a contribution of $250."

Kimball said the FBI entrapped Williams, who lacked an actual plan to hurt people.

"Before they got involved, was he ever a threat or danger to anybody?" Kimball said.

The detention hearing also offered a glimpse into the life of the unemployed man who lived with his grandmother in a rural part of Virginia.

Kimball said Williams worked as a cook at a country club until October and that he had strong support from his family, including his grandmother and an uncle who worked at a nearby shipyard. Nine people, including members of his mosque, showed up in court to support him. All of them declined to comment after the hearing.

Kimball added that a pre-trial report from the Federal Probation and Pretrial Services division recommended Williams be released as he awaits trial.

During the hearing, Williams answered the judge's questions with "yes sir" and smiled as he spoke to one of his public defenders. But a prosecutor detailed his erratic behavior with family members before his arrest and said Williams told FBI agents that he would have engaged in a shootout if they arrested him at home.

Prosecutor Joseph DePadilla told the judge that Williams showed little concern for his grandmother in the event a gunbattle were to actually occur.

According to DePadilla, family members said Williams walked around with his gun at night, acted erratically and closed himself off from his friends before his arrest.

DePadilla also rebuked the claim that the FBI somehow entrapped Williams.

"He had his own independent plan for martyrdom," DePadilla said. "This idea was on his own."