can't create dynamic html elements with jsp? important

Hi All,

I am having problem creating dynamic html elements with jsp tags, i have tried to use EL and java scriplet, both of them don't work.

i am trying to create dynamic menu in my "rightMenu.jspf", based on, if user has logged in or not.

some like this!

<jsp:if test ="${validUser == null}">

some simple text menu here

</jsp:if>

but it is not working. it simply loading all and images with in statement, regardless of whether user has logged in or not. i think some how if statement is not working properly.

"validUser" is a session bean, which is not creating at this point, it will created when user will log in successfully. and also this session bean does not exist at the page, where i am trying to check that .

Is there any way to create dynamic values in jsp. It is really important, is there any body who help me in this matter. i would be really grateful.

zaman

[958 byte] By [learner@java_Foruma] at [2007-11-26 17:31:00]
# 1
Couple things:1) there is no "jsp:if" command... if you are trying to use JSTL, it should be "c:if test=..."2) are you sure the variable "validUser" is being set correctly?
Jasprea at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

thank you very much "jaspre" for replying so quick. i am running exactly the following code.

<c:if test="${validUser != null}">

<div>

<img src="./images/Undo.gif" />

</div>

</c:if>

i am setting it as follows:

<jsp:useBean id="validUser" class="mywebtracker.authenticate.User" scope="session">

<jsp:setProperty name="validUser" property="name" param="userName" />

<jsp:setProperty name="validUser" property="password" param="userPassword" />

<jsp:setProperty name="validUser" property="status" param="userStatus" />

</jsp:useBean>

it works fine but i am setting in another pages called "processUser.jsp", that also get data from "loginForm.jsp" but that "validUser" does not exist until some body actually login into the system.

i am trying to create menu in the right.jspf, when a application will loaded first time, obviously there is no validUser object exist. I tried to create validUser object some where in header.jspf but it still don't work.

i don't know, where i am making mistake. i would be grateful, if you can solve this problem

zaman

learner@java_Foruma at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Give us all the coding details in a clear format, otherwise it is hard (if not impossible) to understand your problem.Have you set up your JSTL 1.1 environment correctly?Tell us exactly what is working and what isn't.
appy77a at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Sorry, it's not very clear what you're doing or how your pages are organized. Are you seeing that validUser is null or not null?

So far, you've said that you have these pages:

[loginForm.jsp]

I'm guessing this page contains the login form and it goes to processUser.jsp below?

[processUser.jsp]

<jsp:useBean id="validUser" ...>

// once this executes, validUser is created in the session scope and is not null

[right.jspf] - this is a fragment, so which page are you using this on?

<c:if test="${validUser != null}" ...>

Jasprea at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

everything is working fine. all environement is set properly. all jsp function are working. i have problems when it comes to creating dynamic creation of html elements in jsp fractions.

for example, when i put some code with in <C:choose ><c:when then rather than one conditional execution, every thing evaluated and printed in jsp fraction, regardless of any condition

i can put whole code here but it is alot

thank you very much for you response

zaman>

learner@java_Foruma at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

hi jaspre,

yes, you are right. loginForm.jsp contains the actual form, while the processUser.jsp is process the all param of that form. yes once it is created then it is not null.

<c:if test ="${validUser == null}"......

i am using above in right.jspf.

i have got one "main.jsp" page that control all flow of my program. for example, it does include header, leftMenu, right, footer jsp fractions. and display other pages such as loginForm.jsp as a main body, depends on what user click on.

for example, if user will click on register menu that registrationForm.jsp will appear in the middle ><div> but includes all top,left,right and bottom fractions.

i hope you will understand my page organisation now.. thanks for your response.

zaman

learner@java_Foruma at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
tell you what, try this and let us know what happens on the page:<c:if test="${false}">This is impossible!</c:if>
Jasprea at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
Hi jaspreit is printing "this is impossible", that is in between if statements. if figure it out, please let me know. i would be grateful, i am really struggling with it.zaman
learner@java_Foruma at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
and jaspre,even if replace false with true in that statement, it is still printing that text line in the jsp fragment. zaman
learner@java_Foruma at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
can any one on able to solve my problem please, i am extremely struggling.i would be gratefulzaman
learner@java_Foruma at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

We would need to see all of your code to try to figure this out and even with that, it may not be enough because it could have something to do with your configuration. Instead of posting your code, create a very small example application that reproduces the problem. It should only require one or two jsps, then post them here. Other than that, I don't think we can help you.

Jasprea at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

hi jaspre,

thanks for replying me. you know what, is it not something wrong with web.xml file. i remember once, i deleted some from there, a property with "*.jsp". i can't remember what exactly was it though.

all if statements works on files ending with extension ".jsp" but don't work only on with extension ".jspf". there must be to do with this.

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<servlet>

<servlet-name>ValidateServlet</servlet-name>

<servlet-class>ValidateServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>ValidateServlet</servlet-name>

<url-pattern>/ValidateServlet</url-pattern>

</servlet-mapping>

<servlet>

<servlet-name>dwr-invoker</servlet-name>

<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>

<init-param>

<param-name>debug</param-name>

<param-value>true</param-value>

</init-param>

<init-param>

<param-name>pollAndCometEnabled</param-name>

<param-value>true</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>dwr-invoker</servlet-name>

<url-pattern>/dwr/*</url-pattern>

</servlet-mapping>

<session-config>

<session-timeout>

30

</session-timeout>

</session-config>

<welcome-file-list>

<welcome-file>

main.jsp

</welcome-file>

</welcome-file-list>

</web-app>

if any one can figure it out. i would be grateful.

zaman

learner@java_Foruma at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13

>all if statements works on files ending with extension ".jsp" but don't work only

>on with extension ".jspf". there must be to do with this.

How are you including right.jspf into your pages?

A jspf is meant to be a JSP fragment which is included with an <%@ include %> directive. It is not a standalone jsp.

If you are using <jsp:include> then you need to include a .jsp, and that jsp needs to be complete on its own. ie it has to import the tag libraries for itself, declare all its own variables etc etc.

evnafetsa at 2007-7-8 23:58:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...