0

我有一个具有 Init-Param 名称的 java portlet - javax.portlet.faces.defaultViewId.edit,其值为 /timesheetEntry.jsp

==timesheetEntry.jsp==

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<f:view>
    <c:choose>
        <c:when test="#{timesheetEntryPreferences.new}">
        <c:out value="New Timesheet Entry"></c:out>
    </c:when>
        <c:otherwise>
            <h:form id="timesheetEntryBeanForm">
                <h:panelGrid columns="3" border="1">
                    <f:facet name="header">
                        <h:outputText
                            value="Timesheet Entry (#{timesheetEntryPreferences.timesheetEntryId})" />
                    </f:facet>
                    <h:outputText value="#{timesheetEntryPreferences.new}"></h:outputText>
                    <h:outputText value="Timesheet Date:"></h:outputText>
                    <h:inputText id="timesheetDate"
                        value="#{timesheetEntryBean.timesheetDate}" required="true">
                        <f:converter converterId="javax.faces.DateTime" />
                    </h:inputText>
                    <h:message for="timesheetDate"></h:message>
                    <h:outputText value="Task Name:"></h:outputText>
                    <h:inputText id="taskName" value="#{timesheetEntryBean.taskName}"
                        required="true"></h:inputText>
                    <h:message for="taskName"></h:message>
                    <h:outputText value="Hours Worked:"></h:outputText>
                    <h:inputText id="hoursWorked"
                        value="#{timesheetEntryBean.hoursWorked}" required="true">
                        <f:validateLongRange minimum="1" maximum="24"></f:validateLongRange>
                    </h:inputText>
                    <h:message for="hoursWorked"></h:message>
                </h:panelGrid>
                <h:commandButton action="#{timesheetEntryController.saveEntry}"
                    value="Submit"></h:commandButton>
            </h:form>
        </c:otherwise>

    </c:choose>
</f:view>

==TimesheetEntryPreferences.java==

public class TimesheetEntryPreferences {
    private int timesheetEntryId;

    public int getTimesheetEntryId() {
        return timesheetEntryId;
    }

    public void setTimesheetEntryId(int timesheetEntryId) {
        this.timesheetEntryId = timesheetEntryId;
    }

    public TimesheetEntryPreferences() {
        try {
            timesheetEntryId = Integer.parseInt(PreferencesHelper
                    .getPreference("timesheetEntryId", "0"));
        } catch (NumberFormatException nfe) {
            System.err.println("Invalid Timesheet Entry has been set");

            timesheetEntryId = 0;
        }
    }

    public boolean isNew() {
        return timesheetEntryId == 0;
    }
}

注意:PreferencesHelper 类具有静态方法 getPreference(),它获取 portlet 首选项。

现在我的问题是,当呈现 portlet 时,timesheetEntryPreferences.new 必须为真,因此

<c:out value="New Timesheet Entry"></c:out>

必须显示正确吗?但它不会进入那个并且总是显示 c:otherwise 标记(即表单)。

请让我知道有什么问题?

4

0 回答 0