Announcement Announcement Module
Collapse
No announcement yet.
Jakarta input taglibraries and spring model object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jakarta input taglibraries and spring model object

    I'm attempting to use jakarta input taglibraries with Spring framework. The problem I am stuck with is the access to Spring model object inside java scriptlet. For example the input select tag requires the options list as Hashtable:
    Code:
    <input:select  name="inputTagProducts" options="<%= sampleData.getInputProducts%>"/>
    I tried to declare the requestContextAttribute
    Code:
    <property name="requestContextAttribute"><value>context</value></property>
    in view resolver and then attempted to access it in scriptlet as
    Code:
    <%=((SampleData)context.getModelObject("sampleData")).getInputProducts()%>
    but it seems somewhat incorrect approach and it did not work either. Could anyone offer any working solution or ideas? Thank you.

  • #2
    jsp:useBean

    Asking myself, answering myself. Just added this line of code to jsp
    Code:
    <jsp:useBean id="sampleData" class="sd.ms.bus.dto.SampleDTO"/>
    and
    Code:
    <input:select  bean="sampleData" name="inputTagProducts" options="<%=sampleData.getInputTagProducts()%>"/>
    works as wanted.

    Comment


    • #3
      I'm having the same problem

      Hi I just don't know how to fit a Hashtable into the
      jakarta input taglib

      Can you show how you did, I need more code, like where do you
      put the
      <property name="requestContextAttribute"><value>context</value></property>

      and what do you put in the servlet?

      I can show you a listing of mine, if you can telle me what's the error.

      my code in handleRequest
      while (iter.hasNext()) {
      Voie uneVoie = (Voie) iter.next();
      listVoieCir.put(Integer.toString(uneVoie.getId()), uneVoie.getNomVoie());

      }


      Map myModel = new HashMap();
      myModel.put("now", now);
      myModel.put("voies", listVoieCir);


      return new ModelAndView("listBox", "model", myModel);

      and my jsp

      <%@ include file="/WEB-INF/jsp/include.jsp" %>
      <%@ taglib uri="/WEB-INF/taglibs-input.tld" prefix="input" %>
      <jsp:useBean id="voies" class="java.util.Hashtable"/>
      <html>
      <head><title><fmt:message key="title"/></title></head>
      <body>
      <h1><fmt:message key="heading"/></h1>

      <p><fmt:message key="greeting"/> <c:out value="${model.now}"/>
      </p>

      <h3>Liste des voies</h3>



      <input:select name="listVoies" options="<%=voies%>" />-->




      <br>
      </body>
      </html>

      Comment


      • #4
        I was a bit wrong in my previous post as I did not define the scope of the bean which should be in my case request and finally I did not use the RequestContext attribute.

        This is my DTO:
        Code:
        package fn.sc.dto;
        
        import java.util.Hashtable;
        
        public class QuestionDTO {
        	private Hashtable qTypes;
        
        	public Hashtable getQTypes() {
        		return qTypes;
        	}
        
        	public void setQTypes(Hashtable types) {
        		qTypes = types;
        	}
        }
        Here I am adding the dto to view
        Code:
        return new ModelAndView("simpleAdminQuestionForm", "questionDTO", questionDTO);
        Here I am using the bean in test.jsp
        Code:
        <%@ taglib uri="http://jakarta.apache.org/taglibs/input-1.0" prefix="input" %>
        <%@ taglib prefix="spring" uri="/spring" %>
        <jsp:useBean id="questionDTO" class="fn.sc.dto.QuestionDTO" scope="request"></jsp:useBean>
        <input:form>
        	<table>
        		<tr>
        			<td><spring:message code="label.question"/></td>
        			<td><input:textarea name="question"/></td>
        		</tr>
        		<tr>
        			<td><spring:message code="label.answerType"/></td>
        			<td><input:select name="answerType" bean="questionDTO" options="<%=questionDTO.getQTypes()%>"></input:select> </td>
        		</tr>
        	</table>
        </input:form>

        Comment


        • #5
          It's working great

          Hi thank you very much

          it's working great.

          Fanfaron

          Comment

          Working...
          X