Sandip Chaudhuri

Greenhorn
+ Follow
since Dec 27, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sandip Chaudhuri

Left JSF for a while cause it was bugging me no end .
Havent solved the problem yet. I do not want to use the session scope because then the amount of data will keep on increasing.

However i realised why the problem is actually occuring. Though i do not know how to avoid it. View is created when the request comes. Therefore since my beans are request beans the view is not populated with data. On receiving the request the bean populates data for the first time so everything goes haywire. I decided not to call valuechangelisteners after this.
17 years ago
JSF
the java code for getData

17 years ago
JSF
When a request is received the view is created,initialised or reused. However when a new page is rendered by the navigation is the view created or initialised or rendered ?

BTW does anyone have any idea why my jsf page is not working


helloworld.jsp
17 years ago
JSF
Oh no i am not using the getters and setters that way. That would be impracticle won't it? All i am supposed to do is populate the Value Object and send it to the the interface to deal with.

The retriving and saving of data is done by methods in the backing bean whih pass the Value Object to the Interface(Spring). What i am looking for is how do i fill up the backing bean of the second jsp from the first in such way that the server populates its view.
17 years ago
JSF
The get Data code is this

public String getData()
{
if(this.securityProfileDataBean.getProfileID() !=null)
{
SecurityProfileDAOImpl as = new SecurityProfileDAOImpl();
this.securityProfileDataBean = as.getSecurityProfile(this.securityProfileDataBean.getProfileID());

return "success";
}
return "failure";
}


and the navigation is

<navigation-rule>
<from-view-id>/helloWorld.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/access/securityprofile/SecurityProfile.jsp</to-view-id>
</navigation-case>
</navigation-rule>
17 years ago
JSF
i have figured out what is happening but i cant figure out what i am supposed to do.

wats happening is that i have a JSP which takes in a value form the user.
That value is referenced to an variable in My backing bean.
The submit calls an action in the same backing bean which hits the db to get the data and return a navigation to another jsp. So far so good. The new view is rendered and the values are shown. What is occuring is that the view creted on the server is in its initial state. The data is not populated into the components in the server. So when the form is again submitted the valueChangers are called since all are null.

So i have come back to ground zero.

How do i fill data into a Backing Bean from the backend.

This is my original view:-
<f:view>
<h:form id="form">
<h:panelGrid id="grid" columns="2">
<h:outputText id="output1" value="Please enter your Id"/>
<h:inputText id="input1" required="true" value="#{securityProfile.securityProfileDataBean.profileID}"/>

<h:commandButton id="button1" value="press me" action="#{securityProfile.getData}"/>
<h:commandLink id="button3" value="ADD ME" action="success" immediate="true"/>
<h:messages showDetail="true" showSummary="false" layout="table"/>
</h:panelGrid>
</h:form>

</f:view>

Now i understand that if i hit the db from securityProfile.getData() to populate the bean securityProfile and show the result on another jsp it is wrong. So how am i supposed to do it ?
17 years ago
JSF
Could you please give me some links or something for the examples?
Also i am using MyFaces and my beans are all always in request scope.
17 years ago
JSF
As per what i gather from JSF for nonbelievers for the lifecycle we have the 6 steps.

1. Restore view
2. Apply request values; process events
3. Process validations; process events
4. Update model values; process events
5. Invoke application; process events
6. Render response

Where restore view we have new view, initial view, and postback.
The form on submission will finally reach the Invoke application where the method called will be executed after which the navigation will be handeled. After that we have the render response phase.

Now if the navigation is going to another jsf. Is the new view created by the render Response? and the bean for the view populated?
What it seems to me is that the navigated to jsp is rendered but the view is not created. The values which were present in the initial bean gets carried over to the page but since it is of request scope it finishes there. So what i get on the navigated to jsp is that i can see the values but the view has actually not been created or is an initial view. So if i use any immediate=true link/action then all i get are null fields. Is my understanding of the lifecycle correct? please help.
17 years ago
JSF
there is an onclick submission there. However what i am referring to is that when the checkbox is clicked the first time the getters are called. However on other subsequent clicks the getters are not called. This is causing the trouble because the page starts behaving crazily. If the checbox initially clicked that is the bean returns a true value for it and then it is unchecked the code goes haywire the immediate=true does not work and the validaions occur which i dont want at that point of time.
btw wats simple ? and which implementation of jsf are u using?
17 years ago
JSF
I have a simple page with one inputText and a h:commandButton
On press of the command button i have to take the value of that field and use it to fetch data and display the data on another jsp.

The inputText is pointed to a paramter in the managedBean which i have to fill from the database. The command button calls a method from the managedbean which gets the data from the database and assigns the values to the bean. It then returns the outcome as 'success' which is then mapped to another jsp in the navigation case.
The second page shows all the data and has a save button for updating the data.
There is also a checkbox(immediate = true) with a valuechangelistner which is called when the box is clicked. When this page is submitted the first time this checkbox is clicked a getters of the bean are again called. However on subsequent clicks the getters are not called. Why does this happen?
17 years ago
JSF
I have two selectBooleanCheckbox in my jsp
When the value of the checkboxes is true when the page is loaded from the database then for some reason when the checkbox1 is clicked the valueChangeListener of the second checkbox is called.

< h:selectBooleanCheckbox id="loginDurationRestrictionFlag" value="#{securityProfile.loginDurationRestrictionFlag}" immediate="true" valueChangeListener="#{securityProfile.enableDates}" />
there is an on click of this checkbox written which submits the page.
( not able to write it here the topic isnt getting posted )

< h:selectBooleanCheckbox id="passwordNeverExpiresFlag" value="#{securityProfile.passwordNeverExpiresFlag}" immediate="true" valueChangeListener="#{securityProfile.enableExpiryDays}"/>

also an on click here which submits the page

when the loginDurationRestrictionFlag value returns true and the data is loaded on the page the checkbox shows checked but on clicked it calls the enableExpiryDays method. the reverse happens if the passwordNeverExpiresFlag is checked when the page loads and the passwordNeverExpiresFlag is clicked on the enableDates is called. However there does not seem to be a problem once the page is loaded with any value false.

public boolean getLoginDurationRestrictionFlag() {
if (securityProfileDataBean.getLoginDurationRestrictionFlag() == null
|| securityProfileDataBean.getLoginDurationRestrictionFlag()
.equals("N"))
return false;
return true;
}

public void setLoginDurationRestrictionFlag(boolean loginDurationRestFlag) {
if (loginDurationRestFlag)
this.securityProfileDataBean.setLoginDurationRestrictionFlag("Y");
else
this.securityProfileDataBean.setLoginDurationRestrictionFlag("N");
}

public boolean getPasswordNeverExpiresFlag() {
if (securityProfileDataBean.getPasswordNeverExpiresFlag() == null
|| securityProfileDataBean.getPasswordNeverExpiresFlag()
.equals("N"))
return false;
return true;
}

public void setPasswordNeverExpiresFlag(boolean pwdNeverExpiresFlag) {
if (pwdNeverExpiresFlag)
this.securityProfileDataBean.setPasswordNeverExpiresFlag("Y");
else
this.securityProfileDataBean.setPasswordNeverExpiresFlag("N");
}

I can not figure out what i am doing wrong.
Another thing i noticed is that after clicking any of the boxes preloaded with true once the other works when clicked.

Another thing that i forgot to mention
The primary key is being entered from helloworld.jsp(#{securityProfile.securityProfileDataBean.profileID}) and a button is pressed whose action is defined by #{securityProfile.addMode}
this method returns 'success' which then goes to the SecurityProfile.jsp

public String getData()
{
if(this.securityProfileDataBean.getProfileID() !=null)
{
SecurityProfileDAOImpl as = new SecurityProfileDAOImpl();
this.securityProfileDataBean = as.getSecurityProfile(this.securityProfileDataBean.getProfileID());
return "success";
}
return "failure";
}


I added a System.out.println() in one of the getters and found that it gets called when the page gets displayed when the getData is called from getData(). The System.out.println() gets displayed again when that page is submitted again via the valueChangeListener but doesnt get displayed on the second submission. So i figure i have missed something but what i can not figure it out.

[ July 13, 2006: Message edited by: Sandip Chaudhuri ]
[ July 14, 2006: Message edited by: Sandip Chaudhuri ]
17 years ago
JSF
Hi,
I am pretty new to JSF and very confused about its working as well. This may be cause i am still thinking in the struts mode which is causing the problem.

What i have is a simple senario. (using MyFaces)

the User clicks on a link or submits a page. That link has a nivigation

<navigation-rule>
<from-view-id>/helloWorld.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/Profile.jsp</to-view-id>
</navigation-case>
</navigation-rule>

I want to pre populate some values in the bean used in Profile.jsp. How do i do it?
IN struts we had the action class which would allow me to prepopulate. Thats is if i extended LookupDispatchAction then calling the right method would allow me to populate the bean. How do i do this ?
17 years ago
JSF
How to change the component state via jsf?
Do i have to submit the page?

If i do state changes by javascript how do I inform the server then?

Another question which is bothering me is that i have used validator="#{mybean.validateRequiredIf}" when the required="true" is not set for the component.

However if i do not enter any value then the validateRequiredIf is not called.
I am completely new to JSF and these are basics i guess.
17 years ago
JSF
I am pretty positive it depends upon containers.
And I know from firsthand experience IBM Websphere does not, while TomCat 5 does.
18 years ago
JSP
i think there is some jUnit which is used to test struts action classes.
they create the servlet requestand response so this is definately possible.
18 years ago