3

In my jsp page there have a table with nested list value, i want to send that table value to the container, The outer table value were sent but the inner table value not sent to the container, I am new here please let me know how to over come this situation,

My jsp

<script>
function rowAdded(rowElement) {
    //clear the imput fields for the row
    $(rowElement).find("input").val('');
    //may want to reset <select> options etc

    //in fact you may want to submit the form
    saveNeeded();
}
function rowRemoved(rowElement) {
    saveNeeded();
}
function saveNeeded() {
    $('#submit').css('color','red');
    $('#submit').css('font-weight','bold');
    if( $('#submit').val().indexOf('!') != 0 ) {
        $('#submit').val( '!' + $('#submit').val() );
    }
}
function beforeSubmit() {
    alert('script Working');
    return true;
}

$(document).ready( function() {
    var config = {
        rowClass : 'rule',
        addRowId : 'addRule',
        removeRowClass : 'removeRule',
        formId : 'ruleListForm',
        rowContainerId : 'ruleListContainer',
        indexedPropertyName : 'ruleList',
        indexedPropertyMemberNames : 'id,ruleName,parameterName,overwriteValue',
        rowAddedListener : rowAdded,
        rowRemovedListener : rowRemoved,
        beforeSubmit : beforeSubmit
    };
    new DynamicListHelper(config);
});
</script>
<html>
<form:form action="/update" method="post" id="ruleListForm"   modelAttribute="ruleListContainer">

            <table border="1">
                <thead>
                    <h3 align="center">Selected Rule</h3>
                    <tr>
                        <th data-field="id" width="25">ID&nbsp;&nbsp;&nbsp;  </th>
                        <th data-field="details" width="20">RuleName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>

                        <th data-field="parameter" width="240">Parameter&nbsp;&nbsp;</th>
                    </tr>
                </thead>
                <tbody id="ruleListContainer">
                    <c:forEach items="${List2}" var="as">

                        <tr class="rule">
                            <td><input type="hidden" name="ruleList[].id" value="${as.rule.id}" /> ${as.rule.id}</td>
                            <td><input type="hidden" name="ruleList[].ruleName" value="${as.rule.ruleName}" /> ${as.rule.ruleName}</td>
                            <td>&nbsp;<input id="one" class="datepicker" type="text" name="ruleList[].startDate" size="11" height="0.10"></td>
                            <td>&nbsp;<input id="two" class="datepicker" type="text" name="ruleList[].endDate" size="11" height="0.10"></td>
                            <td>
                                <table border="1">
                                    <c:forEach items="${as.ruleAssignmentParameter}" var="asss">
                                        <tr>
                                            <td><input type="hidden" name="ruleList[].parameterName"value="${asss.parameterName}" > ${asss.parameterName}</td>
                                            <td><input type="hidden" name="ruleList[].overwriteValue" value="${asss.overwriteValue}" /> ${asss.overwriteValue}</td>
                                        </tr>
                                    </c:forEach>
                                </table>
                            </td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
            <br>
             <input type="submit" value="Update">
        </form:form>
</html>         

Here is my model class

import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import com.demo.app.model.RuleAssignmentParameter;
public class RuleAssUI {
private int id;
private String ruleName;
public int getId() {
    return id;
}
public void setId(int id) {
    this.id = id;
}
public String getRuleName() {
    return ruleName;
}
public void setRuleName(String ruleName) {
    this.ruleName = ruleName;
}
private List<RuleAssignmentParameter> ruleAssignmentParameter = new LinkedList<RuleAssignmentParameter>();

public List<RuleAssignmentParameter> getRuleAssignmentParameter() {
    return ruleAssignmentParameter;
}
public void setRuleAssignmentParameter(List<RuleAssignmentParameter> ruleAssignmentParameter) {
    this.ruleAssignmentParameter = ruleAssignmentParameter;
}
public RuleAssUI(){     
}
public RuleAssUI(int id,String ruleName){
    this.id=id;
    this.ruleName=ruleName; 
}
}

My container where i store the list value

import java.util.LinkedList;
import java.util.List;
public class RuleListContainer {
 private List<RuleAssUI> ruleList = new LinkedList<RuleAssUI>();
    public RuleListContainer() {
    }

    public RuleListContainer(List<RuleAssUI> ruleList) {
        this.ruleList = ruleList;
    }

    public List<RuleAssUI> getRuleList() {
        return ruleList;
    }

    public void setRuleList(List<RuleAssUI> ruleList) {
        this.ruleList = ruleList;
    } 

Controller

@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(@ModelAttribute("SpringWeb") RuleListContainer ruleListContainer, HttpSession session, ModelMap model) {

    ruleListContainer.getRuleList().size();

    for (RuleAssUI rul1 : ruleListContainer.getRuleList()) {
        System.out.println("Id:   " + rul1.getId());
        System.out.println("RuleName:  " + rul1.getRuleName());
        for (RuleAssignmentParameter rul2 : rul1.getRuleAssignmentParameter()) {
            System.out.println("ParameterName: " + rul2.getParameterName());
            System.out.println("ParameterValue: " + rul2.getOverwriteValue());

        }
    }
    session.setAttribute("ruleListContainer", ruleListContainer);
    return "hello";
}

I am trying so many time but unable to fixed the issue, And browse also but did't get any proper help, so please help to do items

I NEED HELP PLEASE SOME BODY HELP ME...!

Thank you in advance

6
  • where comes from this list? <c:forEach items="${List2}" var="as"> Commented Apr 27, 2016 at 15:55
  • @cralfaro, There have one ruleassignment details class from this class i create that List2 Commented Apr 27, 2016 at 16:00
  • @cralfaro, i am able to populate the list and nested list value form database, which is hold in List2, But problem is that when i send this value to the controller it is not pass. Commented Apr 27, 2016 at 16:02
  • i response you in an answer will be easier to read there. Commented Apr 27, 2016 at 16:13
  • let me know if adding indexes fixed your problem Commented Apr 27, 2016 at 16:25

1 Answer 1

1

I think the problem is in your jsp file. You need to set the index of each list element.

<c:forEach items="${List2}" var="as" varStatus="vs">

                    <tr class="rule">
                        <td><input type="hidden" name="ruleList[${vs.index}].id" value="${as.rule.id}" /> ${as.rule.id}</td>
                        <td><input type="hidden" name="ruleList[${vs.index}].ruleName" value="${as.rule.ruleName}" /> ${as.rule.ruleName}</td>
                        <td>&nbsp;<input id="one" class="datepicker" type="text" name="ruleList[${vs.index}].startDate" size="11" height="0.10"></td>
                        <td>&nbsp;<input id="two" class="datepicker" type="text" name="ruleList[${vs.index}].endDate" size="11" height="0.10"></td>
                        <td>
                            <table border="1">
                                <c:forEach items="${as.ruleAssignmentParameter}" var="asss" varStatus="assignments">
                                    <tr>
                                        <td><input type="hidden" name="ruleList[${vs.index}].ruleAssignmentParameter[${assignments.index}].parameterName" value="${asss.parameterName}" > ${asss.parameterName}</td>
                                        <td><input type="hidden" name="ruleList[${vs.index}].ruleAssignmentParameter[${assignments.index}].overwriteValue" value="${asss.overwriteValue}" /> ${asss.overwriteValue}</td>
                                    </tr>
                                </c:forEach>
                            </table>
                        </td>
                    </tr>
                </c:forEach>

Also in your controller (POST method) you are trying to get the object identified by "SpringWeb" but should be "ruleListContainer", same name you have in your form tag

The problem was you had a list into RuleAssUI and you was not accesing correctly, you need 2 loops and indexes, one for each list.

Here is the key:

ruleList[${vs.index}].ruleAssignmentParameter[${assignments.index}].parameterName
Sign up to request clarification or add additional context in comments.

15 Comments

@ cralfaro, Still is not working, the parameterName & overwriteValue not pass to the container actuly
@ cralfaro, after adding indexes nothing is happen, still the value is not pass to the container, what i do sir.? i am trying thousand of time but still unable to fi the problem
@Emad also be sure the name of the object you are using in your form tag is the same in your POST method with the ModelAttribute
@ cralfaro, yes it is same
The id and ruleName are pass to the container, i can see the list value, by setting debugging point in update servlet, but the parameterName and Overwritevalue were null,
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.