【问题标题】:Using stripes indexed properties to populate a map使用条带索引属性填充地图
【发布时间】:2016-04-30 23:59:00
【问题描述】:

希望您能帮我找到困扰我两天的问题的答案。

我正在构建一个用于进行剧院预订的应用程序,作为我一直在学习的 Java 课程的一部分。

我正在尝试使用条纹索引功能来使用条纹文本输入字段填充地图对象。

请看下面的代码。

JSP:

<c:set var="voorstellingen" value="${actionBean.theater.voorstellingen}" />
    <s:form beanclass="theater.action.TheaterActionBean" method="get">            
        <d:table name="${actionBean}">    
            <d:column title="naam">
                Naam:<s:text name="naam" title="Naam" size="30">Voer uw naam in</s:text>
            </d:column>
            <d:column title="telefoon" >    
                Telefoonnummer:<s:text name="telefoon" title="Telefoon"  size="30">Voer uw telefoonnummer in</s:text>
            </d:column>
        </d:table>
        <p></p>
        <table id="voorstelling">
            <thead>
                <tr>
                    <th>Voorstelling</th>
                    <th>Datum</th>
                    <th>Aantal vrij plaatsen</th>
                    <th>Aantal te reserveren</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${voorstellingen}" var="voorstelling" >
                <tr>
                    <td><c:out value="${voorstelling.naam}" /></td>  
                    <td><c:out value="${voorstelling.datum.time}" / </td>
                    <td><c:out value="${voorstelling.aantalVrij}" /></td>
                    <td><c:out value="${voorstelling.id}" /></td>
                    <td><s:text name="aantal[${voorstelling.id}]"></s:text>
                </tr>
                </c:forEach>
            </tbody>
        </table>
        <s:submit name="reserveer" value="Reserveren"/>
    </s:form>

上面的代码会生成一个表格,您可以在其中输入客户详细信息,然后是一个显示剧院表演的部分和一个文本框,您可以在其中输入要订购的门票数量。按“Reserveer”转发到 actionBean 中的事件处理程序。

以下是我的ActionBean中的相关代码

公共类 TheaterActionBean 扩展 BaseActionBean {

private static final String FORMVIEW = "/WEB-INF/jsp/theater.jsp";
private String naam = null;
private String telefoon=null;
//private int aantal = 0;
private int id = 0;
private Map<Integer,Integer> aantal = null;

public String message = null;

...... 

 public Resolution reserveer() throws TheaterException{
   message = message +  "Telefoon:" + telefoon + "Naam:" + naam + "Aantalreserveren:" + aantal;
   Theater theater=getContext().getCurrentTheater();
   if (aantal != null){
        Iterator it = aantal.entrySet().iterator();
        while (it.hasNext()){
            Map.Entry paar= (Map.Entry)it.next();
            message = message + "key " + paar.getKey() + "value" + paar.getValue();
        }
   }
   return new ForwardResolution(FORMVIEW);
}

......

public void setAantal(Map<Integer,Integer> aantal){
    this.aantal = aantal;
}

阅读其他一些来源,例如

http://www.coderanch.com/t/555416/oa/Stripes-Nested-Indexed-Properties-Selecthttps://stripesframework.atlassian.net/wiki/display/STRIPES/Indexed+Properties

我期待关注

<s:text name="aantal[${voorstelling.id}]"></s:text>

映射到我的 ActionBean 中名为 aantal 的 Map 属性,但 ik 一直返回空值。

我的目标是使用地图通过底层模型处理每个剧院表演的单独预订。

我需要做些什么才能让它与条纹一起使用?

亲切的问候,

乔斯

【问题讨论】:

    标签: java stripes indexed-properties


    【解决方案1】:

    虽然您的代码示例包含一些省略号,但可能是您没有为 aantal 实现 getter:

    public Map<Integer,Integer> getAantal(){
        return aantal;
    }
    

    对此并不完全确定,但我相信 Stripes 会自省 ActionBean 中索引属性的 getter 以获取用于绑定的泛型类型信息。

    【讨论】:

    • 乐于助人。我希望你会和我一样喜欢 Stripes。索引属性是 Stripes 更好的特性之一。
    猜你喜欢
    • 2017-05-07
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多