jsf - How to get Bean data in JSP -
i have bean defined personbean
in session scope.
what want find personbean.personid
in jsp page.
i want in jsp page, because want calculation based on personid
. have idea how same.
in jsp, able print same using jsf
<h:outputtext value="#{personbean.personid}" />
however need value assigned integer value in jsp shown below.
<h:outputtext value="#{personbean.personid}" /> <% int = new personbean().getpersonid; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %>
i thought int = new personbean().getpersonid;
work, not working. idea how get this?
update 1
i tried
<jsp:usebean id="sessionpersonaldatabean" class="com.sac.databean.personalinformationdatabean" scope="session"/> <% out.print("my id " + sessionpersonaldatabean.getpersonid()); %>
still output my id 0
instead of my id 0
.
note:
when use, <h:outputtext value=#{personalinformationdatabean.personid} />
proper output.
you should avoid scriptlets in jsps, answer question: jsp servlet. if bean stored in session scope under attribute "personbean", session:
personbean p = (personbean) request.getsession().getattribute("personbean");
if it's stored under attribute "personalinformationdatabean", code of course
personbean p = (personbean) request.getsession().getattribute("personalinformationdatabean");
the code new personbean()
creates new personbean instance, of course, there no reason instance have same id instance stored in session. pretty basic java stuff, , advise learning bit more java language , basic oo concepts before using jsf.
Comments
Post a Comment