I have two classes and two pages found below:
My question is how do I access the attributes of HelloModel from HelloView to have them displayed in helloName.jsp . The dot notation is not working out for me, and I am not sure if this would require a custom tag to perform this type of work. I had been doing a fair amount of icefaces lately and assumed it would be similar. It is not working out in the sense it cannot find the property hm.name
class HelloView
{
private HelloModel hm;
public String getAttribute()
{
return hm.getName();
}
//getters / setters
}
class HelloModel
{
private String name;
//getters / setters
}
hello.jsp
<form action="helloName.jsp" method="post" name="form">
Hello enter your name!
<input type="text" name="name">
<input type="submit" name="submit" value="Submit" >
helloName.jsp
<body>
<jsp:useBean id="hello" class="HelloView" scope="page">
<jsp:setProperty property="hm.name" name="hello"/>
</jsp:useBean>
Thank you <%=hello.getHelloModel()%>
</body>
You need two
<jsp:useBean>s.Based on the information and code given so far, that would look something like this:
The first one creates
HelloModeland sets the request parameternameas a property of it (it should have apublic void setName(String name)method). The second one createsHelloViewand sets theHelloModelashmproperty of it (it should have apublic void setHm(HelloModel hm)method).Unrelated to the concrete problem,
<jsp:useBean>follows a different MVC approach than normal JSF and JSP/Servlets. It’s recommend to not use it. Also, classes should be inside a package or it will fail on most servers (packageless classes works only in certain Tomcat+JDK combinations).