Reputation: 630
I am using netbeans 7.2 and primefaces 3.4. I have created a database, entity classes from database and jsf pages from the entity classes. I am now trying to set up a page that shows a datatable containing the info from one of the databases - Userdetails - (done) which, when a row is clicked on, opens a dialog to add the with a bunch of preset options which can be edited, before that User is added to the other table.
I am having trouble getting the information from the selected row to show up, though. I have cleaned up the code as much as possible and restricted it to just the relevant parts - if anything should be added or taken out, please, just tell me.
I have already looked at some of the answers here on this question and I couldn't get them to work for me. I have tried both the commandbutton approach and the ajax, on row-select approach.
package jsf;
// LOTS OF IMPORTS
@ManagedBean(name = "userdetailsController")
//@ViewScoped
@SessionScoped
public class UserdetailsController implements Serializable {
//DECLARATIONS eg private Userdetails selectedElement;
public UserdetailsController() {
}
// BUNCH OF PREGENERATED CODE OMITTED
public Userdetails getSelected() {
if (current == null) {
current = new Userdetails();
selectedItemIndex = -1;
}
return current;
}
public String create() {
try {
getFacade().create(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("resources/Bundle").getString("UserdetailsCreated"));
return prepareCreate();
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("resources/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
public void setSelectedElement(Userdetails selectedElement) {
this.selectedElement = selectedElement;
}
public Userdetails getSelectedElement() {
return selectedElement;
}
//COLUMN MODEL STUFF THAT WORKS FINE HERE
}
The xhtml stuff
<p:dataTable var="userdetails" value="#{userdetailsController.elements}"
rowKey="#{userdetails.userid}"
scrollable="true" scrollRows="10" scrollHeight="150"
resizableColumns="true"
selection="#{userdetailsController.selectedElement}"
draggableColumns="true" selectionMode="single" paginator="true"
widgetVar="userdetails" id="elementsTable">
<p:ajax event="rowSelect"
update=":datatableForm:display" />
<p:columns value="#{userdetailsController.columns}" var="column" columnIndexVar="colIndex" sortBy="#{userdetails[column.property]}" filterBy="#{userdetails[column.property]}">
<f:facet name="header">
#{column.header}
</f:facet>
#{userdetails[column.property]}
</p:columns>
<f:facet name="footer">
<p:commandButton id="addDlgBtn" value="Add this user?" update=":datatableForm:display" oncomplete="addUser.show()"/>
</f:facet>
</p:dataTable>
</p:fieldset>
That's how the datatable is confined, and the dialog looks like this, but with many more options:
<p:dialog id="dlgAdd" header="Adding users" widgetVar="addUser">
<p:panelGrid id="display" columns="2" cellpadding="4">
<h:outputLabel value="#{bundle.CreateConnectiontableLabel_userid}" for="userid"/>
<h:outputText value="#{userdetailsController.selected.userid}" title="#{bundle.CreateConnectiontableTitle_userid}"/>
<h:outputLabel value="#{bundle.CreateConnectiontableLabel_username}" for="username"/>
<h:outputText value="#{userdetailsController.selected.username}" title="#{bundle.CreateConnectiontableTitle_username}"/>
<h:outputLabel value="#{bundle.CreateConnectiontableLabel_infovalue}" for="infovalue"/>
<h:inputText value="1" title="#{bundle.CreateConnectiontableTitle_infovalue}"/>
</p:panelGrid>
<p:commandButton id="addbtn" value="Add the User." update=":datatableForm"
actionListener="#{connectiontableController.create}"
onclick="addUser.close()"/>
</p:dialog>
However, when I click the add button, I don't get those presets that would be from the selectedElement, ie, #{userdetailsController.selected.username} turns up blank. And when I click Adduser, I get the following error (with full Stacktrace):
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception javax.el.PropertyNotWritableException: /securedadmin/adminsetup.xhtml @146,110 value="": Illegal Syntax for Set Operation at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136) at javax.faces.component.UIInput.updateModel(UIInput.java:818) at javax.faces.component.UIInput.processUpdates(UIInput.java:735) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242) at org.primefaces.component.dialog.Dialog.processUpdates(Dialog.java:366) at javax.faces.component.UIForm.processUpdates(UIForm.java:281) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242) at org.primefaces.component.layout.Layout.processUpdates(Layout.java:252) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242) at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1231) at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:662)
EDIT: The following was just me being dumb, I will try other suggestions shortly but this was just the for requiring appropriate ids. Oops.
I am also told for each of them:
WARNING: Unable to find component with ID userid in view.
Thanks.
Upvotes: 0
Views: 2692
Reputation: 1108632
javax.el.PropertyNotWritableException: /securedadmin/adminsetup.xhtml @146,110 value="": Illegal Syntax for Set Operation
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:136)
at javax.faces.component.UIInput.updateModel(UIInput.java:818)
...
At line 146, character 110 of /securedadmin/adminsetup.xhtml
you've a
<h:inputText value="" />
This is not right. It's not possible to perform a setter method operation on that, exactly as the exception message tells.
Either remove the value=""
<h:inputText />
or bind it to a bean property with a getter/setter like so
<h:inputText value="#{bean.value}" />
This is explained in chapter 1 of a sane JSF tutorial. I recommend to go through one.
Upvotes: 3
Reputation: 2768
First I saw this part:
onclick="addUser.close()"
I used hide() not close.
Also I can't see here, but is your dialog and datatable in seperate form? And you can use ViewScoped too.
One more thing. In datatable you assigned selected row to userdetailsController.selectedElement and in dialog you used userdetailsController.selected. Make same.
Upvotes: 1