Jsf 向ArrayList添加的字符串未显示/未更新

Jsf 向ArrayList添加的字符串未显示/未更新,jsf,arraylist,Jsf,Arraylist,…所以我有了@ApplicationScoped Bean“应用程序”: Facelet如下所示: <!-- EMAILS --> <h3>Configured Emails</h3> <h:form> <h:inputText value="Email" var="email"/> <h:commandButton value="Add Email" action="#{Appl

…所以我有了@ApplicationScoped Bean“应用程序”:

Facelet如下所示:

 <!-- EMAILS -->
    <h3>Configured Emails</h3>
    <h:form>
        <h:inputText value="Email" var="email"/>
        <h:commandButton value="Add Email" action="#{Application.addEmail(email)}"/>
    </h:form>
    <h:form>
        <ui:repeat var="email" value="#{Application.emails}">
            <tr>
                <td>#{email}</td>

                <td>
                    <f:facet name="header">Action</f:facet>
                    <h:commandLink value="Delete" action="#{Application.rmEmail(email)}"/>
                </td>
            </tr>
            <br></br>
        </ui:repeat>
    </h:form>

配置电子邮件
#{email}
行动


…所以当我尝试添加“blabla@bla.com“,这是结果:

  • 有一个删除按钮显示,但不是字符串本身
  • 是否正确添加了字符串-并且JSF不会重新呈现视图
  • ..或者字符串添加不正确
请帮忙! 谢谢

我终于修好了

感谢用户@Kukeltje,他向我暗示了我做错的基本事情,感谢用户@Wietrol通过道德支持和“相信我”在聊天中激励我:)

解决方案:

..在Application.java中:

public List<Feed> sentNotifications = new ArrayList<>();

public List<String> emails = new ArrayList<>();

public List<String> words = new LinkedList<>(Arrays.asList("vuln", "banana", "pizza", "bonanza"));

public List<String> feeds = new LinkedList<>(
        Arrays.asList("http://www.kb.cert.org/vulfeed",
                "https://ics-cert.us-cert.gov/advisories/advisories.xml",
                "https://ics-cert.us-cert.gov/alerts/alerts.xml")
);

private String currentEmail;
private String currentFeed;
private String currentWord;
..和gui.xhtml:

 <!-- EMAILS -->
    <h3>Configured Emails</h3>
    <h:form>
        <h:inputText value="#{Application.currentEmail}" var="email"/>
        <h:commandButton value="Add Email" action="#{Application.addEmail}"/>
    </h:form>
    <h:form>
        <ui:repeat var="email" value="#{Application.emails}">
            <tr>
                <td>#{email}</td>

                <td>
                    <f:facet name="header">Action</f:facet>
                    <h:commandLink value="Delete" action="#{Application.rmEmail(email)}"/>
                </td>
            </tr>
            <br></br>
        </ui:repeat>
    </h:form>

配置电子邮件
#{email}
行动


请注意
action=“#{Application.addEmail}”
如何不使用参数,而是通过
value=“#{Application.currentmail}”
将参数传递给方法

如果你,读者,有同样的问题,请考虑以下几点:

  • bean中每个字段的getter/setter
  • 原始字段
  • “委托”基本字段的无参数方法,例如my addEmail方法
希望这个答案对有同样问题的ppl有用

您好,
Gewure

@Kukeltje我正在使用JSF2和Primefaces来做这件事,你为什么要把它编辑掉?因为你的问题中没有JSF-2或Primefaces的具体内容。它是简单的JSF。仅仅是你正在(某处)使用PrimeFaces这一事实并没有理由将其用作tag@Kukeltje好的,好的。。。你知道答案吗?:)我将为您提供一个链接,但请阅读一些好的教程。代码中非常基本的错误:谢谢@Kukeltje,。。。我现在明白了。我已经阅读了很多教程,但您可能会发现它并不总是很简单,尤其是如果JSF出于某种奇怪的原因不喜欢来自xhtml的参数化方法调用。不过,我学到了很多!
public List<Feed> sentNotifications = new ArrayList<>();

public List<String> emails = new ArrayList<>();

public List<String> words = new LinkedList<>(Arrays.asList("vuln", "banana", "pizza", "bonanza"));

public List<String> feeds = new LinkedList<>(
        Arrays.asList("http://www.kb.cert.org/vulfeed",
                "https://ics-cert.us-cert.gov/advisories/advisories.xml",
                "https://ics-cert.us-cert.gov/alerts/alerts.xml")
);

private String currentEmail;
private String currentFeed;
private String currentWord;
 public void addEmail() {
        emails.add(currentEmail);
 }
 <!-- EMAILS -->
    <h3>Configured Emails</h3>
    <h:form>
        <h:inputText value="#{Application.currentEmail}" var="email"/>
        <h:commandButton value="Add Email" action="#{Application.addEmail}"/>
    </h:form>
    <h:form>
        <ui:repeat var="email" value="#{Application.emails}">
            <tr>
                <td>#{email}</td>

                <td>
                    <f:facet name="header">Action</f:facet>
                    <h:commandLink value="Delete" action="#{Application.rmEmail(email)}"/>
                </td>
            </tr>
            <br></br>
        </ui:repeat>
    </h:form>