Setting a jstl bean varable?

i have a java bean like this:
          <jsp:useBean id="empskill" class="com.Database.EmployeeSkill" scope="page">
               <jsp:setProperty name="empskill" property="ename" value="<%= session.getAttribute( "ename" ) %>"/>
               <jsp:setProperty name="empskill" property="skill.skillname" value="<%= session.getAttribute( "sname" ) %>"/>
          <jsp:setProperty name="empskill" property="yearsexperience" value="<%= session.getAttribute( "yexp" ) %>"/>
          </jsp:useBean>and i have java set method in employeeskill :
   public void setSkill(Skill skill) {this.skill = skill; }and i have a java set method in skill :
    public void setSkillname(String skillname) { this.skillname = skillname; }why is it that i cant set the parameter like this, i get this error:
org.apache.jasper.JasperException: An exception occurred processing JSP page /main.jsp at line 277
274:      
275:           <jsp:useBean id="empskill" class="com.Database.EmployeeSkill" scope="page">
276:                <jsp:setProperty name="empskill" property="ename" value="<%= session.getAttribute( "ename" ) %>"/>
277:                <jsp:setProperty name="empskill" property="skill.skillname" value="<%= session.getAttribute( "sname" ) %>"/>
278:           <jsp:setProperty name="empskill" property="yearsexperience" value="<%= session.getAttribute( "yexp" ) %>"/>
279:           </jsp:useBean>
280:           
     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:414)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
org.apache.jasper.JasperException: org.apache.jasper.JasperException: Cannot find any information on property 'skill.skillname' in a bean of type 'com.Database.EmployeeSkill'
     org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(JspRuntimeLibrary.java:666)
     org.apache.jsp.main_jsp._jspService(main_jsp.java:353)
     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:390)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
org.apache.jasper.JasperException: Cannot find any information on property 'skill.skillname' in a bean of type 'com.Database.EmployeeSkill'
     org.apache.jasper.runtime.JspRuntimeLibrary.getWriteMethod(JspRuntimeLibrary.java:794)
     org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(JspRuntimeLibrary.java:663)
     org.apache.jsp.main_jsp._jspService(main_jsp.java:353)
     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:390)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

This is a tough looking design. Here is what I would ask myself, if I were you:
Is EmployeeSkill A Skill, or does EmployeeSkill Have A Skill?
Your design says: EmployeeSkill Has A Skill, but it seems to me that EmployeeSkill Is A Skill.
So instead of having EmployeeSkill contain an object of type Skill, maybe EmployeeSkill should extend Skill:
class Skill {
    private ResultSet rs ;//the result set to hold the data from the database
    private Connection con;//holds the connection to the database
    private Statement stmt;//used to run SQL       
    private int skillid;
    private String skillname, description;
    SkillType skilltype = new SkillType();
    public void setSkillid(int skillid) { this.skillid = skillid; }
    public void setSkillname(String skillname) { this.skillname = skillname; }
    public void setDescription(String description) { this.description = description; }
    public void setSkilltype(SkillType skilltype) { this.skilltype = skilltype; }
    public int getSkillid() { return this.skillid; }
    public String getSkillname() { return this.skillname; }
    public String getSkillDescription() { return this.description; }
    public SkillType getSkilltype() { return this.skilltype; }
} //end Skill class
public class EmployeeSkill extends Skill {
    private ResultSet rs ;//the result set to hold the data from the database
    private Connection con;//holds the connection to the database
    private Statement stmt;//used to run SQL       
    private String skilllevel;
    private double yearsexperience = 0;
    Employee employee = new Employee();
    public void setSkilllevel(String level) { this.skilllevel = level; }
    public void setYearsexperience(double yearsexp) { this.yearsexperience = yearsexp; }
    public void setEmpid(int empid) {this.employee.setEmpid(empid); }
    public void setEname(String ename) { this.employee.setEname(ename); }
    public int getEmpid() { return this.employee.getEmpid(); }
    public String getEname() { return this.employee.getEname(); }
    public String getSkilllevel() { return this.skilllevel; }
    public double getYearsexperience() { return this.yearsexperience; }
} //end EmployeeSkill classIn that case, because EmployeeSkill is a Skill, it has all the methods of the parent Skill type.
Choosing between inheritance (EmployeeSkill Is A Skill) and composition (EmployeeSkill Has A Skill) can be tricky sometimes. Only use the inheritance scheme if it actually fits (it does appear to fit to me), and only if the Skill referenced by EmployeeSkill doesn't change in relationship to the EmployeeSkill (for example, if the Skill's SkillType can change indepependently, or if, over the course of your application, the EmployeeSkill may point to several different Skills, while maintaining its own identity).
An Composition alternative to the above code would have delegate methods in the EmployeeSkill class to pass information to the Skill, and get it back:
public class EmployeeSkill {
    private ResultSet rs ;//the result set to hold the data from the database
    private Connection con;//holds the connection to the database
    private Statement stmt;//used to run SQL       
    private String skilllevel;
    private double yearsexperience = 0;
    Employee employee = new Employee();
    Skill skill = new Skill();
    public void setSkilllevel(String level) { this.skilllevel = level; }
    public void setYearsexperience(double yearsexp) { this.yearsexperience = yearsexp; }
    public void setEmpid(int empid) {this.employee.setEmpid(empid); }
    public void setEname(String ename) { this.employee.setEname(ename); }
    public void setSkillid(int skillid) { this.skill.setSkillid(skillid); }
    public void setSkillname(String skillname) { this.skill.setSkillname(skillname); }
    public void setDesctiption(String description) { this.skill.setDescription(description); }
    public void setSkilltype(SkillType skilltype) { this.skill.setSkilltype(skilltype); }
    public int getSkillid() { return this.skill.getSkillid(); }
    public String getSkillname() { return this.skill.getSkillname(); }
    public String getDescription() { return this.skill.getSkillDescription(); }
    public SkillType getSkilltype() { return this.skill.getSkilltype(); }
    public int getEmpid() { return this.employee.getEmpid(); }
    public String getEname() { return this.employee.getEname(); }
    public String getSkilllevel() { return this.skilllevel; }
    public double getYearsexperience() { return this.yearsexperience; }
} //end EmployeeSkill classIt looks worse because it has more methods, but it can be the better design in the long run.
I would also question the design that says 'EmployeeSkill Has An Employee'. It seems to me that the opposite should be true, the 'Employee Has An EmployeeSkill', or a bunch of them. So it might be worth thinking about how to better manage that relationship.

Similar Messages

  • How can I set a Session bean timeout

    Hello !
    How can I set a Session bean to time out eg. 48 hours ?
    Thanks
    Uiloq Slettemark

    For stateful session beans you can use the timeout attribute in the orion-ejb-jar e.g.
    <session-deployment timeout=1800 ..>
    this is specified in seconds and Default Value: 30 (minutes)
    regards
    Debu

  • Setting a session bean

    How do i set a session bean in my JSF action? I have defined this session bean in my faces-config.xml file:
    <managed-bean>
    <managed-bean-name>SelectedHistoryRecord</managed-bean-name>
    <managed-bean-class>com.myco.nps_history.model.NPSHistoryRecord</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    And so far I know how to retrieve it's value ...
    javax.faces.application.Application app = ctx.getApplication();
    NPSHistoryRecord selectedHistoryRecord = (NPSHistoryRecord)app.getVariableResolver().resolveVariable(ctx, "SelectedHistoryRecord");
    but I don't know how to set the session bean to be an instance of a different bean than that returned. Your advice is appreciated, - Dave

    Indeed, ExternalContext#getSessionMap() returns a modifable map of session attributes (backed by HttpSession#get/setAttrbute() in a Servlet environment), including the session scoped managed beans which are keyed by their managed bean name.
    You may find this article useful in general: [http://balusc.blogspot.com/2006/06/communication-in-jsf.html].

  • Adding Set of Session Beans generates client with wrong session bean names

    Hi,
    I am trying to import a set of session beans deployed on Sun Java Sever 8.2 using Netbeans 6.0. on windows XP.
    The problem is that the imported set generated by the IDE has wrong session bean names and out of 8 session beans in the client jar only 6 are shown (and different 6 every time). Also the remote methods of one bean are associated with another bean and every time its a different set of bean clients generated.
    I am really perplexed with this behavior. Any help on this issue will be highly appreciated.

    An RMI/IIOP parameter type must meet one of thefollowing criteria:
    It must be a primitive type, or it must implementeither java.rmi.Remote or java.io.Serializable,
    or it must be an interface for which the runtime typesatisfies the previous criteria,
    or it must be an array containing elements thatsatisfy the previous criteria.This tells you exactly what you need to do.

  • How to set properties of bean?

    I am using tomcat apache webserver, I need to set properties of beans using servlet. But it not works.Is there any permission needed? If yes than how it is set? Is there any setting that remove all the security policies?

    I will assume this is the same question I just answered to you:
    Put the bean on the session after you fill it on your servlet:
    request.getSession().setAttribute("attributeName", bean);

  • Is it possible to set all the bean properties at once in a servlet?

    Hi,
    I would like to set all the properties of a bean, that is instantiated in a servlet, at once. The values I want to set the bean properties with are kept in a request object coming from a jsp. All form parameter names of the jsp are the same as the names of all bean properties.
    I would like to set all the bean properties at once, so I don't have to use the 'getParameter' method for every bean property. Actually just like when setting properties in a jsp using the setProperty tag, but then in the servlet.
    Is there a possibility to do so?
    thanks and regards,
    dampe hin

    You have an html with a form, after submitting, forward the user to a jsp page with the following code:
    // instantiate bean
    <jsp:useBean id=�cust� class=�Northwind� />
    // set all bean properties
    <jsp:setProperty name=�cust� property=�*� />its up to you what to do next, you could simply forward the user to your servlet for database storage, etc. hope this helps, good luck!

  • Calling setter on backing bean via JavaScript / AJAX using JSF2

    My application requires me to invoke a setter on a backing bean instance. I am trying to do this using the following javascript code:
    var stateListWidth = document.getElementById("myform:stateListWidth");
    stateListWidth.setAttribute("value", 100);
    jsf.ajax.request(this, event, {execute: 'stateListWidth', render: 'stateListWidth'});and added a hidden field as follows:
    <h:form id="myform">
    <h:inputHidden id="stateListWidth" value="#{cityController.stateListWidth}"/>However my setter method is never called. I can see the parameters (myform:stateListWidth = 100) are POST'd to the server side, but not translated into a setter invocation. Any ideas if this is possible and how to do this.

    I got it working. Had to specify the full ID of the element myform:stateListWidth rather then just stateListWidth.
    var stateListWidth = document.getElementById(myform:stateListWidth);
    stateListWidth.setAttribute("value", 100);
    jsf.ajax.request(this, event, {execute: 'myform:stateListWidth', render: 'myform:stateListWidth' });I still wonder if there is a better way without using a hidden field to get this working?

  • Set maximum session bean pool size?

    Using the embedded OC4J, how can I set the maximum pool size for my session beans? I am using Jdeveloper 10g. Do I have to manually edit some XML file?

    Set the system property com.sun.jndi.ldap.connect.pool.maxsize
    System.setProperty("com.sun.jndi.ldap.connect.pool.maxsize", "25");

  • Error setting property in bean of type null

    Hi i have jsf page and input text
    a managed bean with property sum of type float
    i attached this property to the input text:
    <h:inputText id="adr" value="#{userBean.sum}"/>
    but when enter a value and submit the page
    it prints me error in the page:
    Error setting property 'sum' in bean of type null
    any idea?

    The message says that the userBean is null.
    Check your faces-config.xml.

  • Set value of bean objects inthe other beans

    Hi
    i have a session scope bean "mySessionScopeBean" . in this bean i have a String value .
    Now How can i set its value from other beans .
    I searched and find this stufff code for get value :
    Map<String, Object> viewScope =AdfFacesContext.getCurrentInstance().getViewScope();
    String username = (String)viewScope.get("userName");
    is this code true ?

    is this code true ?
    Well did you tried it?
    Session scope is obviously different than view scope so you can't use this code.
    Instead you can try with:
    MySessionScopeBean yourBean = (MySessionScopeBean)ADFContext.getCurrent().getSessionScope().get("mySessionScopeBean");
    String username = yourBean.getUsername();  // of course, if you have getter for username attribute.
    Dario

  • Which WebLogic XDoclet Properties to set for Entity Beans

    I have no documentation about howto set the WebLogic XDoclet properties (in a EJB Project).
    The Entity Beans used by me, are CMP's accessing an Oracle Data Source (allready setup by me in the WebLogic console).
    If someone knows documentation about this, or some example of a CMP (with @weblogic tags) that is backed by an Oracle table, I will appreciate that very much

    Hi ,
    Go through the following link,In that you will find the weblogic tags and will get some needfull information on this issue.
    http://dev2dev.bea.com/pub/a/2002/03/243.html
    Regards
    Anilkumar kari

  • Not able to set Property in bean

    this is my code-----------------------------------------------
    <% if (request.getParameterValues("Submit")!=null)
    %>
    <jsp:useBean id="WriteToFile1" class="mypackage.WriteToFile"/>
    <jsp:setProperty name="WriteToFile1"
    property="Path"
    value='<%= request.getParameter("Date") %>'/>
    <jsp:setProperty name="WriteToFile1"
    property="PageText"
    value='<%=request.getParameter("Diary") %>'/>
    <% WriteToFile1.WriteSomething();
    } //endif
    %>
    Sequence of code-
    1create an instance of WritToFile.claa
    2.get The Name of the File From a html Form entry "Date"
    3.Get The Data from Same From Entry "Diary"
    4.pass these values to class file and call the create and write method in the class file
    but i am getting this error
    " Cannot find any information on property 'Path' in a bean of type mypackage.WriteToFile' "
    Any help

    Does your writeToFile bean have methods getPath(), setPath()?
    Those are required to use the jsp:setProperty tag with them.
    Also rather than using a scriptlet expression, you can write your jsp:setProperty tag like this:
    <jsp:setProperty name="WriteToFile1" property="Path" parameter="Date">Check out the [url http://java.sun.com/products/jsp/syntax/1.2/syntaxref1216.html#8856] JSP Syntax reference  for details.

  • Setting up JSTL

    Hi,
    Seems to be a common problem but I am getting the following error when trying to use the JSTL:
    "The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application".
    The taglib line in the jsp page is
    <%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>my web.xml looks like this...
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>I haven't ported across any jars or tlds for this as yet (i have tried but came up with a number of errors!!)
    I am using Tomcat 6.0.14 and netbeans.
    Can anyone advise on how to get this to work?
    Thanks in advance!
    Tim

    hi tcsmith1978
    Check whether your are using jstl's jar file in your project library while using jstl tags. If you havenot added them, then add them taking it as priority task

  • How to load some setting in application bean on web application start up?

    Hi
    Thank you for reading my post
    Is it possible to load some setting in applicationBean when the web application starts?
    And also
    I need to store some of my application configuration in a .properties file
    can some one please help me with the following items ?
    -How i can access the .properties file
    -where should i put it.

    Hi
    Thank you
    How i can load the .properties files ?
    how should i find the path ? some servers does not allows an application to find the real path to load a file.
    Thanks

  • Set Property to javaBean using JSTL

    Hi all,
    I have a custom object variable that I read from the session using JSTL.
    <c:set var="someObj" value="${sessionScope.myObj}" scope="page"/>
    Now i wan to set the obj into my JavaBean.
    <jsp:useBean id="myBean" scope="request" class"ObjectA">
         <jsp:setProperty name="myBean" property="objA" value='????' />     
    </jsp:useBean>
    How may I achieve this?
    I've tried the following ways:
    value = ${someObj}
    value = '<c:out value=$"someObj">'
    value = 'someObj'
    But none of them works. Any suggestion? I do not wish to have any scriplets.
    Thank you.

    Here is an example of how to do it:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
    First Bean :
        <!-- create the first bean in the request scope-->
         <jsp:useBean id="firstBean" scope="request" class="com.test.testBean"/>
         <!-- output the default name -->
        <c:out value="${firstBean.name}" />
        <!-- set the name to a new value an output the new value -->
        <c:set   value="newName" target="${firstBean}" property="name" />
        <BR><c:out value="${firstBean.name}" />
        <P>
    Second bean : 
        <!-- create the first bean in the request scope-->
        <jsp:useBean id="secondBean" scope="request" class="com.test.testBean"/>
         <!-- output the default name -->
        <c:out value="${secondBean.name}" />
         <!-- set the name to a new value an output the new value -->
        <c:set   value="secondbeanName" target="${secondBean}" property="name" />
        <BR><c:out value="${secondBean.name}" />
    <P>
    Bean reference:
        <!-- set the first bean beanRef to the second bean --> 
        <c:set   value="${secondBean}" target="${firstBean}" property="beanRef" />
         <!-- output the name property of the first bean bean ref -->
            <c:out value="${firstBean.beanRef.name}" />     
            <!-- change the name property of the second bean and the output the name property of the first bean bean ref -->
            <c:set   value="A completely new name" target="${secondBean}" property="name" />
         <br><c:out value="${firstBean.beanRef.name}" />     
        </body>
    </html>where com.test.testBean is:
    package com.test;
    public class testBean {
         private String name = "My Name";
         private int value = 11;
         private boolean exists = true;
         private testBean beanRef;
         public boolean isExists() {
              return exists;
         public void setExists(boolean exists) {
              this.exists = exists;
         public String getName() {
              return name;
         public void setName(String name) {
              this.name = name;
         public int getValue() {
              return value;
         public void setValue(int value) {
              this.value = value;
         public testBean getBeanRef() {
              return beanRef;
         public void setBeanRef(testBean beanRef) {
              this.beanRef = beanRef;
    }

Maybe you are looking for