Error : non-serializable attribute value into ViewMap - java

i have the same application in 2 systems(laptops) but its working in one but not in another.i get the following error in another system. i have also posted the code below.what i want to do is cascading dropdown with a button that calls method of a different managed bean, and a placeOrder button to add a record in database.but i get the following error at the time of page loading
WARNING: Setting non-serializable attribute value into ViewMap: (key: stockOrderBean, value class: beans.stockOrderBean)
SEVERE: Error Rendering View[/ClientTemplate/stockTrade.xhtml]
java.io.NotSerializableException: beans.stockOrderBean
WARNING: JSF1087: Unable to generate Facelets error page as the response has already been committed.
SEVERE: javax.faces.FacesException: beans.stockOrderBean
xhtmlcode:
<h:outputText value="Exchange :"/>
<p:selectOneMenu value="#{stockOrderBean.exchange}" style="width: 200px">
<f:selectItem itemLabel="Select Exchange"/>
<f:selectItem itemLabel="NSE" itemValue="nse"/>
<f:selectItem itemLabel="BSE" itemValue="bse"/>
<p:ajax update="sym" listener="#{stockOrderBean.wow}"/>
</p:selectOneMenu>
<h:outputText value="Select ScripSymbol :"/>
<p:selectOneMenu value="#{stockOrderBean.scripID}" style="width: 200px" id="sym">
<f:selectItem itemLabel="Select scrip"/>
<f:selectItems var="scrip" value="#{stockOrderBean.sl}" itemLabel="#{scrip.scripSymbol}" itemValue="#{scrip.scripID}"/>
</p:selectOneMenu>
<p:commandButton value="Get Quote" actionListener="#{stockOrderBean.equity.setQuote}" oncomplete="cd.show()" update=":frmdialog" />
<h:panelGrid columns="2" id="d1" style="width:565px">
<h:outputText value="How would you like to place order"/>
<p:selectOneRadio value="#{stockOrderBean.transType}">
<f:selectItem itemLabel="Market Order" itemValue="MarketOrder"/>
<p:ajax update="frmTrade:d1"/>
<f:selectItem itemLabel="Limit Order" itemValue="LimitOrder"/>
<p:ajax update="frmTrade:d1"/>
</p:selectOneRadio>
<h:outputText value="Trigger Price"/>
<p:inputText value="#{stockOrderBean.triggerPrice}" disabled="#{stockOrderBean.transType == 'LimitOrder'}"/>
<h:outputText value="Limit Price"/>
<p:inputText value="#{stockOrderBean.limitPrice}" disabled="#{stockOrderBean.transType == 'MarketOrder'}"/>
</h:panelGrid>
<h:outputText value="Select your Demate Account"/>
<p:selectOneMenu value="#{stockOrderBean.demateAccount}" style="width: 120px">
<f:selectItem itemLabel="#{stockOrderBean.demateAccount}" itemValue="#{stockOrderBean.demateAccount}"/>
</p:selectOneMenu>
<p:commandButton value="Place New Order" actionListener="#{stockOrderBean.placeOrder}"/>
<p:commandButton value="Reset New Order" type="reset"/>
</h:form>
<p:dialog widgetVar="cd" header="Scrip Quotes Detail" resizable="true">
<h:form id="frmdialog">
<table>
<tr>
<td>
Ask :
</td>
<td>
<b><h:outputText value="#{stockOrderBean.equity.ask}"/></b>
</td>
</table>
</h:form>
</p:dialog>
sockOrderBean code:
#javax.faces.bean.ManagedBean
#javax.faces.bean.ViewScoped
public class stockOrderBean{
#WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
private StatelessWebService_Service service;
//properties with getter setter
#ManagedProperty(value="#{equtiyBean}")
private equityBean equity = new equityBean();
public void placeOrder(...){
//method not called
}
the same code is working in one system but not on another.what could be the reason and how do i solve it?

Some server configurations need to save HTTP sessions on harddisk or need to transfer them over network to some central datastore, often with the goal to share the session between multiple servers in a cluster, or to minimize excessive memory usage. This in turn requires that all session attributes implement Serializable so that the server could use ObjectOutputStream to convert Java objects to bytes which can then be saved on disk or transferred over network and ObjectInputStream to convert those bytes back to Java objects.
If an object which is stored in the HTTP session does not implement Serializable, then you will get a NotSerializableException with the full qualified class name in the message. You should then fix the class to implement Serializable.
public class StockOrderBean implements Serializable {
// ...
}
In JSF, this applies to all view and session scoped managed beans. Request and application scoped beans doesn't need to implement Serializable. Note that all of the bean properties should also be Serializable. But you will get a clear enough NotSerializableException whenever one is encountered.

Anything which is added to session is Serialized. The error is telling you that your backing bean should probably be Serializable. No idea why it's intermittent though.

Try adding the code below to your web.xml. It will keep session objects on server side.
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>

Related

p:ajax using an global HTML id to reference to an <h:messages> attribute

I currently working on an project that needs some "rebuild" but still there is no money on this - so I have to deal with that what's in front of me. I need to display an message on every change of the radioButton as you can see in this code example:
<h:form>
<h:messages id="msg"/>
<p:accordionPanel value="#{exerciseBean.getCategoriesInGrade(5)}" var="category">
<p:tab title="#{category.categoryName}">
<h:panelGrid columns="1" cellpadding="5">
<ui:repeat value="#{exerciseBean.getSingleChoiceInGrade(5, category.categoryName)}" var="exercise">
<div>#{exercise.getText()}</div>
<p:selectOneRadio value="#{exerciseBean.data}" >
<f:selectItems value="#{exercise.getChoices()}" var="c" itemLabel="#{c.id}" itemValue="#{c.id}" />
<p:ajax event="change" process="#this" listener="#{exerciseBean.validateInput(exercise.getId())}" update="msg"/>
</p:selectOneRadio>
</ui:repeat>
</h:panelGrid>
</p:tab>
</p:accordionPanel>
</h:form>
As you can see - inside this <h:form> there is directly an <h:messages> with the id msg. Now the problem: I still get the error: "cannot find component with identifier 'msg'". I now tried it with the prefix : but still the same problem. Is there a way to get PrimeFaces/JSF to reference to this "global-id"?
In my backend I send the message like this:
FacesMessage facesMessage = new FacesMessage("Right Answer!");
FacesContext.getCurrentInstance().addMessage(null, facesMessage);
thanks.
You need an id for your form.
You then need to modify the reference to msg in the ajax update attribute.
So the following code change should do it for you.
1.<h:form id="formID" >
2.<p:ajax event="change" process="#this" listener="#{exerciseBean.validateInput(exercise.getId())}" update=":formID:msg"/>

Primefaces / JSF: selectOneMenu value is not set, ajax listener not called

I am using Primefaces and JSF to develop this frontend. My issue is that one of my selectonemenus never sets its value binding, "selectedGroup", so the second dropdown is never populated. My backing bean is being called to "update" the second selectonemenu, but the listener of that ajax is not called, nor is selectedGroup ever set. This code is effectively identical to the Showcase for "Select". I even verified that the showcase code works from scratch (which i did not doubt), but fail to see how my situation is any different from that example.
Other stackoverflow questions on this topic indicate that something was left out, but none of those suggestions matched my issue.
I have two selectOneMenus, like so.
<h:form id="outerForm">
<p:panel id="outerPanel">
<p:panelGrid id="outerPanelGrid">
<h:outputLabel for="groupSelection" value="Group: "/>
<p:selectOneMenu id="groupSelection" value="#{myBean.selectedGroup}" >
<p:ajax update="commandSelection"
listener="#{myBean.handleGroupSelection}" />
<f:selectItem itemLabel="---Please Select Group---" itemValue=""/>
<f:selectItems var="group" value="#{myBean.groups}"
itemLabel="#{group.name}" itemValue="#{group.name}" />
</p:selectOneMenu>
<h:outputLabel for="commandSelection" value="Command: "/>
<p:selectOneMenu id="commandSelection" value="#{myBean.command}">
<f:selectItems value="#{myBean.commandStringsList}"/>
</p:selectOneMenu>
</p:panelGrid>
</p:panel>
</h:form>
This page is being displayed in the "center" portion of my layout template like so..
<ui:define id="content" name="content">
<p:panel id="contentPanel" style="float:left; border:none">
<ui:include src="#{anotherBean.currentView}.xhtml"/>
</p:panel>
</ui:define>
The backing bean DOES use some data classes to contain some of the data which is populated, but I thought i was doing everything correct to map it into the view. For the most part, I am using Strings, though.
Does anyone see what I am missing? At the very least, is this xhtml valid?
I should also mention that this page was working before I created and used a template. Basically, I was rendering it in a tab of a tabview using ui:include in the body of index.xhtml. Though I did not notice initially, this page stopped working sometime after I incorporated the template (poor testing on my part, I know).
<f:selectItems var="group" value="#{myBean.groups}"
itemLabel="#{group.name}" itemValue="#{group.name}" />
you can't specify selectItems this way. translation has to be bidirectional. use a converter!
<f:selectItems var="group" value="#{myBean.groups}"
itemLabel="#{group.name}" itemValue="#{group}"
converter="groupConverter"/>

Is it possible to have a form with validation and to use rich:modalPanel for data entry too?

Richfaces 3.3.3, Jsf 1.2:
I have a a4j:form that uses some simple validation, mainly required="true" to ensure the form does not get submitted without some necessary data.
I also have some complex data to add (optionally) to the form, so I thought the best way to do this is to have a a4j:commandButton that displays a rich:modalPanel where the user can create the complex data set.
The created data is also displayed in a h:selectManyListbox that is reRendered when the modalPanel is closed.
That's the plan, at least. I have the following problems:
reRender works, but only if I prevent validation via immediate="true" - which in turn seems to prevent the selected data from the modalPanel to be present in the backing Bean
if I remove the immediate tag, the data gets updated, but only if there are no validation errors
What is the best way to get this to work the way I want? Is there another, better way?
UPDATE:
The Validation that fails is in some different part of the form, not in the data entered via the modalPanel, which is displayed in the Listbox
CODE:
modalPanel:
<rich:modalPanel id="addTrimming" domElementAttachment="parent" width="150" height="130">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Define Filter" />
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/images/close.gif" styleClass="hidelink" id="hidelinkAddTrimming"/>
<rich:componentControl for="addTrimming" attachTo="hidelinkAddTrimming" operation="hide" event="onclick"/>
</h:panelGroup>
</f:facet>
<h:panelGrid id="trimsettings" columns="3">
<h:outputText value="Target:" style="font-weight:bold"/>
<h:inputText id="target" label="XML Filename" required="true" value="#{xmlCreator.trimTarget}">
</h:inputText>
<h:outputText value=""/>
<h:outputText value="Mode:"/>
<h:selectOneMenu value="#{xmlCreator.trimMode}">
<f:selectItem itemLabel="Quality" itemValue="quality"/>
<f:selectItem itemLabel="after Primer" itemValue="afterPrimer"/>
<f:selectItem itemLabel="fixed" itemValue="fixed"/>
<f:selectItem itemLabel="Median length" itemValue="median"/>
<f:selectItem itemLabel="Motif" itemValue="motif"/>
</h:selectOneMenu>
<h:outputText value=""/>
</h:panelGrid>
<h:panelGroup>
<a4j:commandButton value="OK" action="#{xmlCreator.createTrimming}" onclick="from:submit()">
<a4j:support event="oncomplete" ajaxSingle="true" immediate="true" reRender="trimsPanel"/>
</a4j:commandButton>
</h:panelGroup>
</rich:modalPanel>
relevant form part:
<h:outputText value="Trimming:"/>
<a4j:outputPanel id="trimsPanel">
<h:selectManyListbox id="trims" value="#{xmlCreator.selectedTrimmings}">
<f:selectItems value="#{si:toSelectTrimmingList(xmlCreator.trimmings)}"/>
</h:selectManyListbox>
</a4j:outputPanel>
<a4j:commandButton id="addTrimButton" immediate="true" value=" + Trimming">
<rich:componentControl for="addTrimming" attachTo="addTrimButton" operation="show" event="onclick"/>
</a4j:commandButton>
If you do it in one form than you should separate it into two: one will be your main form and another will be form inside modal panel. Thus you'll be able to submit modal panel independently of main form and your submit button in modal panel will look like this:
<a4j:commandButton value="OK" action="#{xmlCreator.createTrimming}" reRender="trimsPanel"/>
you should use process with immediate to send modalpanel's data to bean when closing panel with a a:commandButton or a:commandLink.
for this, modal panel data has to be valid as expected, so you will get valid new data and add it to h:selectManyListBox 's bean value and reRender h:selectManyListBox.
this should work. if not please post your a:form and modalPanel code full to check.

Problem with Java Faces and h:selectOneMenu

I have a Modal form with three combos:
<h:panelGrid columns="3" id="parameterLabels" >
<h:outputText id="lblCdrType" styleClass="formLabel" value="#{BRulesConfig.lblParameter307}:" />
<h:selectOneMenu id="cmdCdrType" style="font-family:Verdana, Arial, Helvetica, sans-serif ;font-size: 14px; width:240px ;"
value="#{BRulesConfig.cdrType}" >
<f:selectItem itemValue="-1" itemLabel="-Select One-" itemDisabled="true"/>
<f:selectItems id="lstCdrType" value="#{BRulesConfig.cdrTypeList}" />
<a4j:support event="onchange" action="#{BRulesConfig.changeStatus}"
reRender="parameterValuesPanelTypeModule,parameterValuesPanelFields,pnlValuesPar,formMessage,formErrMessage,formErrorNew,formInfoNew"
ajaxSingle="true" status="idLoading" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="2" id="parameterValuesPanelTypeModule" >
<h:outputText id="lblCdrTypeModule" styleClass="formLabel" value="#{BRulesConfig.lblParameter307_output}:" />
<h:selectOneMenu id="cmdCdrTypeModule" style="font-family:Verdana, Arial, Helvetica, sans-serif ;font-size: 14px; width:240px ;"
value="#{BRulesConfig.parameterValueBean.id_output}" >
<f:selectItem itemValue="-1" itemLabel="-Select One-" itemDisabled="true"/>
<f:selectItems id="lstCdrTypeModule" value="#{BRulesConfig.cdrTypeModules}" />
<a4j:support event="onchange" ajaxSingle="true" status="idLoading" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="2" id="parameterValuesPanelFields" >
<h:outputText id="lblCdrTypeModuleField" styleClass="formLabel" value="#{BRulesConfig.lblParameter307_field}: #{BRulesConfig.parameterValueBean.value}" />
<h:selectOneMenu id="cmdCdrTypeModuleField" style="font-family:Verdana, Arial, Helvetica, sans-serif ;font-size: 14px; width:240px ;"
value="#{BRulesConfig.parameterValueBean.value}">
<f:selectItem itemValue="-1" itemLabel="-Select One-" itemDisabled="true"/>
<f:selectItems id="lstCdrTypeModuleField" value="#{BRulesConfig.cdrTypeModulesField}" />
</h:selectOneMenu>
</h:panelGrid>
Everything is fine and is loading perfectly.
The first combo cmdCdrType uses ajax to load the second combox cmdCdrTypeModule. It does so using the onchange event (a4j:support). This is also true for the third combobox: cmdCdrTypeModule.
I don't have any problem using any of these combos. But when I try to save all the info that I have stored, I receive the following error message sent by Faces:
28-jul-2011 18:04:51 com.sun.faces.lifecycle.RenderResponsePhase execute
INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=frm307:cmdCdrTypeModuleField[severity=(ERROR 2), summary=(frm307:cmdCdrTypeModuleField: Error de ValidaciĆ³n: Valor no es correcto.), detail=(frm307:cmdCdrTypeModuleField: Error de ValidaciĆ³n: Valor no es correcto.)]
Translating the last line:
Error de Validacion :Valor no es Correcto
Validation Error: Value is not valid
I tried using a converter class, but the same error is displayed. I tried changing my beans setters but nothing changes. My faces config looks like this:
<managed-bean>
<managed-bean-name>BRulesConfig</managed-bean-name>
<managed-bean-class>com.tsb.mediation.brules.configuration.BRulesConfigurationControl</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
I don't know why I'm receiving this error. Any help is appreciated.
Validation Error : Value is not correct -- is not a converter error but validator error. Do you use custom objects in the drop down? If yes, then you need to overwrite equals() and hashCode() on the custom object.
During the apply request values phase of the form submit request, JSF will re-obtain the list of select items from the bean to compare the selected value against the list in order to prevent the server side against spoofed/tampered submits. If no one of the items equals() the selected value, then you will get this error.
It look like that the bean is request scoped and/or that you're doing business in the getter. You need to put the bean in the view scope (or when you're using JSF 1.x, the <a4j:keepAlive> on the bean) and move all business logic outside the getters to get it to work properly.

reRendering is not happening in jsf using data table

Rerendering is not working in my code:
<rich:simpleTogglePanel id="bookIncomeHeader1" value="#{myBean.ftBoookIncomelst}"
label="BOOK INCOME" bodyClass="STP" style="ReptxtBold Reptxt_LtPad"
switchType="server">
<rich:dataTable id="bookIncome" value="#{myBean.ftBoookIncomelst}" var="item"
rowKeyVar="row" first="0" width="100%">
<rich:subTable id="subBookIncome"value="#{item.txIncome}" var="income"
rowKeyVar="row">
<rich:column id="descrtiptionColumn" width="30%">
<h:outputText value="#{income.descriptionCell.value}"
rendered="#{!item.editableRow}"
style="#{income.descriptionCell.boldClass}" />
<rich:inplaceInput layout="block" required="true"
value="#{income.descriptionCell.value}"
rendered="#{item.editableRow}"
requiredMessage="Description at row #{row+1} wasn't filled."
changedHoverClass="hover" viewHoverClass="hover"
viewClass="inplace" changedClass="inplace"
selectOnEdit="true" editEvent="onclick" />
</rich:column>
In the above code I have proper id for datatable and I'm calling my ajax call using:
<rich:menuItem value="Add Manual Adjustment" id="addmanualadjust">
<a4j:support event="onclick" action="#{myBean.addNewDataItem}"
reRender="bookIncome">
<f:param name="rowNum" value="#{item.serialNum}"></f:param>
</a4j:support>
</rich:menuItem>
It's hitting the server and calling proper method and updating the required list, but it's not showing any response. Why is it not rendering? It does not show any exception on console either.
the a4j:support and the dataTable should be in the same <x:form>
try adding immediate="true" to the a4j:support to bypass validation errors.
Does it work if you rerender bookIncomeHeader1?
Max
http://mkblog.exadel.com

Categories