struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Albert Kao <albertk...@yahoo.ca>
Subject replace Java scriptlets in JSP page
Date Mon, 29 Dec 2014 23:17:50 GMT
The following Java scriptlet code in a Struts jsp is working fine. 
However, is it possible to change the jsp code so as to remove all the Java scriptlet codes?


The .jsp code is like this:<%
  HttpSession httpSession = request.getSession(true);
  MyClient myClient = (MyClient)httpSession.getAttribute(MyConst.MY_CLIENT);
%>
<logic:iterate id="pOwnersID" name="<%=MyConst.MY_CLIENT%>"
  property="pOwners" length="<%=MyConst.MY_OWNER_MAX%>" indexId="index">
  <%
    pageContext.setAttribute("requiredIndex", myClient.getRequiredIndex(index), PageContext.PAGE_SCOPE);
  %>
  <h2>
    <bean:message key="common.owner.label" /> <%= myClient.getNumber(index) %>
  </h2>

  <div>
    <logic:lessThan name="requiredIndex" value="1">
      <label for='<%="lastName" + index%>' class="required">
        <bean:message key="common.lastName.label" />
        <jsp:include page="/pages/common/required.jsp" flush="true" />
      </label>
    </logic:lessThan>
    <logic:greaterEqual name="requiredIndex" value="1">
      <label for="<%="lastName" + index%>">
        <bean:message key="common.lastName.label" />
      </label>
    </logic:greaterEqual>
    <html:text styleClass="form-control"
      styleId='<%="lastName" + index%>' name="inputForm"
      property='<%="myForm.pOwners["+index+"].lastName"%>' size="62"
      maxlength="30" />
  </div>
</logic:iterate>


The java code is like this:public class Owner implements java.io.Serializable {
    private static final long serialVersionUID = 7920764268572909394L;
    private String lastName;
    private String ownershipCode;
    //...
    
    public Owner() {
    }

    // getter and setters
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    //...
    public Integer getRequiredIndex(Integer index) {
        Integer requiredIndex = index;
        if (OWNRSHP_PARTNER.equals(ownershipCode)) {
            requiredIndex = requiredIndex - 1;
        }
        return requiredIndex;    
    }

    public String getNumber(Integer index) {
        String number = Integer.toString(index + 1);
        if (OWNRSHP_SOLE.equals(ownershipCode)) {
            number = "";
        } 
        return number;    
    }
}


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message