【问题标题】:Disable a row based on condition from database in Liferay Search Container根据 Liferay 搜索容器中数据库的条件禁用一行
【发布时间】:2013-05-07 03:42:04
【问题描述】:

我必须禁用我使用 Liferay 搜索容器从数据库中检索到的行。我在数据库中存储了某些条件。

我希望实现的是:

  1. 我正在显示需要标记出勤率的学生列表。
  2. 有时学生可能会提前请假,在这种情况下,出勤率会在数据库中预先标记。
  3. 所以当显示考勤表时,我想通过禁用包含已标记出勤的学生数据的行来禁用考勤。

我想要做的是,如果出勤是预先标记的,则在表格上显示预先标记出勤的行,并且不允许用户为该学生标记出勤,即禁用该行。

我怎样才能做到这一点?

编辑: 代码sn-p

    Mark Attendance for Today:   
    <%=new java.util.Date()%>

    <portlet:actionURL name="updateAtt" var="updateAttURL" />

        <aui:form name="updateAtt" action="<%=updateAttURL.toString() %>" method="post" >

            Choose Date to mark Attendance:
            <liferay-ui:input-date formName="attendanceDate" yearRangeStart="<%=year %>" yearRangeEnd="<%=year %>"
                    yearValue="<%=year %>" monthValue="<%=month %>" dayValue="<%=day %>" 
                    dayParam="datt" monthParam="matt" yearParam="yatt" />

            <portlet:renderURL  var="viewstudentDataURL"/>

            <liferay-ui:search-container delta="20" emptyResultsMessage="No Results Found">

                <liferay-ui:search-container-results total="<%= studentAttendanceDetails .size() %>"
                        results="<%= ListUtil.subList(studentAttendanceDetails , searchContainer.getStart(), searchContainer.getEnd()) %>" />
                <liferay-ui:search-container-row modelVar="search"
                    className="com.corpserver.mis.portal.model.Student">   

                    <%
                    String LImageId = String.valueOf(search.getFileEntryId());
                    long ImageId = Long.valueOf(LImageId);
                    DLFileEntry image = DLFileEntryLocalServiceUtil .getFileEntry(ImageId ); 
                    String imageURL = "/documents/" + image.getGroupId() + "/" + image.getFolderId() + "/" + image.getTitle()+"/"+image.getUuid();
                    %>

                    <liferay-ui:search-container-column-text name="student Photo" href = "">
                        <img src="<%=imageURL%>" height="50" width="50"/> 
                    </liferay-ui:search-container-column-text>
                    <!-- Code to display student Image -->

                    <%
                    String eol = System.getProperty("line.separator");
                    %>

                    <liferay-ui:search-container-column-text name='student Name' value='<%=String.valueOf(search.getstudentFname()) +  String.valueOf(search.getstudentLname()) + "<br>" + String.valueOf(search.getstudentTitle()) %>'  href="" >

                    </liferay-ui:search-container-column-text>

                    <liferay-ui:search-container-column-text name="Attendance Status">                       
                        <label>Present</label><input type = "radio" name ='updateattendance<%=String.valueOf(search.getstudentId())%>' value = "Present" />
                        <label>Absent</label><input type = "radio" name= 'updateattendance<%=String.valueOf(search.getstudentId())%>' value = "Absent"/>
                    </liferay-ui:search-container-column-text>

                </liferay-ui:search-container-row>

                <liferay-ui:search-iterator searchContainer="<%=searchContainer %>" paginate="<%=true %>" />
            </liferay-ui:search-container>

            <input type = "submit" value = "Update"/>
        </aui:form>
</body>
</html>

【问题讨论】:

  • 嗨,您可以禁用标记出勤的输入控件吗?如果是,给我们搜索容器行的jsp代码
  • @yannicuLar:我已经用我使用的代码 sn-p 更新了问题..
  • @SeeyaK 与问题无关: 我在您的代码中看到了&lt;/body&gt;&lt;/html&gt; 标签。在您的 portlet 的 jsp 中,这些 html 标记不应出现,因为 portlet 仅用于生成片段,并且这些标记由门户自动添加。在某些浏览器中,当您使用 javascript 时,您可能会遇到奇怪的行为,因为会有多个 &lt;/body&gt;&lt;/html&gt; 标签,它们不是格式良好的 html 页面。所以简而言之,我们不应该在portlet的jsp中包含&lt;html&gt;&lt;body&gt;&lt;head&gt;&lt;title&gt;等标签。谢谢
  • @Prakash K : 谢谢你.. 会记下这一点并使用你的建议。
  • 显然,您必须在“出勤状态”列中注入一些 java 代码,并通过例如使用 disabled 属性来操作 字段。问题是如何获得“标记出勤”值(它是“com.corpserver.mis.portal.model.Student”类的“搜索”实例的属性吗??)

标签: liferay liferay-6 disabled-input javascript


【解决方案1】:

您可以使用条件语句只显示标签而不显示输入控件或禁用输入控件,如下所示:

<%
String LImageId = String.valueOf(search.getFileEntryId());
long ImageId = Long.valueOf(LImageId);
DLFileEntry image = DLFileEntryLocalServiceUtil .getFileEntry(ImageId ); 
String imageURL = "/documents/" + image.getGroupId() + "/" + image.getFolderId() + "/" + image.getTitle()+"/"+image.getUuid();

// you can define a flag for the pre-marked attendance
boolean preMarkFlag = isStudentPreMarked(); // have value true (student is premarked) or false (if the student is not pre-maked)    
%>

<liferay-ui:search-container-column-text name="Attendance Status">
    <label>Present</label>
    <input type = "radio"
            name ='updateattendance<%=String.valueOf(search.getstudentId())%>'
            value = "Present"
            <%= preMarkFlag ? "disabled" : "" %> />

    <label>Absent</label>
    <input type = "radio"
            name ='updateattendance<%=String.valueOf(search.getstudentId())%>'
            value = "Absent"
            <%= preMarkFlag ? "disabled" : "" %> />
</liferay-ui:search-container-column-text>

或者另一种方法是只显示一个标签而不显示输入单选按钮

<liferay-ui:search-container-column-text name="Attendance Status">
    <%
    // I am assuming if preMarkFlag is true then the student is absent
    // as mentioned in your question
    if (preMarkFlag) {
    %>

    <label>Absent</label>

    <%
    } else {
    %>

    <label>Present</label>
    <input type = "radio"
            name ='updateattendance<%=String.valueOf(search.getstudentId())%>'
            value = "Present"
            <%= preMarkFlag ? "disabled" : "" %> />

    <label>Absent</label>
    <input type = "radio"
            name ='updateattendance<%=String.valueOf(search.getstudentId())%>'
            value = "Absent"
            <%= preMarkFlag ? "disabled" : "" %> />

    <%
    }
    %>
</liferay-ui:search-container-column-text>        

【讨论】:

  • 我应该使用自定义查询来检查学生的出勤情况吗?
  • @SeeyaK 我假设您已经知道特定学生是如何预先标记的,因为您没有在问题中提供有关如何存储出勤率以及如何存储预先标记的任何详细信息出席。因此,如果没有这些信息,将很难提出建议。但我认为您肯定需要一种方法来检查它,如果内部实现不是直接的或无法通过 dynamicQuery 完成,则内部实现可以是自定义查询。
  • 我同意 Prakash,您的控制器类中应该有一个方法,该方法将 com.corpserver.mis.portal.model.Student 作为参数,并返回一个布尔值或整数。在您的 jsp 中,在列代码中,调用此函数(提供“搜索”变量,正如您的 modelVar attr 声明的那样)并使用结果隐藏或禁用单选/复选框控件。您的问题是如何禁用这些控件,我认为 Prakash 的回答涵盖了这一点
  • @Prakash K:会有一张申请休假的表格。如果准许请假,则更新出勤表并且学生在请假期间被标记为缺席。前任。如果 A 在接下来的 5 天请假,则提前标记为接下来的 5 天缺勤。每天签到时,在接下来的 5 天内,A 将显示为已被标记为缺勤,并且他的考勤不能更改。我希望这能回答您的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-26
  • 1970-01-01
  • 1970-01-01
  • 2021-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多