Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.2k views
in Technique[技术] by (71.8m points)

jsp - Struts2 Iterate a Map inside a Map with binding the property

I am trying to iterate a map inside a map object and bind the selected value to the property value. I could able to iterate but, the selected values are not binding with the action property value.

Here is the code:

ABCAction.java

public class ABCAction {
     private Category categoryOptions;
     private Map<String, Map<String, Category>> category;
     // with the values
}

Category.java

@Getter
@Setter
public class Category {
    private String id;
    private boolean applied;
}

category.jsp

    <s:hidden name="categoryOptions"/>
    <s:iterator value="%{category}" var="categoryElement">
    <s:set var="categoryKey" value="#categoryElement.key"/>
    <s:set var="categoryValue" value="#categoryElement.value"/>
    <div>
        <s:checkbox name="categoryOptions" id="categoryOption"/>
        <label for="categoryOption" class="d-inline" > <s:property value="%{categoryKey}" escapeHtml="false"/></label>
    </div>
    <div>
        <div>
            <div>
                <s:iterator value="%{categoryValue}" var="categoryMap" status="ctr">
                    <s:set var="subKey" value="#categoryMap.key"/>
                    <s:set var="subValue" value="#categoryMap.value"/>
                    <div class="staffNotes">
                        <div class="col-md-9 noPaddingContainer">
                            <s:radio  name="categoryOptions[%{#ctr.index}].applied" id="categoryOption" list="%{subKey}"/>
                            <s:hidden name = "categoryOptions[%{#ctr.index}].id" value="%{#subValue.id}"/>
                            
                            <s:hidden name = "categoryOptions[%{#ctr.index}].applied" value="%{#subValue.applied}"/>
                        </div>
                        
                    </div>
                   
                </s:iterator>
            </div>
        </div>
    </div>
    </s:iterator>

I am trying to map "categoryOptions" values to the "categoryOptions" in ABCAction class. After selecting the radio button, am just seeing an empty object.

Any help would be appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...