Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple JSF problem  RSS feed

 
Sandip Chaudhuri
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Andrew Och
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have similar code to what you describe and also need getters to run after I click on a Checkbox:

<af:selectBooleanCheckbox id="callIntervalSelector"
value="#{ModifyDeviceManager.callingIntervalBox}"
simple="true" immediate="true"
valueChangeListener="#{ModifyDeviceManager.callingCheckBox}"
onklick="submit()"/>

So what about adding onklick="submit()" to the tag. This causes the getters to be called.

By the way the tag is called onclick but to submit this post i had to rename it to onklick.
 
Sandip Chaudhuri
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Andrew Och
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the project I am assigned to we are using myfaces-1.1.1

As you say with the combination of immediate true and onclick submission this should run all the getters and not do any validation. Since you seem to be getting almost totally opposite behaviour perhaps it is the version of myfaces that is the problem, but that would mean that the immediate tag is not doing what it is supposed to be doing (preventing validation of other fields) and that would be quite an extreme bug.
 
Sandip Chaudhuri
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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">
<hutputText 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 ?
 
Sandip Chaudhuri
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Andrew Och
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry not to reply sooner to this. I look at your code example and I think that what you are doing is fine.

If you have null values after you click the <h:commandButton id="button1" value="press me" action="#{securityProfile.getData}"/> I wonder if you have got the backing bean set to request rather then session scope (set in your faces-config.xml). This would mean that you would set the values but after the post method completes the values are lost. From your code snippet I think that session scope is what you need.

<managed-bean>
<managed-bean-name>securityProfile</managed-bean-name>
<managed-bean-class>package.name.securityProfile</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

If I understand correctly the action button click above will fill:
<h:inputText id="input1" required="true" value="#{securityProfile.securityProfileDataBean.profileID}"/> by running the getProfileID( ) method on the securityProfileDataBean which is an object in the but the backing bean values are then lost. Since all your code provided looks fine, my final idea is the scope of the backing bean.

I hope this helps and best of luck. If you already solved this, then let me know what was the matter.
 
Sandip Chaudhuri
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!