Row Checker:
If you want to select multiple rows then you can go with row checker
Use the below code in jsp:
<aui:form method="post" name="fm">
<aui:input name="studentIds" type="hidden" />
<liferay-ui:search-container delta="5"
iteratorURL="<%=iteratorURL%>"
rowChecker="<%=new RowChecker(renderResponse)%>">
<liferay-ui:search-container-results
results="<%=ListUtil.subList(courseStudents, searchContainer.getStart(), searchContainer.getEnd())%>"
total="<%=courseStudents.size()%>" />
<liferay-ui:search-container-row
className="com.ekhub.servicelayer.model.CourseStudent"
modelVar="courseStudent" keyProperty="uid">
<liferay-ui:search-container-column-text property="uid"
name="Student Id" />
<liferay-ui:search-container-column-text name="Assign"
href="<%=studentAssignURL.toString()%>" value="Assign" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator searchContainer="<%=searchContainer%>" />
</liferay-ui:search-container>
<aui:button value="Assign Selected Students"
onClick='<%= renderResponse.getNamespace() + "assignStudents();" %>' />
</aui:form>
Script in Jsp page
<aui:script>
Liferay.provide(
window,
'<portlet:namespace />assignStudents',
function() {
var checkBoxValue = Liferay.Util.listCheckedExcept(document.<portlet:namespace />fm, "<portlet:namespace />allRowIds");
if(checkBoxValue==""||checkBoxValue==null){
alert('<%= UnicodeLanguageUtil.get(pageContext, "Please select atleast one student to assign") %>');
return false;
}
if (confirm('<%= UnicodeLanguageUtil.get(pageContext, "Are you sure you want to assign the selected students? ") %>')) {
document.<portlet:namespace />fm.<portlet:namespace />studentIds.value=checkBoxValue;
submitForm(document.<portlet:namespace />fm, "<%=studentAssignURL.toString()%>");
}
},
['liferay-util-list-fields']
);
</aui:script>
Then in java method write the below code
public void assignStudentAction(ActionRequest request,
ActionResponse response) throws IOException, PortletException,
SystemException, PortalException {
StudentAssessmentMap studentAssessmentMap = new StudentAssessmentMapImpl();
long assessmentId = ParamUtil.getLong(request, "assessmentId");
long[] studentIds = StringUtil.split(
ParamUtil.getString(request, "studentIds"), 0L);
for (int i = 0; i < studentIds.length; i++)
{
studentAssessmentMap.setAssessmentId(assessmentId);
studentAssessmentMap.setStudentId(studentIds[i]);
StudentAssessmentMapLocalServiceUtil.addStudentAssessmentMap(studentAssessmentMap);
}
}
If you want to select multiple rows then you can go with row checker
Use the below code in jsp:
<aui:form method="post" name="fm">
<aui:input name="studentIds" type="hidden" />
<liferay-ui:search-container delta="5"
iteratorURL="<%=iteratorURL%>"
rowChecker="<%=new RowChecker(renderResponse)%>">
<liferay-ui:search-container-results
results="<%=ListUtil.subList(courseStudents, searchContainer.getStart(), searchContainer.getEnd())%>"
total="<%=courseStudents.size()%>" />
<liferay-ui:search-container-row
className="com.ekhub.servicelayer.model.CourseStudent"
modelVar="courseStudent" keyProperty="uid">
<liferay-ui:search-container-column-text property="uid"
name="Student Id" />
<liferay-ui:search-container-column-text name="Assign"
href="<%=studentAssignURL.toString()%>" value="Assign" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator searchContainer="<%=searchContainer%>" />
</liferay-ui:search-container>
<aui:button value="Assign Selected Students"
onClick='<%= renderResponse.getNamespace() + "assignStudents();" %>' />
</aui:form>
Script in Jsp page
<aui:script>
Liferay.provide(
window,
'<portlet:namespace />assignStudents',
function() {
var checkBoxValue = Liferay.Util.listCheckedExcept(document.<portlet:namespace />fm, "<portlet:namespace />allRowIds");
if(checkBoxValue==""||checkBoxValue==null){
alert('<%= UnicodeLanguageUtil.get(pageContext, "Please select atleast one student to assign") %>');
return false;
}
if (confirm('<%= UnicodeLanguageUtil.get(pageContext, "Are you sure you want to assign the selected students? ") %>')) {
document.<portlet:namespace />fm.<portlet:namespace />studentIds.value=checkBoxValue;
submitForm(document.<portlet:namespace />fm, "<%=studentAssignURL.toString()%>");
}
},
['liferay-util-list-fields']
);
</aui:script>
Then in java method write the below code
public void assignStudentAction(ActionRequest request,
ActionResponse response) throws IOException, PortletException,
SystemException, PortalException {
StudentAssessmentMap studentAssessmentMap = new StudentAssessmentMapImpl();
long assessmentId = ParamUtil.getLong(request, "assessmentId");
long[] studentIds = StringUtil.split(
ParamUtil.getString(request, "studentIds"), 0L);
for (int i = 0; i < studentIds.length; i++)
{
studentAssessmentMap.setAssessmentId(assessmentId);
studentAssessmentMap.setStudentId(studentIds[i]);
StudentAssessmentMapLocalServiceUtil.addStudentAssessmentMap(studentAssessmentMap);
}
}
0 comments:
Post a Comment